Author: fejj
Date: 2008-02-08 15:51:46 -0500 (Fri, 08 Feb 2008)
New Revision: 95300

Modified:
   trunk/moon/src/ChangeLog
   trunk/moon/src/font.cpp
   trunk/moon/src/font.h
Log:
2008-02-08  Jeffrey Stedfast  <[EMAIL PROTECTED]>

        * font.cpp (TextFont::TextFont): If the loaded font's family_name
        doesn't match the requested family name, fall back to the default
        font (it means the requested font doesn't exist on the system).
        (TextLayout::Layout): Added a 'first_char' state variable that can
        be used to figure out if if the current char is the first char on
        a line. This is needed for the wrapping logic.



Modified: trunk/moon/src/ChangeLog
===================================================================
--- trunk/moon/src/ChangeLog    2008-02-08 20:17:45 UTC (rev 95299)
+++ trunk/moon/src/ChangeLog    2008-02-08 20:51:46 UTC (rev 95300)
@@ -1,5 +1,14 @@
 2008-02-08  Jeffrey Stedfast  <[EMAIL PROTECTED]>
 
+       * font.cpp (TextFont::TextFont): If the loaded font's family_name
+       doesn't match the requested family name, fall back to the default
+       font (it means the requested font doesn't exist on the system).
+       (TextLayout::Layout): Added a 'first_char' state variable that can
+       be used to figure out if if the current char is the first char on
+       a line. This is needed for the wrapping logic.
+
+2008-02-08  Jeffrey Stedfast  <[EMAIL PROTECTED]>
+
        Fixes some text layout bugs in TextBlockFontFamilies.xaml
 
        * xaml.cpp (flush_char_data): Now takes a string 'next_element'

Modified: trunk/moon/src/font.cpp
===================================================================
--- trunk/moon/src/font.cpp     2008-02-08 20:17:45 UTC (rev 95299)
+++ trunk/moon/src/font.cpp     2008-02-08 20:51:46 UTC (rev 95300)
@@ -609,24 +609,31 @@
        return FT_New_Face (libft2, file->path, fface->index, &face) == 0;
 }
 
-TextFont::TextFont (FcPattern *pattern, bool fromFile, const char *name)
+TextFont::TextFont (FcPattern *pattern, bool fromFile, const char 
*family_name, const char *debug_name)
 {
        const char *fallback_fonts[] = { "Lucida Sans Unicode", "Lucida Sans", 
"Sans" };
        FcChar8 *family = NULL, *filename = NULL;
        FcPattern *matched, *fallback;
+       char **families = NULL;
        uint attempt = 0;
        FcResult result;
        FT_Error err;
        double size;
-       int id;
+       int id, i;
        
-       d(fprintf (stderr, "\nAttempting to load %s\n", name));
+       d(fprintf (stderr, "\nAttempting to load %s\n", debug_name));
        
        FcPatternGetDouble (pattern, FC_PIXEL_SIZE, 0, &size);
        FcPatternGetDouble (pattern, FC_SCALE, 0, &scale);
        FcPatternReference (pattern);
        matched = pattern;
        
+       if (family_name) {
+               families = g_strsplit (family_name, ",", -1);
+               for (i = 0; families[i]; i++)
+                       families[i] = g_strstrip (families[i]);
+       }
+       
        do {
                if (FcPatternGetString (matched, FC_FILE, 0, &filename) != 
FcResultMatch)
                        goto fail;
@@ -636,8 +643,25 @@
                
                d(fprintf (stderr, "\t* loading font from `%s' (index=%d)... ", 
filename, id));
                if ((err = FT_New_Face (libft2, (const char *) filename, id, 
&face)) == 0) {
-                       d(fprintf (stderr, "success!\n"));
-                       break;
+                       if (fromFile || attempt > 0 || !family_name || 
!face->family_name) {
+                               d(fprintf (stderr, "success!\n"));
+                               break;
+                       }
+                       
+                       // make sure the font family name matches what was 
requested...
+                       for (i = 0; families[i]; i++) {
+                               if (!strcmp (face->family_name, families[i]))
+                                       break;
+                       }
+                       
+                       if (families[i]) {
+                               d(fprintf (stderr, "success!\n"));
+                               break;
+                       }
+                       
+                       d(fprintf (stderr, "no; incorrect family\n"));
+                       FT_Done_Face (face);
+                       face = NULL;
                } else {
                        d(fprintf (stderr, "failed :(\n"));
                }
@@ -691,6 +715,9 @@
        
        FcPatternDestroy (matched);
        
+       if (families)
+               g_strfreev (families);
+       
        if (face != NULL) {
                FT_Set_Pixel_Sizes (face, 0, (int) size);
                
@@ -735,7 +762,7 @@
 }
 
 TextFont *
-TextFont::Load (FcPattern *pattern, bool fromFile, const char *name)
+TextFont::Load (FcPattern *pattern, bool fromFile, const char *family_name, 
const char *debug_name)
 {
        TextFont *font;
        
@@ -744,7 +771,7 @@
                return font;
        }
        
-       return new TextFont (pattern, fromFile, name);
+       return new TextFont (pattern, fromFile, family_name, debug_name);
 }
 
 void
@@ -1271,15 +1298,15 @@
 TextFont *
 TextFontDescription::GetFont ()
 {
+       char *debug_name = NULL;
        FcPattern *pattern;
-       char *name = NULL;
        
        if (font == NULL) {
-               d(name = ToString ());
+               d(debug_name = ToString ());
                pattern = CreatePattern ();
-               font = TextFont::Load (pattern, (set & FontMaskFilename), name);
+               font = TextFont::Load (pattern, (set & FontMaskFilename), 
GetFamily (), debug_name);
                FcPatternDestroy (pattern);
-               d(g_free (name));
+               d(g_free (debug_name));
        }
        
        if (font)
@@ -1878,6 +1905,7 @@
 void
 TextLayout::Layout ()
 {
+       bool first_char = true;
        TextSegment *segment;
        bool clipped = false;
        gunichar prev = 0;
@@ -1997,7 +2025,7 @@
                                                lw = spc.width;
                                                i = spc.index;
                                                wrap = true;
-                                       } else if (i > segment->start) {
+                                       } else if (/*i > segment->start*/ 
!first_char) {
                                                // Wrap before this char
                                                segment->end = i;
                                                wrap = true;
@@ -2025,6 +2053,7 @@
                                        break;
                                }
                        } else {
+                               first_char = false;
                                wrap = false;
                        }
                        
@@ -2047,6 +2076,7 @@
                                //ascend = run->font->Ascender ();
                                lh = run->font->Height ();
                                line = new TextLine ();
+                               first_char = true;
                                spc.index = -1;
                                sx = lw = 0.0;
                                

Modified: trunk/moon/src/font.h
===================================================================
--- trunk/moon/src/font.h       2008-02-08 20:17:45 UTC (rev 95299)
+++ trunk/moon/src/font.h       2008-02-08 20:51:46 UTC (rev 95300)
@@ -119,7 +119,7 @@
        
        GlyphInfo *glyphs;
        
-       TextFont (FcPattern *pattern, bool fromFile, const char *name);
+       TextFont (FcPattern *pattern, bool fromFile, const char *family_name, 
const char *debug_name);
        
        bool OpenZipArchiveFont (FcPattern *pattern, const char *path);
        
@@ -133,7 +133,7 @@
        void ref ();
        void unref ();
        
-       static TextFont *Load (FcPattern *pattern, bool fromFile, const char 
*name);
+       static TextFont *Load (FcPattern *pattern, bool fromFile, const char 
*family_name, const char *debug_name);
        
        GlyphInfo *GetGlyphInfo (gunichar unichar);
        GlyphInfo *GetGlyphInfoByIndex (uint32_t index);

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to