Code

null check fixes patch from bug 261475
authorbuliabyak <buliabyak@users.sourceforge.net>
Thu, 28 Aug 2008 18:35:16 +0000 (18:35 +0000)
committerbuliabyak <buliabyak@users.sourceforge.net>
Thu, 28 Aug 2008 18:35:16 +0000 (18:35 +0000)
src/libnrtype/FontFactory.cpp
src/libnrtype/Layout-TNG-Compute.cpp
src/libnrtype/Layout-TNG-Output.cpp

index 760ee87b61a07763f1bd10a750f157b239681e54..f2d3be60a1877615dadd91c93c77d79131c50beb 100644 (file)
@@ -821,7 +821,8 @@ font_instance *font_factory::Face(PangoFontDescription *descr, bool canFail)
         res->Ref();
         AddInCache(res);
     }
-    res->InitTheFace();
+    if(res)
+       res->InitTheFace();
     return res;
 }
 
index c1897e06684a4fa7eabe7ec74b2e4b293d719435..96ea2be7c9032978f5f0b16c604ab6230fe18d7f 100644 (file)
@@ -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::_computeFontLineHeight(font_instance *font, double font
         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
index aa387504825a95973d9a28f67cec243406dc2dbe..a3857b476a7f503287403489bb17b857f59e4075 100644 (file)
@@ -116,22 +116,24 @@ void Layout::getBoundingBox(NRRect *bounding_box, NR::Matrix const &transform, i
         _getGlyphTransformMatrix(glyph_index, &glyph_matrix);
         NR::Matrix total_transform = glyph_matrix;
         total_transform *= transform;
-        boost::optional<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) {
+           boost::optional<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];
+            }
+       }
     }
 }