Author: fejj
Date: 2007-09-19 17:36:36 -0400 (Wed, 19 Sep 2007)
New Revision: 86047

Added:
   trunk/moon/src/text.patch
Modified:
   trunk/moon/src/ChangeLog
   trunk/moon/src/Makefile.am
   trunk/moon/src/font.cpp
   trunk/moon/src/font.h
Log:
2007-09-19  Jeffrey Stedfast  <[EMAIL PROTECTED]>

        * font.cpp: More fixes to make stuff build/work (more or less).

        * text.patch: Patch to make text layout/rendering use my new code
        rather than pango.



Modified: trunk/moon/src/ChangeLog
===================================================================
--- trunk/moon/src/ChangeLog    2007-09-19 21:34:29 UTC (rev 86046)
+++ trunk/moon/src/ChangeLog    2007-09-19 21:36:36 UTC (rev 86047)
@@ -1,3 +1,10 @@
+2007-09-19  Jeffrey Stedfast  <[EMAIL PROTECTED]>
+
+       * font.cpp: More fixes to make stuff build/work (more or less).
+
+       * text.patch: Patch to make text layout/rendering use my new code
+       rather than pango.
+
 2007-09-19  Chris Toshok  <[EMAIL PROTECTED]>
 
        * text.cpp (TextBlock::Layout): don't insert multiple fg_attrs.

Modified: trunk/moon/src/Makefile.am
===================================================================
--- trunk/moon/src/Makefile.am  2007-09-19 21:34:29 UTC (rev 86046)
+++ trunk/moon/src/Makefile.am  2007-09-19 21:36:36 UTC (rev 86047)
@@ -19,6 +19,7 @@
        dependencyobject.h \
        downloader.h    \
        error.h         \
+       font.h          \
        frameworkelement.h \
        garray-ext.h    \
        geometry.h      \
@@ -60,6 +61,7 @@
        dirty.h \
        dirty.cpp       \
        downloader.cpp  \
+       font.cpp        \
        frameworkelement.cpp    \
        garray-ext.cpp  \
        geometry.cpp    \

Modified: trunk/moon/src/font.cpp
===================================================================
--- trunk/moon/src/font.cpp     2007-09-19 21:34:29 UTC (rev 86046)
+++ trunk/moon/src/font.cpp     2007-09-19 21:36:36 UTC (rev 86047)
@@ -18,7 +18,7 @@
 #include "font.h"
 
 
-static GHashTable *font_hash = NULL;
+static GHashTable *font_cache = NULL;
 static bool initialized = false;
 static FT_Library libft2;
 static double dpi;
@@ -37,7 +37,7 @@
                return;
        }
        
-       font_hash = g_hash_table_new ((GHashFunc) FcPatternHash, (GEqualFunc) 
FcPatternEqual);
+       font_cache = g_hash_table_new ((GHashFunc) FcPatternHash, (GEqualFunc) 
FcPatternEqual);
        
        pattern = FcPatternBuild (NULL, FC_FAMILY, FcTypeString, "Sans",
                                  FC_SIZE, FcTypeDouble, 10.0, NULL);
@@ -100,8 +100,10 @@
                return FC_WIDTH_SEMICONDENSED;
        case FontStretchesNormal:
                return FC_WIDTH_NORMAL;
+#if 0
        case FontStretchesMedium:
                return FC_WIDTH_NORMAL;
+#endif
        case FontStretchesSemiExpanded:
                return FC_WIDTH_SEMIEXPANDED;
        case FontStretchesExpanded:
@@ -128,26 +130,23 @@
 
 #define LOAD_FLAGS (FT_LOAD_NO_BITMAP | FT_LOAD_TARGET_NORMAL)
 
-Font::Font (FcPattern *pattern, double size)
+TextFont::TextFont (FcPattern *pattern, double size)
 {
        const char *filename = NULL;
        FcPattern *matched, *sans;
        bool retried = false;
        FcResult result;
        //double size;
-       int flags;
        int id;
        
        FcPatternReference (pattern);
        matched = pattern;
        
-       flags = FT_LOAD_NO_BITMAP | FT_LOAD_TARGET_NORMAL;
-       
        //FcPatternGetDouble (matched, FC_PIXEL_SIZE, 0, &size);
        
 retry:
        
-       if (FcPatternGetString (matched, FC_FILE, 0, &filename) != 
FcResultMatch)
+       if (FcPatternGetString (matched, FC_FILE, 0, (FcChar8 **) &filename) != 
FcResultMatch)
                goto fail;
        
        if (FcPatternGetInteger (matched, FC_INDEX, 0, &id) != FcResultMatch)
@@ -172,7 +171,7 @@
        
        FcPatternDestroy (matched);
        
-       FT_Set_Pixel_Sizes (face, 0, size);
+       FT_Set_Pixel_Sizes (face, 0, (int) size);
        
        glyphs = g_new0 (GlyphInfo, 256);
        glyphs[0].unichar = 1; /* invalidate */
@@ -183,7 +182,7 @@
        ref_count = 1;
 }
 
-Font::~Font ()
+TextFont::~TextFont ()
 {
        int i;
        
@@ -197,27 +196,27 @@
        FcPatternDestroy (pattern);
 }
 
-Font *
-Font::Load (FcPattern *pattern, double size)
+TextFont *
+TextFont::Load (FcPattern *pattern, double size)
 {
-       Font *font;
+       TextFont *font;
        
-       if ((font = (Font *) g_hash_table_lookup (font_cache, pattern))) {
+       if ((font = (TextFont *) g_hash_table_lookup (font_cache, pattern))) {
                font->ref ();
                return font;
        }
        
-       return new Font (pattern, size);
+       return new TextFont (pattern, size);
 }
 
 void
-Font::ref ()
+TextFont::ref ()
 {
        ref_count++;
 }
 
 void
-Font::unref ()
+TextFont::unref ()
 {
        ref_count--;
        
@@ -226,19 +225,19 @@
 }
 
 int
-Font::EmSize ()
+TextFont::EmSize ()
 {
        return face->units_per_EM;
 }
 
 int
-Font::Height ()
+TextFont::Height ()
 {
-       return face->height;
+       return face->height / 64;
 }
 
 const GlyphInfo *
-Font::GetGlyphInfo (uint32_t unichar)
+TextFont::GetGlyphInfo (uint32_t unichar)
 {
        GlyphInfo *glyph;
        uint32_t index;
@@ -255,17 +254,49 @@
                
                g_free (glyph->bitmap.buffer);
                
-               if (FT_Load_Glyph (face, glyph->index, LOAD_FLAGS) == 0) {
+               if (glyph->index > 0 && FT_Load_Glyph (face, glyph->index, 
LOAD_FLAGS) == 0) {
                        if (FT_Render_Glyph (face->glyph, 
FT_RENDER_MODE_NORMAL) != 0)
                                goto unavail;
                        
-                       memcpy (&glyph->metrics, &face->glyph->metrics, sizeof 
(&glyph->metrics));
+                       //memcpy (&glyph->metrics, &face->glyph->metrics, 
sizeof (glyph->metrics));
+                       glyph->metrics.horiBearingX = 
face->glyph->metrics.horiBearingX / 64;
+                       glyph->metrics.horiBearingY = 
face->glyph->metrics.horiBearingY / 64;
+                       glyph->metrics.vertBearingX = 
face->glyph->metrics.vertBearingX / 64;
+                       glyph->metrics.vertBearingY = 
face->glyph->metrics.vertBearingY / 64;
+                       glyph->metrics.horiAdvance = 
face->glyph->metrics.horiAdvance / 64;
+                       glyph->metrics.vertAdvance = 
face->glyph->metrics.vertAdvance / 64;
+                       glyph->metrics.height = face->glyph->metrics.height / 
64;
+                       glyph->metrics.width = face->glyph->metrics.width / 64;
                        
                        glyph->bitmap = face->glyph->bitmap;
-                       glyph->bitmap.buffer = g_memdup 
(face->glyph->bitmap.buffer,
-                                                        
face->glyph->bitmap.rows * face->glyph->bitmap.pitch);
+                       glyph->bitmap.buffer = (unsigned char *) g_memdup 
(face->glyph->bitmap.buffer,
+                                                                          
face->glyph->bitmap.rows *
+                                                                          
face->glyph->bitmap.pitch);
                        glyph->bitmap_left = face->glyph->bitmap_left;
                        glyph->bitmap_top = face->glyph->bitmap_top;
+               } else if (glyph->index == 0 && (unichar == 0x20 || unichar == 
0x09)) {
+                       glyph->metrics.horiBearingX = 0;
+                       glyph->metrics.horiBearingY = 0;
+                       glyph->metrics.horiBearingX = 0;
+                       glyph->metrics.horiBearingY = 0;
+                       
+                       memset (&glyph->bitmap, 0, sizeof (&glyph->bitmap));
+                       glyph->bitmap_left = 0;
+                       glyph->bitmap_top = 0;
+                       
+                       if (unichar == 0x20) {
+                               // Space
+                               glyph->metrics.horiAdvance = 
face->max_advance_width / 64;
+                               glyph->metrics.vertAdvance = 
face->max_advance_height / 64;
+                               glyph->metrics.height = 
face->max_advance_height / 64;
+                               glyph->metrics.width = face->max_advance_width 
/ 64;
+                       } else if (unichar == 0x09) {
+                               // Tab
+                               glyph->metrics.horiAdvance = 
face->max_advance_width / 8;
+                               glyph->metrics.vertAdvance = 
face->max_advance_height / 64;
+                               glyph->metrics.height = 
face->max_advance_height / 64;
+                               glyph->metrics.width = face->max_advance_width 
/ 8;
+                       }
                } else {
                unavail:
                        memset (&glyph->metrics, 0, sizeof (&glyph->metrics));
@@ -275,20 +306,20 @@
                }
        }
        
-       if (glyph->bitmap.buffer)
+       if (glyph->metrics.horiAdvance > 0)
                return glyph;
        
        return NULL;
 }
 
 void
-Font::Render (cairo_t *cr, const GlyphInfo *glyph)
+TextFont::Render (cairo_t *cr, const GlyphInfo *glyph)
 {
        // FIXME: render the glyph
 }
 
 void
-Font::Render (cairo_t *cr, uint32_t unichar)
+TextFont::Render (cairo_t *cr, uint32_t unichar)
 {
        const GlyphInfo *glyph;
        
@@ -299,7 +330,7 @@
 }
 
 
-FontDescription::FontDescription ()
+TextFontDescription::TextFontDescription ()
 {
        font = NULL;
        
@@ -312,12 +343,12 @@
        size = 14.666f;
 }
 
-FontDescription::FontDescription (const char *str)
+TextFontDescription::TextFontDescription (const char *str)
 {
        // FIXME: implement me
 }
 
-FontDescription::~FontDescription ()
+TextFontDescription::~TextFontDescription ()
 {
        if (font != NULL)
                font->unref ();
@@ -327,7 +358,7 @@
 }
 
 FcPattern *
-FontDescription::CreatePattern ()
+TextFontDescription::CreatePattern ()
 {
        FcPattern *pattern;
        char **families;
@@ -337,11 +368,11 @@
        FcPatternAddDouble (pattern, FC_DPI, dpi);
        
        if (set & FontMaskFilename)
-               FcPatternAddString (pattern, FC_FILE, filename);
+               FcPatternAddString (pattern, FC_FILE, (FcChar8 *) filename);
        
-       families = g_strsplit (GetFamily (), ',', -1);
+       families = g_strsplit (GetFamily (), ",", -1);
        for (i = 0; families[i]; i++)
-               FcPatternAddString (pattern, FC_FAMILY, families[i]);
+               FcPatternAddString (pattern, FC_FAMILY, (FcChar8 *) 
families[i]);
        g_strfreev (families);
        
        FcPatternAddInteger (pattern, FC_SLANT, fc_style (style));
@@ -352,28 +383,30 @@
        return pattern;
 }
 
-const Font *
-FontDescription::GetFont ()
+TextFont *
+TextFontDescription::GetFont ()
 {
        FcPattern *pattern;
        
        if (font == NULL) {
                pattern = CreatePattern ();
-               font = Font::Load (pattern, size);
+               font = TextFont::Load (pattern, size);
                FcPatternDestroy (pattern);
        }
        
+       font->ref ();
+       
        return font;
 }
 
 uint8_t
-FontDescription::GetFields ()
+TextFontDescription::GetFields ()
 {
        return set;
 }
 
 void
-FontDescription::UnsetFields (uint8_t mask)
+TextFontDescription::UnsetFields (uint8_t mask)
 {
        if (!(set & mask))
                return;
@@ -397,60 +430,60 @@
 }
 
 void
-FontDescription::Merge (FontDescription *font, bool replace)
+TextFontDescription::Merge (TextFontDescription *desc, bool replace)
 {
        bool changed = false;
        
-       if ((font->set & FontMaskFilename) && (!(set & FontMaskFilename) || 
replace)) {
-               if (strcmp (filename, font->filename) != 0) {
+       if ((desc->set & FontMaskFilename) && (!(set & FontMaskFilename) || 
replace)) {
+               if (!filename || strcmp (filename, desc->filename) != 0) {
                        g_free (filename);
-                       filename = g_strdup (font->filename);
+                       filename = g_strdup (desc->filename);
                        changed = true;
                }
                
                set |= FontMaskFilename;
        }
        
-       if ((font->set & FontMaskFamily) && (!(set & FontMaskFamily) || 
replace)) {
-               if (strcmp (family, font->family) != 0) {
+       if ((desc->set & FontMaskFamily) && (!(set & FontMaskFamily) || 
replace)) {
+               if (!family || strcmp (family, desc->family) != 0) {
                        g_free (family);
-                       family = g_strdup (font->family);
+                       family = g_strdup (desc->family);
                        changed = true;
                }
                
                set |= FontMaskFamily;
        }
        
-       if ((font->set & FontMaskStyle) && (!(set & FontMaskStyle) || replace)) 
{
-               if (style != font->style) {
-                       style = font->style;
+       if ((desc->set & FontMaskStyle) && (!(set & FontMaskStyle) || replace)) 
{
+               if (style != desc->style) {
+                       style = desc->style;
                        changed = true;
                }
                
                set |= FontMaskStyle;
        }
        
-       if ((font->set & FontMaskWeight) && (!(set & FontMaskWeight) || 
replace)) {
-               if (weight != font->weight) {
-                       weight = font->weight;
+       if ((desc->set & FontMaskWeight) && (!(set & FontMaskWeight) || 
replace)) {
+               if (weight != desc->weight) {
+                       weight = desc->weight;
                        changed = true;
                }
                
                set |= FontMaskWeight;
        }
        
-       if ((font->set & FontMaskStretch) && (!(set & FontMaskStretch) || 
replace)) {
-               if (stretch != font->stretch) {
-                       stretch = font->stretch;
+       if ((desc->set & FontMaskStretch) && (!(set & FontMaskStretch) || 
replace)) {
+               if (stretch != desc->stretch) {
+                       stretch = desc->stretch;
                        changed = true;
                }
                
                set |= FontMaskStretch;
        }
        
-       if ((font->set & FontMaskSize) && (!(set & FontMaskSize) || replace)) {
-               if (size != font->size) {
-                       size = font->size;
+       if ((desc->set & FontMaskSize) && (!(set & FontMaskSize) || replace)) {
+               if (size != desc->size) {
+                       size = desc->size;
                        changed = true;
                }
                
@@ -464,7 +497,7 @@
 }
 
 const char *
-FontDescription::GetFilename ()
+TextFontDescription::GetFilename ()
 {
        if (set & FontMaskFilename)
                return filename;
@@ -473,7 +506,7 @@
 }
 
 void
-FontDescription::SetFilename (const char *filename)
+TextFontDescription::SetFilename (const char *filename)
 {
        g_free (this->filename);
        
@@ -487,7 +520,7 @@
 }
 
 const char *
-FontDescription::GetFamily ()
+TextFontDescription::GetFamily ()
 {
        if (set & FontMaskFamily)
                return family;
@@ -496,7 +529,7 @@
 }
 
 void
-FontDescription::SetFamily (const char *family)
+TextFontDescription::SetFamily (const char *family)
 {
        g_free (this->family);
        
@@ -510,59 +543,59 @@
 }
 
 FontStyles
-FontDescription::GetStyle ()
+TextFontDescription::GetStyle ()
 {
        return style;
 }
 
 void
-FontDescription::SetStyle (FontStyles style)
+TextFontDescription::SetStyle (FontStyles style)
 {
        this->style = style;
        set |= FontMaskStyle;
 }
 
 FontWeights
-FontDescription::GetWeight ()
+TextFontDescription::GetWeight ()
 {
        return weight;
 }
 
 void
-FontDescription::SetWeight (FontWeights weight)
+TextFontDescription::SetWeight (FontWeights weight)
 {
        this->weight = weight;
        set |= FontMaskWeight;
 }
 
-FontStretchs
-FontDescription::GetStretch ()
+FontStretches
+TextFontDescription::GetStretch ()
 {
        return stretch;
 }
 
 void
-FontDescription::SetStretch (FontStretchs stretch)
+TextFontDescription::SetStretch (FontStretches stretch)
 {
        this->stretch = stretch;
        set |= FontMaskStretch;
 }
 
 double
-FontDescription::GetSize ()
+TextFontDescription::GetSize ()
 {
        return size;
 }
 
 void
-FontDescription::SetSize (double size)
+TextFontDescription::SetSize (double size)
 {
        this->size = size;
        set |= FontMaskSize;
 }
 
 char *
-FontDescription::ToString ()
+TextFontDescription::ToString ()
 {
        bool attrs = false;
        GString *str;
@@ -644,7 +677,7 @@
                        g_string_append (str, "ExtraBlack");
                        break;
                default:
-                       g_string_append_printf (str, "%d", (int) wieght);
+                       g_string_append_printf (str, "%d", (int) weight);
                        break;
                }
        }
@@ -671,9 +704,11 @@
                        break;
                case FontStretchesNormal:
                        break;
+#if 0
                case FontStretchesMedium:
                        g_string_append (str, "Medium");
                        break;
+#endif
                case FontStretchesSemiExpanded:
                        g_string_append (str, "SemiExpanded");
                        break;
@@ -695,26 +730,19 @@
 }
 
 
-TextRun::TextRun (const char *uft8, int len, TextDecorations deco, Font *font, 
Brush *fg)
+TextRun::TextRun (const char *utf8, int len, TextDecorations deco, 
TextFontDescription *font, Brush *fg)
 {
-       type = Run;
-       
        text = g_utf8_to_ucs4_fast (utf8, len, NULL);
-       
-       this->height = font->Height ();
+       this->font = font->GetFont ();
        this->deco = deco;
-       this->font = font;
        this->fg = fg;
 }
 
-TextRun::TextRun (TextDecorations deco, Font *font, Brush *fg)
+TextRun::TextRun (TextDecorations deco, TextFontDescription *font, Brush *fg)
 {
-       type = LineBreak;
-       
-       this->height = font->Height ();
+       this->font = font->GetFont ();
        this->text = NULL;
        this->deco = deco;
-       this->font = font;
        this->fg = fg;
 }
 
@@ -730,7 +758,7 @@
        TextDecorations deco;
        const uint32_t *text;
        int start, end;
-       Font *font;
+       TextFont *font;
        Brush *fg;
        
        int height;
@@ -768,7 +796,7 @@
 
 TextLine::~TextLine ()
 {
-       segments->Clear ();
+       segments->Clear (true);
        delete segments;
 }
 
@@ -857,8 +885,10 @@
 void
 TextLayout::SetTextRuns (List *runs)
 {
-       this->runs->Clear (true);
-       delete this->runs;
+       if (this->runs) {
+               this->runs->Clear (true);
+               delete this->runs;
+       }
        
        this->runs = runs;
        
@@ -884,11 +914,11 @@
 void
 TextLayout::Layout ()
 {
+       const GlyphInfo *glyph;
        TextSegment *segment;
-       GlyphInfo *glyph;
+       int lw, lh, myb;
        TextLine *line;
        TextRun *run;
-       int lw, lh;
        Space spc;
        int i;
        
@@ -898,15 +928,16 @@
        lines->Clear (true);
        lh = height = 0;
        lw = width = 0;
+       myb = 0;
        
-       if (!runs || runs->IsEmpty ())
+       if (!runs || runs->IsEmpty () || max_width == 0 || max_height == 0)
                return;
        
        line = new TextLine ();
        for (run = (TextRun *) runs->First (); run; run = (TextRun *) 
run->next) {
                lh = MAX (lh, run->font->Height ());
                
-               if (run->type == LineBreak) {
+               if (run->text == NULL /* LineBreak */) {
                        lines->Append (line);
                        line->height = lh;
                        
@@ -921,21 +952,24 @@
                        continue;
                }
                
-               if (!text[0])
+               if (!run->text[0])
                        continue;
                
                spc.index = -1;
+               spc.width = -1;
                segment = new TextSegment (run, 0);
                for (i = 0; run->text[i]; i++) {
                        if (!(glyph = run->font->GetGlyphInfo (run->text[i])))
                                continue;
                        
+                       myb = MAX (myb, glyph->metrics.horiBearingY);
+                       
                        if (g_unichar_isspace (run->text[i])) {
                                spc.index = i;
                                spc.width = lw;
                        }
                        
-                       if ((lw + glyph->metrics.horiAdvance) <= max_width) {
+                       if (max_width < 0 || (lw + glyph->metrics.horiAdvance) 
<= max_width) {
                                // this glyph fits nicely on this line
                                lw += glyph->metrics.horiAdvance;
                                continue;
@@ -943,12 +977,18 @@
                        
                        // need to wrap
                        if (spc.index != -1) {
+                               // wrap at the last lwsp char
                                segment->end = spc.index;
-                               lw = spc->width;
+                               lw = spc.width;
                                i = spc.index;
-                       } else {
+                       } else if (segment->start < i) {
+                               // have to break the word across lines
                                segment->end = i;
                                i--;
+                       } else {
+                               // glyphs are too large to fit within @max_width
+                               // we will have to limit 1 glyph per line
+                               segment->end = i + 1;
                        }
                        
                        // end this line
@@ -971,23 +1011,39 @@
                
                segment->end = i;
                line->segments->Append (segment);
+               
+               width = MAX (width, lw);
+               
+               if (max_height > 0 && height > max_height)
+                       break;
        }
        
-       if (line)
+       if (line) {
                lines->Append (line);
+               line->height = lh;
+               height += lh;
+       }
+       
+       if (lh > 0)
+               height += (lh - myb);
+       
+       height++;
+       width++;
+       
+       printf ("layout extents are %d, %d\n", width, height);
 }
 
 void
 TextLayout::Render (cairo_t *cr, UIElement *element, double x, double y)
 {
-       cairo_image_surface_t *surface;
        int width, height, stride;
+       cairo_surface_t *surface;
+       const FT_Bitmap *bitmap;
+       const GlyphInfo *glyph;
        TextSegment *segment;
        TextDecorations deco;
-       FT_Bitmap *bitmap;
-       Font *font = NULL;
+       TextFont *font = NULL;
        Brush *fg = NULL;
-       GlyphInfo *glyph;
        TextLine *line;
        double dx, dy;
        int i;
@@ -1013,25 +1069,36 @@
                                if (!(glyph = font->GetGlyphInfo 
(segment->text[i])))
                                        continue;
                                
-                               bitmap = &glyph->bitmap;
+                               if (glyph->index > 0) {
+                                       bitmap = &glyph->bitmap;
+                                       
+                                       height = bitmap->rows;
+                                       width = bitmap->width;
+                                       stride = bitmap->pitch;
+                                       
+                                       cairo_move_to (cr, x + dx, y + dy - 
glyph->metrics.horiBearingY);
+                                       
+                                       // Render the glyph
+                                       // FIXME: set the surface on the cached 
glyph?
+                                       surface = 
cairo_image_surface_create_for_data (bitmap->buffer,
+                                                                               
       CAIRO_FORMAT_A8,
+                                                                               
       width, height,
+                                                                               
       stride);
+                                       
+                                       cairo_save (cr);
+                                       cairo_set_source_surface (cr, surface, 
x + dx, y + dy - glyph->metrics.horiBearingY);
+                                       
+                                       cairo_new_path (cr);
+                                       cairo_rectangle (cr, x + dx, y + dy - 
glyph->metrics.horiBearingY,
+                                                        (double) width, 
(double) height);
+                                       cairo_close_path (cr);
+                                       cairo_fill (cr);
+                                       
+                                       cairo_surface_destroy (surface);
+                                       cairo_restore (cr);
+                               }
                                
-                               height = bitmap->rows;
-                               width = bitmap->width;
-                               stride = bitmap->pitch;
-                               
-                               cairo_move_to (cr, x + dx, y + dy);
-                               
-                               // Render the glyph
-                               surface = cairo_image_surface_create_for_data 
(bitmap->buffer,
-                                                                              
CAIRO_FORMAT_A8,
-                                                                              
width, height,
-                                                                              
stride);
-                               
-                               cairo_set_source_surface (cr, surface, 
glyph->bitmap_left, glyph->bitmap_top);
-                               
-                               cairo_surface_destroy (surface);
-                               
-                               dx += (double) glyph->metrics->horiAdvance;
+                               dx += (double) glyph->metrics.horiAdvance;
                        }
                        
                        segment = (TextSegment *) segment->next;
@@ -1042,117 +1109,3 @@
                dx = 0.0f;
        }
 }
-
-
-
-
-
-
-
-#if 0
-void
-TextLayout::Layout ()
-{
-       bool new_segment = true;
-       TextAttr *uline = NULL;
-       TextAttr *font = NULL;
-       TextAttr *fg = NULL;
-       TextSegment *segment;
-       GlyphInfo *glyph;
-       TextAttr *attr;
-       int i = 0;
-       int w, h;
-       
-       if (!dirty)
-               return;
-       
-       segments->Clear (true);
-       h = height = 0;
-       w = width = 0;
-       
-       if (!text || !text[0])
-               return;
-       
-       attr = (TextAttr *) attrs->First ();
-       
-       while (utext[i]) {
-               if (uline && uline->end <= i)
-                       uline = NULL;
-               if (font && font->end <= i)
-                       font = NULL;
-               if (fg && fg->end <= i)
-                       fg = NULL;
-               
-               while (attr) {
-                       if (attr->start > i)
-                               break;
-                       
-                       switch (attr->type) {
-                       case TextAttrForeground:
-                               new_segment = true;
-                               fg = attr;
-                               break;
-                       case TextAttrUnderline:
-                               new_segment = true;
-                               uline = attr;
-                               break;
-                       case TextAttrFont:
-                               new_segment = true;
-                               font = attr;
-                               break;
-                       }
-                       
-                       attr = (TextAttr *) attr->next;
-               }
-               
-               // we always need a font and an fg
-               g_assert (font != NULL);
-               g_assert (fg != NULL);
-               
-               if (new_segment) {
-                       if (segment)
-                               segment->end = i;
-                       
-                       segment = new TextSegment (Text, i);
-                       segment->uline = uline ? true : false;
-                       segment->font = font->font;
-                       segment->fg = fg->fg;
-                       
-                       segments->Append (segment);
-                       
-                       new_segment = false;
-               }
-               
-               if (utext[i] == '\n') {
-                       // insert a LineBreak segment
-                       if (segment->start < i) {
-                               segment = new TextSegment (LineBreak, i);
-                               segment->uline = uline ? true : false;
-                               segment->font = font->font;
-                               segment->fg = fg->fg;
-                               
-                               segments->Append (segment);
-                       } else {
-                               // current Text segment had no text
-                               segment->type = LineBreak;
-                       }
-                       
-                       width = MAX (width, w);
-                       segment->end = ++i;
-                       w = 0;
-                       
-                       segment = new TextSegment (Text, i);
-                       segment->uline = uline ? true : false;
-                       segment->font = font->font;
-                       segment->fg = fg->fg;
-                       
-                       segments->Append (segment);
-                       
-                       continue;
-               }
-               
-               glyph = font->font->GlyphInfo (utext[i]);
-               i++;
-       }
-}
-#endif

Modified: trunk/moon/src/font.h
===================================================================
--- trunk/moon/src/font.h       2007-09-19 21:34:29 UTC (rev 86046)
+++ trunk/moon/src/font.h       2007-09-19 21:36:36 UTC (rev 86047)
@@ -12,10 +12,17 @@
 #define __FONT_H__
 
 #include <stdint.h>
+
+#include <cairo.h>
 #include <ft2build.h>
 #include FT_FREETYPE_H
 #include <fontconfig/fontconfig.h>
+#include <fontconfig/fcfreetype.h>
 
+#include "uielement.h"
+#include "brush.h"
+#include "list.h"
+
 enum FontStretches {
        FontStretchesUltraCondensed = 1,
        FontStretchesExtraCondensed = 2,
@@ -76,12 +83,13 @@
 };
 
 
+G_BEGIN_DECLS
 void font_init (void);
+G_END_DECLS
 
-
 struct GlyphInfo;
 
-class Font {
+class TextFont {
        int ref_count;
        
        FcPattern *pattern;
@@ -89,16 +97,16 @@
        
        GlyphInfo *glyphs;
        
-       Font (FcPattern *pattern, double size);
+       TextFont (FcPattern *pattern, double size);
        
 public:
        
-       ~Font ();
+       ~TextFont ();
        
        void ref ();
        void unref ();
        
-       static Font *Load (FcPattern *pattern, double size);
+       static TextFont *Load (FcPattern *pattern, double size);
        
        const GlyphInfo *GetGlyphInfo (uint32_t unichar);
        
@@ -110,8 +118,8 @@
 };
 
 
-class FontDescription {
-       Font *font;
+class TextFontDescription {
+       TextFont *font;
        
        // bitmask of set attributes
        uint8_t set;
@@ -127,17 +135,17 @@
        FcPattern *CreatePattern ();
        
 public:
-       FontDescription ();
-       FontDescription (const char *str);
-       ~FontDescription ();
+       TextFontDescription ();
+       TextFontDescription (const char *str);
+       ~TextFontDescription ();
        
-       const Font *GetFont ();
+       TextFont *GetFont ();
        
        uint8_t GetFields ();
        
        void UnsetFields (uint8_t mask);
        
-       void Merge (FontDescription *font, bool replace);
+       void Merge (TextFontDescription *desc, bool replace);
        
        const char *GetFilename ();
        void SetFilename (const char *filename);
@@ -151,8 +159,8 @@
        FontWeights GetWeight ();
        void SetWeight (FontWeights weight);
        
-       FontStretchs GetStretch ();
-       void SetStretch (FontStretchs stretch);
+       FontStretches GetStretch ();
+       void SetStretch (FontStretches stretch);
        
        double GetSize ();
        void SetSize (double size);
@@ -161,24 +169,15 @@
 };
 
 
-enum TextRunType {
-       LineBreak,
-       Run,
-};
-
 class TextRun : public List::Node {
 public:
-       TextRunType type;
-       
        TextDecorations deco;
        uint32_t *text;
-       Font *font;
+       TextFont *font;
        Brush *fg;
        
-       int height;
-       
-       TextRun (const char *uft8, int len, TextDecorations deco, Font *font, 
Brush *fg);
-       TextRun (TextDecorations deco, Font *font, Brush *fg);
+       TextRun (const char *utf8, int len, TextDecorations deco, 
TextFontDescription *font, Brush *fg);
+       TextRun (TextDecorations deco, TextFontDescription *font, Brush *fg);
        ~TextRun ();
 };
 
@@ -216,7 +215,7 @@
        
        void Layout ();
        void GetPixelSize (int *w, int *h);
-       void Render (cairo_t *cr, UIElement *element);
+       void Render (cairo_t *cr, UIElement *element, double x, double y);
 };
 
 #endif /* __FONT_H__ */

Added: trunk/moon/src/text.patch
===================================================================
--- trunk/moon/src/text.patch   2007-09-19 21:34:29 UTC (rev 86046)
+++ trunk/moon/src/text.patch   2007-09-19 21:36:36 UTC (rev 86047)
@@ -0,0 +1,595 @@
+Index: text.h
+===================================================================
+--- text.h     (revision 86046)
++++ text.h     (working copy)
+@@ -17,56 +17,8 @@
+ #include <pango/pango.h>
+ 
+ #include "brush.h"
+-#include "mango.h"
++#include "font.h"
+ 
+-enum FontStretches {
+-      FontStretchesUltraCondensed = 1,
+-      FontStretchesExtraCondensed = 2,
+-      FontStretchesCondensed      = 3,
+-      FontStretchesSemiCondensed  = 4,
+-      FontStretchesNormal         = 5,
+-      FontStretchesMedium         = 5,
+-      FontStretchesSemiExpanded   = 6,
+-      FontStretchesExpanded       = 7,
+-      FontStretchesExtraExpanded  = 8,
+-      FontStretchesUltraExpanded  = 9
+-};
+-
+-enum FontStyles {
+-      FontStylesNormal,
+-      FontStylesOblique,
+-      FontStylesItalic
+-};
+-
+-enum FontWeights {
+-      FontWeightsThin       = 100,
+-      FontWeightsExtraLight = 200,
+-      FontWeightsLight      = 300,
+-      FontWeightsNormal     = 400,
+-      FontWeightsMedium     = 500,
+-      FontWeightsSemiBold   = 600,
+-      FontWeightsBold       = 700,
+-      FontWeightsExtraBold  = 800,
+-      FontWeightsBlack      = 900,
+-      FontWeightsExtraBlack = 950,
+-};
+-
+-enum StyleSimulations {
+-      StyleSimulationsNone
+-};
+-
+-enum TextDecorations {
+-      TextDecorationsNone,
+-      TextDecorationsUnderline
+-};
+-
+-enum TextWrapping {
+-      TextWrappingWrap,
+-      TextWrappingNoWrap,
+-      TextWrappingWrapWithOverflow
+-};
+-
+-
+ void text_init (void);
+ void text_destroy (void);
+ 
+@@ -86,7 +38,7 @@
+       virtual void OnPropertyChanged (DependencyProperty *prop);
+       virtual void OnSubPropertyChanged (DependencyProperty *prop, 
DependencyProperty *subprop);
+ 
+-      PangoFontDescription *font;
++      TextFontDescription *font;
+       Brush *foreground;
+ };
+ 
+@@ -137,6 +89,32 @@
+ 
+ 
+ class TextBlock : public FrameworkElement {
++      TextFontDescription *font;
++      TextLayout *layout;
++      Brush *foreground;
++      
++      bool dirty_actual_values;
++      double actual_height;
++      double actual_width;
++      
++      void CalcActualWidthHeight (cairo_t *cr);
++      void Layout (cairo_t *cr);
++      void Paint (cairo_t *cr);
++      
++      double GetActualWidth ()
++      {
++              if (dirty_actual_values)
++                      CalcActualWidthHeight (NULL);
++              return actual_width;
++      }
++      
++      double GetActualHeight ()
++      {
++              if (dirty_actual_values)
++                      CalcActualWidthHeight (NULL);
++              return actual_height;
++      }
++      
+ public:
+       static DependencyProperty *ActualHeightProperty;
+       static DependencyProperty *ActualWidthProperty;
+@@ -172,34 +150,6 @@
+       virtual Value *GetValue (DependencyProperty *property);
+       virtual void SetValue (DependencyProperty *property, Value *value);
+       virtual void SetValue (DependencyProperty *property, Value value);
+-      
+-private:
+-      PangoFontDescription *font;
+-      MangoRenderer *renderer;
+-      PangoLayout *layout;
+-      Brush *foreground;
+-      
+-      bool dirty_actual_values;
+-      double actual_height;
+-      double actual_width;
+-      
+-      void CalcActualWidthHeight (cairo_t *cr);
+-      void Layout (cairo_t *cr);
+-      void Paint (cairo_t *cr);
+-
+-      double GetActualWidth ()
+-      {
+-              if (dirty_actual_values)
+-                      CalcActualWidthHeight (NULL);
+-              return actual_width;
+-      }
+-
+-      double GetActualHeight ()
+-      {
+-              if (dirty_actual_values)
+-                      CalcActualWidthHeight (NULL);
+-              return actual_height;
+-      }
+ };
+ 
+ TextBlock *text_block_new (void);
+Index: text.cpp
+===================================================================
+--- text.cpp   (revision 86046)
++++ text.cpp   (working copy)
+@@ -22,66 +22,11 @@
+ #include "text.h"
+ 
+ 
+-static PangoStretch
+-font_stretch (FontStretches stretch)
+-{
+-      switch (stretch) {
+-      case FontStretchesUltraCondensed:
+-              return PANGO_STRETCH_ULTRA_CONDENSED;
+-      case FontStretchesExtraCondensed:
+-              return PANGO_STRETCH_EXTRA_CONDENSED;
+-      case FontStretchesCondensed:
+-              return PANGO_STRETCH_CONDENSED;
+-      case FontStretchesSemiCondensed:
+-              return PANGO_STRETCH_SEMI_CONDENSED;
+-      case FontStretchesNormal: // FontStretchesMedium (alias)
+-      default:
+-              return PANGO_STRETCH_NORMAL;
+-      case FontStretchesSemiExpanded:
+-              return PANGO_STRETCH_SEMI_EXPANDED;
+-      case FontStretchesExpanded:
+-              return PANGO_STRETCH_EXPANDED;
+-      case FontStretchesExtraExpanded:
+-              return PANGO_STRETCH_EXTRA_EXPANDED;
+-      case FontStretchesUltraExpanded:
+-              return PANGO_STRETCH_ULTRA_EXPANDED;
+-      }
+-}
++static SolidColorBrush *default_foreground_brush = NULL;
+ 
+-static PangoStyle
+-font_style (FontStyles style)
+-{
+-      switch (style) {
+-      case FontStylesNormal:
+-      default:
+-              return PANGO_STYLE_NORMAL;
+-      case FontStylesOblique:
+-              return PANGO_STYLE_OBLIQUE;
+-      case FontStylesItalic:
+-              return PANGO_STYLE_ITALIC;
+-      }
+-}
+-
+-static PangoWeight
+-font_weight (FontWeights weight)
+-{
+-      // FontWeights and PangoWeight values map exactly
+-      
+-      if (weight > 900) {
+-              // FontWeighs have values between 100-999, Pango only allows 
100-900
+-              return (PangoWeight) 900;
+-      }
+-      
+-      return (PangoWeight) weight;
+-}
+-
+-
+-SolidColorBrush *default_foreground_brush = NULL;
+-      
+ static Brush *
+ default_foreground (void)
+ {
+-      
+       if (!default_foreground_brush) {
+               default_foreground_brush = new SolidColorBrush ();
+               Color *color = color_from_str ("black");
+@@ -108,12 +53,12 @@
+       foreground = NULL;
+       
+       /* initialize the font description */
+-      font = pango_font_description_new ();
++      font = new TextFontDescription ();
+ }
+ 
+ Inline::~Inline ()
+ {
+-      pango_font_description_free (font);
++      delete font;
+       
+       if (foreground != NULL) {
+               foreground->Detach (NULL, this);
+@@ -131,19 +76,19 @@
+     
+       if (prop == Inline::FontFamilyProperty) {
+               char *family = inline_get_font_family (this);
+-              pango_font_description_set_family (font, family);
++              font->SetFamily (family);
+       } else if (prop == Inline::FontSizeProperty) {
+               double size = inline_get_font_size (this);
+-              pango_font_description_set_absolute_size (font, size * 
PANGO_SCALE);
++              font->SetSize (size);
+       } else if (prop == Inline::FontStretchProperty) {
+               FontStretches stretch = inline_get_font_stretch (this);
+-              pango_font_description_set_stretch (font, font_stretch 
(stretch));
++              font->SetStretch (stretch);
+       } else if (prop == Inline::FontStyleProperty) {
+               FontStyles style = inline_get_font_style (this);
+-              pango_font_description_set_style (font, font_style (style));
++              font->SetStyle (style);
+       } else if (prop == Inline::FontWeightProperty) {
+               FontWeights weight = inline_get_font_weight (this);
+-              pango_font_description_set_weight (font, font_weight (weight));
++              font->SetWeight (weight);
+       } else if (prop == Inline::ForegroundProperty) {
+               if (foreground != NULL) {
+                       foreground->Detach (NULL, this);
+@@ -321,8 +266,6 @@
+ 
+ TextBlock::TextBlock ()
+ {
+-      renderer = (MangoRenderer *) mango_renderer_new ();
+-      
+       foreground = NULL;
+       
+       layout = NULL;
+@@ -332,17 +275,17 @@
+       dirty_actual_values = true;
+       
+       /* initialize the font description */
+-      font = pango_font_description_new ();
++      font = new TextFontDescription ();
+       char *family = text_block_get_font_family (this);
+-      pango_font_description_set_family (font, family);
++      font->SetFamily (family);
+       double size = text_block_get_font_size (this);
+-      pango_font_description_set_absolute_size (font, size * PANGO_SCALE);
++      font->SetSize (size);
+       FontStretches stretch = text_block_get_font_stretch (this);
+-      pango_font_description_set_stretch (font, font_stretch (stretch));
++      font->SetStretch (stretch);
+       FontStyles style = text_block_get_font_style (this);
+-      pango_font_description_set_style (font, font_style (style));
++      font->SetStyle (style);
+       FontWeights weight = text_block_get_font_weight (this);
+-      pango_font_description_set_weight (font, font_weight (weight));
++      font->SetWeight (weight);
+       
+       // this has to come last, since in our OnPropertyChanged
+       // method we update our bounds.
+@@ -352,13 +295,11 @@
+ 
+ TextBlock::~TextBlock ()
+ {
+-      pango_font_description_free (font);
++      delete font;
+       
+       if (layout)
+-              g_object_unref (layout);
++              delete layout;
+       
+-      g_object_unref (renderer);
+-      
+       if (foreground != NULL) {
+               foreground->Detach (NULL, this);
+               foreground->unref ();
+@@ -374,11 +315,6 @@
+ void
+ TextBlock::Render (cairo_t *cr, int x, int y, int width, int height)
+ {
+-      const char *text = pango_layout_get_text (layout);
+-      
+-      if (!text || !text[0])
+-              return;
+-      
+       cairo_save (cr);
+       cairo_set_matrix (cr, &absolute_xform);
+       Paint (cr);
+@@ -461,17 +397,12 @@
+ void
+ TextBlock::Layout (cairo_t *cr)
+ {
+-      PangoAttribute *uline_attr = NULL;
+-      PangoAttribute *font_attr = NULL;
+-      PangoAttribute *fg_attr = NULL;
+-      PangoAttribute *attr = NULL;
+       TextDecorations decorations;
+       double clip_height, width;
+-      PangoFontMask font_mask;
+-      PangoAttrList *attrs;
+-      size_t start, end;
++      TextWrapping wrapping;
++      uint8_t font_mask;
+       bool clip = false;
+-      GString *block;
++      List *runs;
+       char *text;
+       Brush *fg;
+       int w, h;
+@@ -482,68 +413,39 @@
+               fg = foreground;
+       
+       if (layout == NULL)
+-              layout = pango_cairo_create_layout (cr);
++              layout = new TextLayout ();
+       
+       clip_height = framework_element_get_height (this);
+-      switch (text_block_get_text_wrapping (this)) {
++      wrapping = text_block_get_text_wrapping (this);
++      layout->SetWrapping (wrapping);
++      switch (wrapping) {
+       case TextWrappingWrap:
+               // same as w/ Overflow except we clip height (if defined)
+               if (clip_height > 0.0)
+                       clip = true;
+       case TextWrappingWrapWithOverflow:
+-              pango_layout_set_wrap (layout, PANGO_WRAP_WORD_CHAR);
+-              
+               width = framework_element_get_width (this);
+               
+-              if (width > 0.0)
+-                      pango_layout_set_width (layout, (int) width * 
PANGO_SCALE);
+-              else
+-                      pango_layout_set_width (layout, -1);
++              layout->SetMaxWidth ((int) width);
+               break;
+       default:
+-              pango_layout_set_width (layout, -1);
++              layout->SetMaxWidth (-1);
+               break;
+       }
+       
+-      block = g_string_new ("");
+-      attrs = pango_attr_list_new ();
++      runs = new List ();
+       
+-      font_mask = pango_font_description_get_set_fields (font);
++      font_mask = font->GetFields ();
+       decorations = text_block_get_text_decorations (this);
+       text = text_block_get_text (this);
+-      if (text && *text) {
+-              g_string_append (block, text);
+-              end = block->len;
+-              start = 0;
+-              
+-              font_attr = pango_attr_font_desc_new (font);
+-              font_attr->start_index = start;
+-              font_attr->end_index = end;
+-              
+-              pango_attr_list_insert (attrs, font_attr);
+-              
+-              if (decorations == TextDecorationsUnderline) {
+-                      uline_attr = pango_attr_underline_new 
(PANGO_UNDERLINE_SINGLE);
+-                      uline_attr->start_index = start;
+-                      uline_attr->end_index = end;
+-                      
+-                      pango_attr_list_insert (attrs, uline_attr);
+-              } else {
+-                      uline_attr = NULL;
+-              }
+-              
+-              fg_attr = mango_attr_foreground_new (this, fg);
+-              fg_attr->start_index = start;
+-              fg_attr->end_index = end;
+-              
+-              pango_attr_list_insert (attrs, fg_attr);
+-      }
++      if (text && *text)
++              runs->Append (new TextRun (text, -1, decorations, font, fg));
+       
+       Inlines *inlines = text_block_get_inlines (this);
+       
+       if (inlines != NULL) {
+               Collection::Node *node = (Collection::Node *) 
inlines->list->First ();
+-              PangoFontMask run_mask, inherited_mask;
++              uint8_t run_mask, inherited_mask;
+               TextDecorations deco;
+               Value *value;
+               Inline *item;
+@@ -552,103 +454,53 @@
+               while (node != NULL) {
+                       item = (Inline *) node->obj;
+                       
++                      // Inlines inherit their parent TextBlock's font 
properties if
++                      // they don't specify their own.
++                      run_mask = item->font->GetFields ();
++                      item->font->Merge (font, false);
++                      
++                      inherited_mask = (FontMask) (font_mask & ~run_mask);
++                      
++                      // Inherit the TextDecorations from the parent 
TextBlock if unset
++                      value = item->GetValue 
(Inline::TextDecorationsProperty);
++                      deco = value ? (TextDecorations) value->AsInt32 () : 
decorations;
++                      
+                       switch (item->GetObjectType ()) {
+                       case Type::RUN:
+                               run = (Run *) item;
+                               
+                               text = run_get_text (run);
+                               
+-                              if (text == NULL || *text == '\0') {
+-                                      // optimization
+-                                      goto loop;
++                              if (text && text[0]) {
++                                      if (item->foreground)
++                                              runs->Append (new TextRun 
(text, -1, deco, item->font, item->foreground));
++                                      else
++                                              runs->Append (new TextRun 
(text, -1, deco, item->font, fg));
+                               }
+                               
+-                              start = block->len;
+-                              g_string_append (block, text);
+-                              end = block->len;
+                               break;
+                       case Type::LINEBREAK:
+-                              start = block->len;
+-                              g_string_append_c (block, '\n');
+-                              end = block->len;
++                              if (item->foreground)
++                                      runs->Append (new TextRun (deco, 
item->font, item->foreground));
++                              else
++                                      runs->Append (new TextRun (deco, 
item->font, fg));
+                               break;
+                       default:
+-                              goto loop;
+                               break;
+                       }
+                       
+-                      // Inlines inherit their parent TextBlock's font 
properties if
+-                      // they don't specify their own.
+-                      run_mask = pango_font_description_get_set_fields 
(item->font);
+-                      pango_font_description_merge (item->font, font, false);
+-                      inherited_mask = (PangoFontMask) (font_mask & 
~run_mask);
+-                      
+-                      attr = pango_attr_font_desc_new (item->font);
+-                      attr->start_index = start;
+-                      attr->end_index = end;
+-                      
+-                      if (!font_attr || !pango_attribute_equal ((const 
PangoAttribute *) font_attr, (const PangoAttribute *) attr)) {
+-                              pango_attr_list_insert (attrs, attr);
+-                              font_attr = attr;
+-                      } else {
+-                              pango_attribute_destroy (attr);
+-                              font_attr->end_index = end;
+-                      }
+-                      
+                       if (inherited_mask != 0)
+-                              pango_font_description_unset_fields 
(item->font, inherited_mask);
++                              item->font->UnsetFields (inherited_mask);
+                       
+-                      // Inherit the TextDecorations from the parent 
TextBlock if unset
+-                      value = item->GetValue 
(Inline::TextDecorationsProperty);
+-                      deco = value ? (TextDecorations) value->AsInt32 () : 
decorations;
+-                      if (deco == TextDecorationsUnderline) {
+-                              if (uline_attr == NULL) {
+-                                      uline_attr = pango_attr_underline_new 
(PANGO_UNDERLINE_SINGLE);
+-                                      uline_attr->start_index = start;
+-                                      uline_attr->end_index = end;
+-                                      
+-                                      pango_attr_list_insert (attrs, 
uline_attr);
+-                              } else {
+-                                      uline_attr->end_index = end;
+-                              }
+-                      } else {
+-                              uline_attr = NULL;
+-                      }
+-                      
+-                      // Inlines also inherit their Foreground property from 
their parent
+-                      // TextBlock if not set explicitly
+-                      if (item->foreground)
+-                              attr = mango_attr_foreground_new (this, 
item->foreground);
+-                      else
+-                              attr = mango_attr_foreground_new (this, fg);
+-                      attr->start_index = start;
+-                      attr->end_index = end;
+-                      
+-                      if (!fg_attr || !pango_attribute_equal ((const 
PangoAttribute *) fg_attr, (const PangoAttribute *) attr)) {
+-                              pango_attr_list_insert (attrs, attr);
+-                              fg_attr = attr;
+-                      } else {
+-                              pango_attribute_destroy (attr);
+-                              fg_attr->end_index = end;
+-                      }
+-                      
+-              loop:
+                       node = (Collection::Node *) node->next;
+               }
+       }
+       
+-      // Now that we have our PangoAttrList setup, set it and the text on the 
PangoLayout
+-      pango_layout_set_text (layout, block->str, block->len);
+-      g_string_free (block, true);
++      layout->SetTextRuns (runs);
++      layout->Layout ();
+       
+-      pango_layout_set_attributes (layout, attrs);
++      layout->GetPixelSize (&w, &h);
+       
+-      pango_cairo_update_layout (cr, layout);
+-      mango_renderer_set_cairo_context (renderer, cr);
+-      mango_renderer_layout_path (renderer, layout);
+-      pango_layout_get_pixel_size (layout, &w, &h);
+-      pango_attr_list_unref (attrs);
+-      
+       if (clip && (h > clip_height))
+               text_block_set_actual_height (this, (double) clip_height);
+       else
+@@ -663,7 +515,7 @@
+       TextWrapping wrapping = text_block_get_text_wrapping (this);
+       double h = GetActualHeight ();
+       double w = framework_element_get_width (this);
+-
++      
+       if (wrapping != TextWrappingWrapWithOverflow)
+               h = framework_element_get_height (this);
+       
+@@ -672,9 +524,7 @@
+               cairo_clip (cr);
+       }
+       
+-      pango_cairo_update_layout (cr, layout);
+-      mango_renderer_set_cairo_context (renderer, cr);
+-      mango_renderer_show_layout (renderer, layout);
++      layout->Render (cr, this, 0.0, 0.0);
+ }
+ 
+ void
+@@ -687,19 +537,19 @@
+       
+       if (prop == TextBlock::FontFamilyProperty) {
+               char *family = text_block_get_font_family (this);
+-              pango_font_description_set_family (font, family);
++              font->SetFamily (family);
+       } else if (prop == TextBlock::FontSizeProperty) {
+               double size = text_block_get_font_size (this);
+-              pango_font_description_set_absolute_size (font, size * 
PANGO_SCALE);
++              font->SetSize (size);
+       } else if (prop == TextBlock::FontStretchProperty) {
+               FontStretches stretch = text_block_get_font_stretch (this);
+-              pango_font_description_set_stretch (font, font_stretch 
(stretch));
++              font->SetStretch (stretch);
+       } else if (prop == TextBlock::FontStyleProperty) {
+               FontStyles style = text_block_get_font_style (this);
+-              pango_font_description_set_style (font, font_style (style));
++              font->SetStyle (style);
+       } else if (prop == TextBlock::FontWeightProperty) {
+               FontWeights weight = text_block_get_font_weight (this);
+-              pango_font_description_set_weight (font, font_weight (weight));
++              font->SetWeight (weight);
+       } else if (prop == TextBlock::TextProperty) {
+               // will be updated later in Layout()
+       } else if (prop == TextBlock::InlinesProperty) {
+@@ -1141,6 +991,8 @@
+ void
+ text_init (void)
+ {
++      font_init ();
++      
+       // Inline
+       Inline::FontFamilyProperty = DependencyObject::Register (Type::INLINE, 
"FontFamily", Type::STRING);
+       Inline::FontSizeProperty = DependencyObject::Register (Type::INLINE, 
"FontSize", Type::DOUBLE);

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

Reply via email to