Blob Blame History Raw
Fix crash with bitmap fonts. Fixes #477158
https://bugzilla.redhat.com/show_bug.cgi?id=477158

Comes from this upstream commit:

r19758 | buliabyak | 2008-08-28 20:35:16 +0200 (Thu, 28 Aug 2008) | 1 line
null check fixes patch from bug 261475

diff -up inkscape-0.46/src/libnrtype/FontFactory.cpp.bitmap-fonts inkscape-0.46/src/libnrtype/FontFactory.cpp
--- inkscape-0.46/src/libnrtype/FontFactory.cpp.bitmap-fonts	2008-03-11 05:20:29.000000000 +0100
+++ inkscape-0.46/src/libnrtype/FontFactory.cpp	2009-01-13 21:37:13.000000000 +0100
@@ -817,7 +817,8 @@ font_instance *font_factory::Face(PangoF
         res->Ref();
         AddInCache(res);
     }
-    res->InitTheFace();
+    if(res)
+	res->InitTheFace();
     return res;
 }
 
diff -up inkscape-0.46/src/libnrtype/Layout-TNG-Compute.cpp.bitmap-fonts inkscape-0.46/src/libnrtype/Layout-TNG-Compute.cpp
--- inkscape-0.46/src/libnrtype/Layout-TNG-Compute.cpp.bitmap-fonts	2008-03-11 05:20:29.000000000 +0100
+++ inkscape-0.46/src/libnrtype/Layout-TNG-Compute.cpp	2009-01-13 21:37:13.000000000 +0100
@@ -475,9 +475,9 @@ class Layout::Calculator
                 new_span.in_input_stream_item = unbroken_span.input_index;
                 new_span.baseline_shift = _y_offset;
                 new_span.block_progression = _block_progression;
-                if (_flow._input_stream[unbroken_span.input_index]->Type() == TEXT_SOURCE) {
-                    new_span.font = para.pango_items[unbroken_span.pango_item_index].font;
-                    new_span.font->Ref();
+                if ((_flow._input_stream[unbroken_span.input_index]->Type() == TEXT_SOURCE) && (new_span.font = para.pango_items[unbroken_span.pango_item_index].font))
+                    {
+		    new_span.font->Ref();
                     new_span.font_size = unbroken_span.font_size;
                     new_span.direction = para.pango_items[unbroken_span.pango_item_index].item->analysis.level & 1 ? RIGHT_TO_LEFT : LEFT_TO_RIGHT;
                     new_span.input_stream_first_character = Glib::ustring::const_iterator(unbroken_span.input_stream_first_character.base() + it_span->start.char_byte);
@@ -562,7 +562,7 @@ class Layout::Calculator
                             new_glyph.x = x + unbroken_span.glyph_string->glyphs[glyph_index].geometry.x_offset * font_size_multiplier;
                             new_glyph.y = _y_offset + unbroken_span.glyph_string->glyphs[glyph_index].geometry.y_offset * font_size_multiplier;
                             new_glyph.width = unbroken_span.glyph_string->glyphs[glyph_index].geometry.width * font_size_multiplier;
-                            if (new_glyph.width == 0)
+                            if ((new_glyph.width == 0) && (para.pango_items[unbroken_span.pango_item_index].font))
                                 new_glyph.width = new_span.font_size * para.pango_items[unbroken_span.pango_item_index].font->Advance(unbroken_span.glyph_string->glyphs[glyph_index].glyph, false);
                                 // for some reason pango returns zero width for invalid glyph characters (those empty boxes), so go to freetype for the info
                         }
@@ -903,7 +903,8 @@ void Layout::Calculator::_computeFontLin
         line_height->setZero();
         *line_height_multiplier = 1.0;
     }
-    font->FontMetrics(line_height->ascent, line_height->descent, line_height->leading);
+    else
+	font->FontMetrics(line_height->ascent, line_height->descent, line_height->leading);
     *line_height *= font_size;
 
     // yet another borked SPStyle member that we're going to have to fix ourselves
diff -up inkscape-0.46/src/libnrtype/Layout-TNG-Output.cpp.bitmap-fonts inkscape-0.46/src/libnrtype/Layout-TNG-Output.cpp
--- inkscape-0.46/src/libnrtype/Layout-TNG-Output.cpp.bitmap-fonts	2008-03-11 05:20:29.000000000 +0100
+++ inkscape-0.46/src/libnrtype/Layout-TNG-Output.cpp	2009-01-13 21:39:18.000000000 +0100
@@ -112,21 +112,23 @@ void Layout::getBoundingBox(NRRect *boun
         _getGlyphTransformMatrix(glyph_index, &glyph_matrix);
         NR::Matrix total_transform = glyph_matrix;
         total_transform *= transform;
-        NR::Maybe<NR::Rect> glyph_rect = _glyphs[glyph_index].span(this).font->BBox(_glyphs[glyph_index].glyph);
-        if (glyph_rect) {
-            NR::Point bmi = glyph_rect->min(), bma = glyph_rect->max();
-            NR::Point tlp(bmi[0],bmi[1]), trp(bma[0],bmi[1]), blp(bmi[0],bma[1]), brp(bma[0],bma[1]);
-            tlp *= total_transform;
-            trp *= total_transform;
-            blp *= total_transform;
-            brp *= total_transform;
-            *glyph_rect = NR::Rect(tlp,trp);
-            glyph_rect->expandTo(blp);
-            glyph_rect->expandTo(brp);
-            if ( (glyph_rect->min())[0] < bounding_box->x0 ) bounding_box->x0=(glyph_rect->min())[0];
-            if ( (glyph_rect->max())[0] > bounding_box->x1 ) bounding_box->x1=(glyph_rect->max())[0];
-            if ( (glyph_rect->min())[1] < bounding_box->y0 ) bounding_box->y0=(glyph_rect->min())[1];
-            if ( (glyph_rect->max())[1] > bounding_box->y1 ) bounding_box->y1=(glyph_rect->max())[1];
+        if (_glyphs[glyph_index].span(this).font) {
+            NR::Maybe<NR::Rect> glyph_rect = _glyphs[glyph_index].span(this).font->BBox(_glyphs[glyph_index].glyph);
+            if (glyph_rect) {
+                NR::Point bmi = glyph_rect->min(), bma = glyph_rect->max();
+                NR::Point tlp(bmi[0],bmi[1]), trp(bma[0],bmi[1]), blp(bmi[0],bma[1]), brp(bma[0],bma[1]);
+                tlp *= total_transform;
+                trp *= total_transform;
+                blp *= total_transform;
+                brp *= total_transform;
+                *glyph_rect = NR::Rect(tlp,trp);
+                glyph_rect->expandTo(blp);
+                glyph_rect->expandTo(brp);
+                if ( (glyph_rect->min())[0] < bounding_box->x0 ) bounding_box->x0=(glyph_rect->min())[0];
+                if ( (glyph_rect->max())[0] > bounding_box->x1 ) bounding_box->x1=(glyph_rect->max())[0];
+                if ( (glyph_rect->min())[1] < bounding_box->y0 ) bounding_box->y0=(glyph_rect->min())[1];
+                if ( (glyph_rect->max())[1] > bounding_box->y1 ) bounding_box->y1=(glyph_rect->max())[1];
+            }
         }
     }
 }