[AD] transpose_font, minor addition

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


The attached patch adds a transpose_font function to the font API that can 
be used to remap character ranges. The inspiration and rationale comes 
from this thread: http://www.allegro.cc/forums/view_thread.php?_id=458628.
I think this change is (just) small enough that it can get in despite the 
feature freeze.
Documentation also attached. This fixes a few annoying typos as well.

Evert
Index: docs/src/allegro._tx
===================================================================
RCS file: /cvsroot/alleg/allegro/docs/src/allegro._tx,v
retrieving revision 1.295
diff -u -p -r1.295 allegro._tx
--- docs/src/allegro._tx	10 Feb 2005 20:33:54 -0000	1.295
+++ docs/src/allegro._tx	13 Feb 2005 13:39:00 -0000
@@ -6072,7 +6072,7 @@ to use TrueType fonts, you will need to 
    fonts or both are monochrome fonts, for instance).
 
 @@int @get_font_ranges(FONT *f)
-@domain.hid get_font_range_begin, get_font_range_end
+@xref get_font_range_begin, get_font_range_end, transpose_font
 @shortdesc Returns the number of character ranges in a font.
    This function returns the number of character ranges in a font. You should
    query each of these ranges with get_font_range_begin() and
@@ -6095,7 +6095,7 @@ to use TrueType fonts, you will need to 
    information is not available.
 
 @@int @get_font_range_begin(FONT *f, int range)
-@domain.hid get_font_ranges, get_font_range_end
+@xref get_font_ranges, get_font_range_end, transpose_font
 @shortdesc Returns the start of a character range in a font.
    This function returns the start of the character range for the font f, or
    -1 if that information is not available for the selected font. You can pass
@@ -6111,7 +6111,7 @@ to use TrueType fonts, you will need to 
    is not available.
 
 @@int @get_font_range_end(FONT *f, int range)
-@domain.hid get_font_ranges, get_font_range_begin
+@xref get_font_ranges, get_font_range_begin, transpose_font
 @shortdesc Returns the last character of a character range in a font.
    This function returns the last character of the character range for the
    font f. You can pass -1 for the range parameter if you want to know the
@@ -6130,12 +6130,12 @@ to use TrueType fonts, you will need to 
    not available.
 
 @@FONT *@extract_font_range(FONT *f, int begin, int end)
-@domain.hid get_font_range_begin, get_font_range_end, merge_fonts
-@domain.hid Extracts a range pf characters from a font.
+@xref get_font_range_begin, get_font_range_end, merge_fonts, transpose_font
+@shortdesc Extracts a range of characters from a font.
    This function extracts a character range from a font and returns a new font
    that contains only the range of characters selected by this function. You
    can pass -1 for either the lower or upper bound if you want to select all
-   characters from the start or the end of the font.
+   characters from the start or to the end of the font.
    Example:
 <codeblock>
       FONT *myfont;
@@ -6146,13 +6146,33 @@ to use TrueType fonts, you will need to 
       capitals = extract_font_range(myfont, 'A', 'Z');
 
       /* Create a copy of the font */
-      fontopy = extract_font_range(myfont, -1, -1);
+      fontcopy = extract_font_range(myfont, -1, -1);
       <endblock>
 @retval
    Returns a pointer to the new font or NULL on error. Remember that you are
    responsible for destroying the font when you are finished with it to
    avoid memory leaks.
 
+@@FONT *@transpose_font(FONT *f, int drange)
+@xref get_font_range_begin, get_font_range_end, merge_fonts, extract_font_range
+@shortdesc Transposes all characters in a font.
+   This function transposes all characters in a font, effectively remapping the
+   font. Example:
+<codeblock>
+      FONT *myfont;
+      FONT *capitals;
+      ...
+      /* Create a font of only capital letters */
+      capitals = extract_font_range(myfont, 'A', 'Z');
+
+      /* Now transpose the characters in the font so that they will be used */
+      /*  for the lower case letters a-z */
+      transpose_font(capitals, 'a'-'A');
+      textout_ex(screen, capitals, "allcaps", 100, 100, makecol(255,255,255), 0);
+      <endblock>
+@retval
+   Returns 0 on success, -1 on failure.
+
 @@FONT *@merge_fonts(FONT *f1, FONT *f2)
 @xref extract_font_range, is_color_font, is_mono_font
 @shortdesc Merges two fonts into one font.
@@ -6173,8 +6193,8 @@ to use TrueType fonts, you will need to 
       ...
       /* Create a font that contains the capatials from  */
       /* the fancy font but other characters from myfont */
-      lower_range = extarct_font_range(myfont, -1, 'A'-1);
-      upper_range = extarct_font_range(myfont, 'Z'+1, -1);
+      lower_range = extract_font_range(myfont, -1, 'A'-1);
+      upper_range = extract_font_range(myfont, 'Z'+1, -1);
       capitals = extract_font_range(myfancy_font, 'A', 'Z');
 
       tempfont = merge_fonts(lower_range, capitals);
Index: include/allegro/font.h
===================================================================
RCS file: /cvsroot/alleg/allegro/include/allegro/font.h,v
retrieving revision 1.3
diff -u -p -r1.3 font.h
--- include/allegro/font.h	23 Jan 2005 19:29:02 -0000	1.3
+++ include/allegro/font.h	13 Feb 2005 09:36:18 -0000
@@ -60,6 +60,7 @@ AL_FUNC(int, get_font_range_begin, (FONT
 AL_FUNC(int, get_font_range_end, (FONT *f, int range));
 AL_FUNC(FONT *, extract_font_range, (FONT *f, int begin, int end));
 AL_FUNC(FONT *, merge_fonts, (FONT *f1, FONT *f2));
+AL_FUNC(int, transpose_font, (FONT *f, int drange));
 #ifdef __cplusplus
    }
 #endif
Index: include/allegro/internal/aintern.h
===================================================================
RCS file: /cvsroot/alleg/allegro/include/allegro/internal/aintern.h,v
retrieving revision 1.27
diff -u -p -r1.27 aintern.h
--- include/allegro/internal/aintern.h	1 Feb 2005 13:12:04 -0000	1.27
+++ include/allegro/internal/aintern.h	13 Feb 2005 09:36:20 -0000
@@ -235,6 +235,7 @@ typedef struct FONT_VTABLE
    AL_METHOD(int, get_font_range_end, (FONT *f, int range));
    AL_METHOD(FONT *, extract_font_range, (FONT *f, int begin, int end));
    AL_METHOD(FONT *, merge_fonts, (FONT *f1, FONT *f2));
+   AL_METHOD(int, transpose_font, (FONT *f, int drange));
 } FONT_VTABLE;
 
 AL_VAR(FONT, _default_font);
Index: src/font.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/font.c,v
retrieving revision 1.11
diff -u -p -r1.11 font.c
--- src/font.c	23 Jan 2005 19:29:03 -0000	1.11
+++ src/font.c	13 Feb 2005 09:36:22 -0000
@@ -815,6 +815,32 @@ FONT *mono_merge_fonts(FONT *font1, FONT
 
 
 
+/* mono_transpose_font:
+ *  (mono vtable entry)
+ *  Transpose all glyphs in a font
+ */
+static int mono_transpose_font(FONT* f, int drange)
+{
+   FONT_MONO_DATA* mf = 0;
+
+   if (!f) 
+      return -1;
+
+   mf = (FONT_MONO_DATA*)(f->data);
+
+   while(mf) {
+      FONT_MONO_DATA* next = mf->next;
+      
+      mf->begin += drange;
+      mf->end += drange;
+      mf = next;
+   }
+
+   return 0;
+}
+
+
+
 /* _color_find_glyph:
  *  Helper for color vtable entries, below.
  */
@@ -1246,6 +1272,32 @@ FONT *color_merge_fonts(FONT *font1, FON
 
 
 
+/* color_transpose_font:
+ *  (color vtable entry)
+ *  Transpose all glyphs in a font
+ */
+static int color_transpose_font(FONT* f, int drange)
+{
+   FONT_COLOR_DATA* cf = 0;
+
+   if (!f) 
+      return -1;
+
+   cf = (FONT_COLOR_DATA*)(f->data);
+
+   while(cf) {
+      FONT_COLOR_DATA* next = cf->next;
+      
+      cf->begin += drange;
+      cf->end += drange;
+      cf = next;
+   }
+
+   return 0;
+}
+
+
+
 /********
  * vtable declarations
  ********/
@@ -1262,7 +1314,8 @@ FONT_VTABLE _font_vtable_mono = {
     mono_get_font_range_begin,
     mono_get_font_range_end,
     mono_extract_font_range,
-    mono_merge_fonts
+    mono_merge_fonts,
+    mono_transpose_font
 };
 
 FONT_VTABLE* font_vtable_mono = &_font_vtable_mono;
@@ -1279,7 +1332,8 @@ FONT_VTABLE _font_vtable_color = {  
     color_get_font_range_begin,
     color_get_font_range_end,
     color_extract_font_range,
-    color_merge_fonts
+    color_merge_fonts,
+    color_transpose_font
 };
 
 FONT_VTABLE* font_vtable_color = &_font_vtable_color;
@@ -1397,6 +1451,21 @@ int get_font_range_end(FONT *f, int rang
 
 
 
+
+/* transpose_font:
+ *  Transposes all the glyphs in a font over a range drange. Returns 0 on
+ *   success, or -1 on failure.
+ */
+int transpose_font(FONT *f, int drange)
+{
+   if (f->vtable->transpose_font)
+      return f->vtable->transpose_font(f, drange);
+   
+   return -1;
+}
+
+
+
 /********
  * Declaration of `_default_font' and `font'
  ********/


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/