summaryrefslogtreecommitdiffstats
path: root/src/libnrtype
diff options
context:
space:
mode:
authorMenTaLguY <mental@rydia.net>2007-03-11 21:23:04 +0000
committermental <mental@users.sourceforge.net>2007-03-11 21:23:04 +0000
commit4e432e5960cb8bc9feb6648087b54788c774d773 (patch)
treef83b7730dfb4ff96d45fb96e83367ab3dc28e56f /src/libnrtype
parentSwitch selection bounds and center to use NR::Maybe, addressing most of the (diff)
downloadinkscape-4e432e5960cb8bc9feb6648087b54788c774d773.tar.gz
inkscape-4e432e5960cb8bc9feb6648087b54788c774d773.zip
Eliminate remaining sources of empty NR::Rects
(bzr r2605)
Diffstat (limited to 'src/libnrtype')
-rw-r--r--src/libnrtype/FontInstance.cpp14
-rwxr-xr-xsrc/libnrtype/Layout-TNG-OutIter.cpp2
-rwxr-xr-xsrc/libnrtype/Layout-TNG-Output.cpp30
-rwxr-xr-xsrc/libnrtype/Layout-TNG.h2
-rw-r--r--src/libnrtype/RasterFont.cpp32
-rw-r--r--src/libnrtype/font-instance.h3
6 files changed, 46 insertions, 37 deletions
diff --git a/src/libnrtype/FontInstance.cpp b/src/libnrtype/FontInstance.cpp
index 574a76f62..419a631a5 100644
--- a/src/libnrtype/FontInstance.cpp
+++ b/src/libnrtype/FontInstance.cpp
@@ -611,7 +611,7 @@ bool font_instance::FontSlope(double &run, double &rise)
return true;
}
-NR::Rect font_instance::BBox(int glyph_id)
+NR::Maybe<NR::Rect> font_instance::BBox(int glyph_id)
{
int no=-1;
if ( id_to_no.find(glyph_id) == id_to_no.end() ) {
@@ -624,11 +624,13 @@ NR::Rect font_instance::BBox(int glyph_id)
} else {
no=id_to_no[glyph_id];
}
- if ( no < 0 ) return NR::Rect(NR::Point(0,0),NR::Point(0,0));
- NR::Point rmin(glyphs[no].bbox[0],glyphs[no].bbox[1]);
- NR::Point rmax(glyphs[no].bbox[2],glyphs[no].bbox[3]);
- NR::Rect res(rmin,rmax);
- return res;
+ if ( no < 0 ) {
+ return NR::Nothing();
+ } else {
+ NR::Point rmin(glyphs[no].bbox[0],glyphs[no].bbox[1]);
+ NR::Point rmax(glyphs[no].bbox[2],glyphs[no].bbox[3]);
+ return NR::Rect(rmin, rmax);
+ }
}
Path* font_instance::Outline(int glyph_id,Path* copyInto)
diff --git a/src/libnrtype/Layout-TNG-OutIter.cpp b/src/libnrtype/Layout-TNG-OutIter.cpp
index 8c525084e..167352bd3 100755
--- a/src/libnrtype/Layout-TNG-OutIter.cpp
+++ b/src/libnrtype/Layout-TNG-OutIter.cpp
@@ -201,7 +201,7 @@ Layout::iterator Layout::sourceToIterator(void *source_cookie) const
return sourceToIterator(source_cookie, Glib::ustring::const_iterator(std::string::const_iterator(NULL)));
}
-NR::Rect Layout::glyphBoundingBox(iterator const &it, double *rotation) const
+NR::Maybe<NR::Rect> Layout::glyphBoundingBox(iterator const &it, double *rotation) const
{
if (rotation) *rotation = _glyphs[it._glyph_index].rotation;
return _glyphs[it._glyph_index].span(this).font->BBox(_glyphs[it._glyph_index].glyph);
diff --git a/src/libnrtype/Layout-TNG-Output.cpp b/src/libnrtype/Layout-TNG-Output.cpp
index 5152909f8..68d7752c3 100755
--- a/src/libnrtype/Layout-TNG-Output.cpp
+++ b/src/libnrtype/Layout-TNG-Output.cpp
@@ -113,20 +113,22 @@ 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;
- NR::Rect glyph_rect = _glyphs[glyph_index].span(this).font->BBox(_glyphs[glyph_index].glyph);
- 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];
+ 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];
+ }
}
}
diff --git a/src/libnrtype/Layout-TNG.h b/src/libnrtype/Layout-TNG.h
index 48b01eae5..3eed1fc43 100755
--- a/src/libnrtype/Layout-TNG.h
+++ b/src/libnrtype/Layout-TNG.h
@@ -443,7 +443,7 @@ public:
/** Returns the bounding box of the given glyph, and its rotation.
The centre of rotation is the horizontal centre of the box at the
text baseline. */
- NR::Rect glyphBoundingBox(iterator const &it, double *rotation) const;
+ NR::Maybe<NR::Rect> glyphBoundingBox(iterator const &it, double *rotation) const;
/** Returns the zero-based line number of the character pointed to by
\a it. */
diff --git a/src/libnrtype/RasterFont.cpp b/src/libnrtype/RasterFont.cpp
index 68ecb2e4d..c9af6621f 100644
--- a/src/libnrtype/RasterFont.cpp
+++ b/src/libnrtype/RasterFont.cpp
@@ -107,20 +107,24 @@ void raster_font::BBox(int glyph_id,NRRect *area)
{
area->x0=area->y0=area->x1=area->y1=0;
if ( daddy == NULL ) return;
- NR::Rect res=daddy->BBox(glyph_id);
- NR::Point bmi=res.min(),bma=res.max();
- NR::Point tlp(bmi[0],bmi[1]),trp(bma[0],bmi[1]),blp(bmi[0],bma[1]),brp(bma[0],bma[1]);
- tlp=tlp*style.transform;
- trp=trp*style.transform;
- blp=blp*style.transform;
- brp=brp*style.transform;
- res=NR::Rect(tlp,trp);
- res.expandTo(blp);
- res.expandTo(brp);
- area->x0=(res.min())[0];
- area->y0=(res.min())[1];
- area->x1=(res.max())[0];
- area->y1=(res.max())[1];
+ NR::Maybe<NR::Rect> res=daddy->BBox(glyph_id);
+ if (res) {
+ NR::Point bmi=res->min(),bma=res->max();
+ NR::Point tlp(bmi[0],bmi[1]),trp(bma[0],bmi[1]),blp(bmi[0],bma[1]),brp(bma[0],bma[1]);
+ tlp=tlp*style.transform;
+ trp=trp*style.transform;
+ blp=blp*style.transform;
+ brp=brp*style.transform;
+ *res=NR::Rect(tlp,trp);
+ res->expandTo(blp);
+ res->expandTo(brp);
+ area->x0=(res->min())[0];
+ area->y0=(res->min())[1];
+ area->x1=(res->max())[0];
+ area->y1=(res->max())[1];
+ } else {
+ nr_rect_d_set_empty(area);
+ }
}
void raster_font::LoadRasterGlyph(int glyph_id)
diff --git a/src/libnrtype/font-instance.h b/src/libnrtype/font-instance.h
index ec58ce1d7..4bec0203d 100644
--- a/src/libnrtype/font-instance.h
+++ b/src/libnrtype/font-instance.h
@@ -12,6 +12,7 @@
#include <libnrtype/nrtype-forward.h>
#include <libnrtype/font-style.h>
#include <livarot/livarot-forward.h>
+#include "libnr/nr-rect.h"
// the font_instance are the template of several raster_font; they provide metrics and outlines
// that are drawn by the raster_font, so the raster_font needs info relative to the way the
@@ -77,7 +78,7 @@ public:
bool FontMetrics(double &ascent, double &descent, double &leading);
bool FontSlope(double &run, double &rise);
// for generating slanted cursors for oblique fonts
- NR::Rect BBox(int glyph_id);
+ NR::Maybe<NR::Rect> BBox(int glyph_id);
// creates a rasterfont for the given style
raster_font* RasterFont(NR::Matrix const &trs, double stroke_width,