Re: [AD] Old problems that still persist on Allegro 4.2 beta 3 |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
On Fri, 2005-05-27 at 19:39 +0200, Evert Glebbeek wrote:
> > So yeah, needs changing, and also for mono data. And I found some more
> > places where it is wrong, should I fix them and commit?
>
> Yeah, but post the patch first.
Ok, attached. Also made the comments from the last patch shorter.
>
> > Oh, and what do you think about a function:
> >
> > void attach_font(FONT *font1, FONT *font2)
>
> I'd love it, but I think it would require an extra vtable entry. That this
> would be very useful occured to me a while back too (when I was working on
> the font example - if you've seen what it does, you'll see what I mean),
> but I really don't want to poke at the vtable at this point.
Yes, and in most cases, fonts will be rather small, so it's not really a
problem.
> > 9 font creations and 19 destructions, with 1+2+3+4+5+6+7+8+9 = 45 range
> > creations (4500 create_bitmaps calls) and 36 range destructions... and
> > so on... compared to the old grabber who used 0. attach_font would be as
> > efficient as the old grabber again.
>
> Note: you can't just copy the bitmap pointers from one font to the next for
> any arbitrary pair of fonts - it will lead to a crash when one of the two
> fonts and its bitmap parameters are destroyed. That means you would have to
> call create_bitmap() anyway.
Ah, true. Either that, or destroy the second font inside the function..
> What we could do is cheat in load_txt_font in that we allow it to bypass
> the vtable and manipulate the font data directly for font formats it
> understands (ie, Allegro's buildin font types). It should then fall back on
> the existing method for other font types. This doesn't help real-time on
> the fly merging of fonts though.
Yes, I was thinking about it, but then when I saw the old code in
datfont.c (which does that), I didn't want to do it anymore :P
> How merge_fonts() should have been implemented, at least internally, is
> with the option of just adding to an existing font instead of copying all
> the existing data over.
True, just an option to merge_fonts would work as well.
> What I would really love is the ability to have `sub fonts', a bit like
> subbitmaps. You can then just import a range of characters from another
> font with no copying at all - just store pointers to the appropriate
> location in the target font. This would require a flag in the font range
> structure to indicate that the `child' should not try to destroy that font
> range.
> Of course, this would require that both parent and child fonts be held in
> memory at the same time.
Or we could do it like with sub bitmaps, simply tells the programmer
that the parent may not be destroyed. (Although, a flag to not destroy
the range would be nicer.)
--
Elias Pschernig
Index: src/font.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/font.c,v
retrieving revision 1.19
diff -u -p -r1.19 font.c
--- src/font.c 16 May 2005 12:40:48 -0000 1.19
+++ src/font.c 27 May 2005 18:46:29 -0000
@@ -640,7 +640,7 @@ static int mono_get_font_range_begin(FON
/* mono_get_font_range_end:
* (mono vtable entry)
- * Get last character for font range. Pass -1 to search the entire font
+ * Get one past last character for font range. Pass -1 to search the entire font
*/
static int mono_get_font_range_end(FONT* f, int range)
{
@@ -689,7 +689,7 @@ static FONT_MONO_DATA *mono_copy_glyph_r
newmf->begin = begin;
newmf->end = end;
newmf->next = NULL;
- num = end - begin+1;
+ num = end - begin;
gl = newmf->glyphs = _al_malloc(num * sizeof *gl);
for (c=0; c<num; c++) {
@@ -1054,7 +1054,7 @@ static int color_get_font_range_begin(FO
/* color_get_font_range_end:
* (color vtable entry)
- * Get last character for font.
+ * Get one past last character for font.
*/
static int color_get_font_range_end(FONT* f, int range)
{
@@ -1088,7 +1088,7 @@ static int color_get_font_range_end(FONT
static FONT_COLOR_DATA* upgrade_to_color_data(FONT_MONO_DATA* mf)
{
FONT_COLOR_DATA* cf = _al_malloc(sizeof *cf);
- BITMAP** bits = _al_malloc((mf->end - mf->begin+1)*sizeof *bits);
+ BITMAP** bits = _al_malloc((mf->end - mf->begin)*sizeof *bits);
int i;
cf->begin = mf->begin;
@@ -1096,7 +1096,7 @@ static FONT_COLOR_DATA* upgrade_to_color
cf->bitmaps = bits;
cf->next = 0;
- for(i = mf->begin; i <= mf->end; i++) {
+ for(i = mf->begin; i < mf->end; i++) {
FONT_GLYPH* g = mf->glyphs[i - mf->begin];
BITMAP* b = create_bitmap_ex(8, g->w, g->h);
clear_to_color(b, 0);
@@ -1158,7 +1158,7 @@ static FONT_COLOR_DATA *color_copy_glyph
newcf->begin = begin;
newcf->end = end;
newcf->next = NULL;
- num = end - begin+1;
+ num = end - begin;
gl = newcf->bitmaps = _al_malloc(num * sizeof *gl);
for (c=0; c<num; c++) {
@@ -1166,7 +1166,7 @@ static FONT_COLOR_DATA *color_copy_glyph
gl[c] = create_bitmap_ex(8, g->w, g->h);
blit(g, gl[c], 0, 0, 0, 0, g->w, g->h);
}
-
+
return newcf;
}
@@ -1201,7 +1201,7 @@ FONT *color_extract_font_range(FONT *f,
/* Get real character ranges */
first = MAX(begin, color_get_font_range_begin(f, -1));
last = (end>-1) ? MIN(end, color_get_font_range_end(f, -1)) : color_get_font_range_end(f, -1);
-
+
cf = NULL;
cfin = f->data;
while (cfin) {
@@ -1402,7 +1402,7 @@ int is_compatible_font(FONT *f1, FONT *f
/* extract_font_range:
* Extracts a character range from a font f, and returns a new font containing
* only the extracted characters.
- * Returns NULL if teh character range could not be extracted.
+ * Returns NULL if the character range could not be extracted.
*/
FONT *extract_font_range(FONT *f, int begin, int end)
{
Index: src/fonttxt.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/fonttxt.c,v
retrieving revision 1.2
diff -u -p -r1.2 fonttxt.c
--- src/fonttxt.c 19 Mar 2005 11:15:06 -0000 1.2
+++ src/fonttxt.c 27 May 2005 18:46:29 -0000
@@ -27,7 +27,7 @@
FONT *load_txt_font(AL_CONST char *filename, RGB *pal, void *param)
{
char buf[1024], *font_str, *start_str = 0, *end_str = 0;
- FONT *f, *f2, *f3, *f4;
+ FONT *f, *f2, *f3;
PACKFILE *pack;
int begin, end;
@@ -35,7 +35,7 @@ FONT *load_txt_font(AL_CONST char *filen
if (!pack)
return NULL;
- f = f2 = f3 = f4 = NULL;
+ f = f2 = f3 = NULL;
while(pack_fgets(buf, sizeof(buf)-1, pack)) {
font_str = strtok(buf, " \t");
@@ -69,19 +69,22 @@ FONT *load_txt_font(AL_CONST char *filen
/* Load the font that needs to be merged with the current font */
if (font_str[0]) {
- if (f4)
- destroy_font(f4);
- f4 = load_font(font_str, pal, param);
+ if (f2)
+ destroy_font(f2);
+ f2 = load_bitmap_font(font_str, pal, param);
}
- if(!f4) {
+ if(!f2) {
destroy_font(f);
pack_fclose(pack);
-
return NULL;
}
-
- /* Extract font range */
- f2 = extract_font_range(f4, begin, end);
+
+ /* load_bitmap_font makes the font start with character 32, so transpose
+ * it so it starts at begin.
+ */
+ transpose_font(f2, begin - 32);
+
+ /* FIXME: More efficient way than to repeatedely merge into a new font? */
if (f) {
f3 = f;
f = merge_fonts(f2, f3);
@@ -89,10 +92,9 @@ FONT *load_txt_font(AL_CONST char *filen
destroy_font(f2);
} else {
f = f2;
- f2 = NULL;
}
+ f2 = NULL;
}
- destroy_font(f4);
pack_fclose(pack);
return f;