From: johanengelen Date: Thu, 11 Sep 2008 21:44:48 +0000 (+0000) Subject: convert almost all libnrtype to Geom:: X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=3da8c9f095f6e1d434809a58940f93585c58ebf3;p=inkscape.git convert almost all libnrtype to Geom:: --- diff --git a/src/desktop.cpp b/src/desktop.cpp index 54285c083..476f1e3d7 100644 --- a/src/desktop.cpp +++ b/src/desktop.cpp @@ -1038,7 +1038,7 @@ SPDesktop::scroll_world (double dx, double dy, bool is_scrolling) } bool -SPDesktop::scroll_to_point (NR::Point const *p, gdouble autoscrollspeed) +SPDesktop::scroll_to_point (Geom::Point const &p, gdouble autoscrollspeed) { gdouble autoscrolldistance = (gdouble) prefs_get_int_attribute_limited ("options.autoscrolldistance", "value", 0, -1000, 10000); @@ -1046,26 +1046,26 @@ SPDesktop::scroll_to_point (NR::Point const *p, gdouble autoscrollspeed) autoscrolldistance /= expansion(_d2w); NR::Rect const dbox = NR::expand(get_display_area(), -autoscrolldistance); - if (!((*p)[NR::X] > dbox.min()[NR::X] && (*p)[NR::X] < dbox.max()[NR::X]) || - !((*p)[NR::Y] > dbox.min()[NR::Y] && (*p)[NR::Y] < dbox.max()[NR::Y]) ) { + if (!(p[NR::X] > dbox.min()[NR::X] && p[NR::X] < dbox.max()[NR::X]) || + !(p[NR::Y] > dbox.min()[NR::Y] && p[NR::Y] < dbox.max()[NR::Y]) ) { - NR::Point const s_w( (*p) * _d2w ); + NR::Point const s_w( p * (Geom::Matrix)_d2w ); gdouble x_to; - if ((*p)[NR::X] < dbox.min()[NR::X]) + if (p[NR::X] < dbox.min()[NR::X]) x_to = dbox.min()[NR::X]; - else if ((*p)[NR::X] > dbox.max()[NR::X]) + else if (p[NR::X] > dbox.max()[NR::X]) x_to = dbox.max()[NR::X]; else - x_to = (*p)[NR::X]; + x_to = p[NR::X]; gdouble y_to; - if ((*p)[NR::Y] < dbox.min()[NR::Y]) + if (p[NR::Y] < dbox.min()[NR::Y]) y_to = dbox.min()[NR::Y]; - else if ((*p)[NR::Y] > dbox.max()[NR::Y]) + else if (p[NR::Y] > dbox.max()[NR::Y]) y_to = dbox.max()[NR::Y]; else - y_to = (*p)[NR::Y]; + y_to = p[NR::Y]; NR::Point const d_dt(x_to, y_to); NR::Point const d_w( d_dt * _d2w ); diff --git a/src/desktop.h b/src/desktop.h index adb6cb98b..8b7ecd98b 100644 --- a/src/desktop.h +++ b/src/desktop.h @@ -250,7 +250,7 @@ struct SPDesktop : public Inkscape::UI::View::View void prev_zoom(); void next_zoom(); - bool scroll_to_point (NR::Point const *s_dt, gdouble autoscrollspeed = 0); + bool scroll_to_point (Geom::Point const &s_dt, gdouble autoscrollspeed = 0); void scroll_world (double dx, double dy, bool is_scrolling = false); void scroll_world (NR::Point const scroll, bool is_scrolling = false) { diff --git a/src/display/nr-arena-glyphs.cpp b/src/display/nr-arena-glyphs.cpp index 0216fe4f9..6bb64f8d0 100644 --- a/src/display/nr-arena-glyphs.cpp +++ b/src/display/nr-arena-glyphs.cpp @@ -255,7 +255,7 @@ nr_arena_glyphs_pick(NRArenaItem *item, NR::Point p, gdouble /*delta*/, unsigned } void -nr_arena_glyphs_set_path(NRArenaGlyphs *glyphs, SPCurve */*curve*/, unsigned int /*lieutenant*/, font_instance *font, gint glyph, NR::Matrix const *transform) +nr_arena_glyphs_set_path(NRArenaGlyphs *glyphs, SPCurve */*curve*/, unsigned int /*lieutenant*/, font_instance *font, gint glyph, Geom::Matrix const *transform) { nr_return_if_fail(glyphs != NULL); nr_return_if_fail(NR_IS_ARENA_GLYPHS(glyphs)); @@ -607,7 +607,7 @@ nr_arena_glyphs_group_clear(NRArenaGlyphsGroup *sg) } void -nr_arena_glyphs_group_add_component(NRArenaGlyphsGroup *sg, font_instance *font, int glyph, NR::Matrix const *transform) +nr_arena_glyphs_group_add_component(NRArenaGlyphsGroup *sg, font_instance *font, int glyph, Geom::Matrix const &transform) { NRArenaGroup *group; @@ -622,7 +622,7 @@ nr_arena_glyphs_group_add_component(NRArenaGlyphsGroup *sg, font_instance *font, NRArenaItem *new_arena = NRArenaGlyphs::create(group->arena); nr_arena_item_append_child(NR_ARENA_ITEM(group), new_arena); nr_arena_item_unref(new_arena); - nr_arena_glyphs_set_path(NR_ARENA_GLYPHS(new_arena), NULL, FALSE, font, glyph, transform); + nr_arena_glyphs_set_path(NR_ARENA_GLYPHS(new_arena), NULL, FALSE, font, glyph, &transform); nr_arena_glyphs_set_style(NR_ARENA_GLYPHS(new_arena), sg->style); } } diff --git a/src/display/nr-arena-glyphs.h b/src/display/nr-arena-glyphs.h index ebf5cee6d..9c6762363 100644 --- a/src/display/nr-arena-glyphs.h +++ b/src/display/nr-arena-glyphs.h @@ -59,10 +59,10 @@ struct NRArenaGlyphsClass { NRArenaItemClass parent_class; }; -void nr_arena_glyphs_set_path (NRArenaGlyphs *glyphs, - SPCurve *curve, unsigned int lieutenant, - font_instance *font, int glyph, - const NR::Matrix *transform); +void nr_arena_glyphs_set_path ( NRArenaGlyphs *glyphs, + SPCurve *curve, unsigned int lieutenant, + font_instance *font, int glyph, + Geom::Matrix const *transform ); void nr_arena_glyphs_set_style (NRArenaGlyphs *glyphs, SPStyle *style); /* Integrated group of component glyphss */ @@ -100,7 +100,7 @@ struct NRArenaGlyphsGroupClass { void nr_arena_glyphs_group_clear (NRArenaGlyphsGroup *group); -void nr_arena_glyphs_group_add_component (NRArenaGlyphsGroup *group, font_instance *font, int glyph, const NR::Matrix *transform); +void nr_arena_glyphs_group_add_component (NRArenaGlyphsGroup *group, font_instance *font, int glyph, Geom::Matrix const &transform); void nr_arena_glyphs_group_set_style (NRArenaGlyphsGroup *group, SPStyle *style); diff --git a/src/gradient-chemistry.cpp b/src/gradient-chemistry.cpp index afbf16009..26945def6 100644 --- a/src/gradient-chemistry.cpp +++ b/src/gradient-chemistry.cpp @@ -31,6 +31,9 @@ #include "sp-tspan.h" #include #include +#include +#include +#include <2geom/transforms.h> #include "xml/repr.h" #include "svg/svg.h" #include "svg/svg-color.h" @@ -299,9 +302,9 @@ sp_gradient_reset_to_userspace (SPGradient *gr, SPItem *item) sp_repr_set_svg_double(repr, "r", width/2); // we want it to be elliptic, not circular - NR::Matrix squeeze = NR::Matrix (NR::translate (-center)) * - NR::Matrix (NR::scale(1, height/width)) * - NR::Matrix (NR::translate (center)); + Geom::Matrix squeeze = Geom::Translate (-center) * + Geom::Scale(1, height/width) * + Geom::Translate (center); gr->gradientTransform = squeeze; { diff --git a/src/gradient-context.cpp b/src/gradient-context.cpp index e6932c710..400661ce2 100644 --- a/src/gradient-context.cpp +++ b/src/gradient-context.cpp @@ -225,7 +225,7 @@ sp_gradient_context_select_next (SPEventContext *event_context) GrDragger *d = drag->select_next(); - event_context->desktop->scroll_to_point(&(d->point), 1.0); + event_context->desktop->scroll_to_point(d->point, 1.0); } void @@ -236,7 +236,7 @@ sp_gradient_context_select_prev (SPEventContext *event_context) GrDragger *d = drag->select_prev(); - event_context->desktop->scroll_to_point(&(d->point), 1.0); + event_context->desktop->scroll_to_point(d->point, 1.0); } static bool diff --git a/src/knot.cpp b/src/knot.cpp index 1584769b4..59e32a56e 100644 --- a/src/knot.cpp +++ b/src/knot.cpp @@ -381,7 +381,7 @@ static int sp_knot_handler(SPCanvasItem */*item*/, GdkEvent *event, SPKnot *knot NR::Point const motion_dt = knot->desktop->w2d(motion_w); Geom::Point p = motion_dt - knot->grabbed_rel_pos; sp_knot_request_position (knot, p, event->motion.state); - knot->desktop->scroll_to_point (&motion_dt); + knot->desktop->scroll_to_point (motion_dt); knot->desktop->set_coordinate_status(knot->pos); // display the coordinate of knot, not cursor - they may be different! if (event->motion.state & GDK_BUTTON1_MASK) gobble_motion_events(GDK_BUTTON1_MASK); diff --git a/src/libnrtype/FontInstance.cpp b/src/libnrtype/FontInstance.cpp index 4f745c0f9..25a6af935 100644 --- a/src/libnrtype/FontInstance.cpp +++ b/src/libnrtype/FontInstance.cpp @@ -87,7 +87,7 @@ bool font_style_equal::operator()(const font_style &a,const font_style &b) { typedef struct ft2_to_liv { Path* theP; double scale; - NR::Point last; + Geom::Point last; } ft2_to_liv; // Note: Freetype 2.2.1 redefined function signatures for functions to be placed in an @@ -105,7 +105,7 @@ typedef FT_Vector FREETYPE_VECTOR; // see nr-type-ft2.cpp for the freetype -> artBPath on which this code is based static int ft2_move_to(FREETYPE_VECTOR *to, void * i_user) { ft2_to_liv* user=(ft2_to_liv*)i_user; - NR::Point p(user->scale*to->x,user->scale*to->y); + Geom::Point p(user->scale*to->x,user->scale*to->y); // printf("m t=%f %f\n",p[0],p[1]); user->theP->MoveTo(p); user->last=p; @@ -115,7 +115,7 @@ static int ft2_move_to(FREETYPE_VECTOR *to, void * i_user) { static int ft2_line_to(FREETYPE_VECTOR *to, void *i_user) { ft2_to_liv* user=(ft2_to_liv*)i_user; - NR::Point p(user->scale*to->x,user->scale*to->y); + Geom::Point p(user->scale*to->x,user->scale*to->y); // printf("l t=%f %f\n",p[0],p[1]); user->theP->LineTo(p); user->last=p; @@ -125,7 +125,7 @@ static int ft2_line_to(FREETYPE_VECTOR *to, void *i_user) static int ft2_conic_to(FREETYPE_VECTOR *control, FREETYPE_VECTOR *to, void *i_user) { ft2_to_liv* user=(ft2_to_liv*)i_user; - NR::Point p(user->scale*to->x,user->scale*to->y),c(user->scale*control->x,user->scale*control->y); + Geom::Point p(user->scale*to->x,user->scale*to->y),c(user->scale*control->x,user->scale*control->y); // printf("b c=%f %f t=%f %f\n",c[0],c[1],p[0],p[1]); user->theP->BezierTo(p); user->theP->IntermBezierTo(c); @@ -137,7 +137,7 @@ static int ft2_conic_to(FREETYPE_VECTOR *control, FREETYPE_VECTOR *to, void *i_u static int ft2_cubic_to(FREETYPE_VECTOR *control1, FREETYPE_VECTOR *control2, FREETYPE_VECTOR *to, void *i_user) { ft2_to_liv* user=(ft2_to_liv*)i_user; - NR::Point p(user->scale*to->x,user->scale*to->y), + Geom::Point p(user->scale*to->x,user->scale*to->y), c1(user->scale*control1->x,user->scale*control1->y), c2(user->scale*control2->x,user->scale*control2->y); // printf("c c1=%f %f c2=%f %f t=%f %f\n",c1[0],c1[1],c2[0],c2[1],p[0],p[1]); @@ -407,9 +407,9 @@ int font_instance::MapUnicodeChar(gunichar c) #ifdef USE_PANGO_WIN32 -static inline NR::Point pointfx_to_nrpoint(const POINTFX &p, double scale) +static inline Geom::Point pointfx_to_nrpoint(const POINTFX &p, double scale) { - return NR::Point(*(long*)&p.x / 65536.0 * scale, + return Geom::Point(*(long*)&p.x / 65536.0 * scale, *(long*)&p.y / 65536.0 * scale); } #endif @@ -486,9 +486,9 @@ void font_instance::LoadGlyph(int glyph_id) { g_assert(polyCurve->cpfx >= 2); endp -= 2; - NR::Point this_mid=pointfx_to_nrpoint(p[0], scale); + Geom::Point this_mid=pointfx_to_nrpoint(p[0], scale); while ( p != endp ) { - NR::Point next_mid=pointfx_to_nrpoint(p[1], scale); + Geom::Point next_mid=pointfx_to_nrpoint(p[1], scale); n_g.outline->BezierTo((next_mid+this_mid)/2); n_g.outline->IntermBezierTo(this_mid); n_g.outline->EndBezierTo(); @@ -546,7 +546,7 @@ void font_instance::LoadGlyph(int glyph_id) ft2_to_liv tData; tData.theP=n_g.outline; tData.scale=1.0/((double)theFace->units_per_EM); - tData.last=NR::Point(0,0); + tData.last=Geom::Point(0,0); FT_Outline_Decompose (&theFace->glyph->outline, &ft2_outline_funcs, &tData); } doAdd=true; @@ -613,7 +613,7 @@ bool font_instance::FontSlope(double &run, double &rise) return true; } -boost::optional font_instance::BBox(int glyph_id) +boost::optional font_instance::BBox(int glyph_id) { int no=-1; if ( id_to_no.find(glyph_id) == id_to_no.end() ) { @@ -627,11 +627,11 @@ boost::optional font_instance::BBox(int glyph_id) no=id_to_no[glyph_id]; } if ( no < 0 ) { - return boost::optional(); + return boost::optional(); } 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); + Geom::Point rmin(glyphs[no].bbox[0],glyphs[no].bbox[1]); + Geom::Point rmax(glyphs[no].bbox[2],glyphs[no].bbox[3]); + return Geom::Rect(rmin, rmax); } } @@ -699,7 +699,7 @@ double font_instance::Advance(int glyph_id,bool vertical) } -raster_font* font_instance::RasterFont(const NR::Matrix &trs, double stroke_width, bool vertical, JoinType stroke_join, ButtType stroke_cap, float /*miter_limit*/) +raster_font* font_instance::RasterFont(const Geom::Matrix &trs, double stroke_width, bool vertical, JoinType stroke_join, ButtType stroke_cap, float /*miter_limit*/) { font_style nStyle; nStyle.transform=trs; diff --git a/src/libnrtype/Layout-TNG-Compute.cpp b/src/libnrtype/Layout-TNG-Compute.cpp index 96ea2be7c..57be6033a 100644 --- a/src/libnrtype/Layout-TNG-Compute.cpp +++ b/src/libnrtype/Layout-TNG-Compute.cpp @@ -1469,7 +1469,7 @@ bool Layout::Calculator::calculate() void Layout::_calculateCursorShapeForEmpty() { - _empty_cursor_shape.position = NR::Point(0, 0); + _empty_cursor_shape.position = Geom::Point(0, 0); _empty_cursor_shape.height = 0.0; _empty_cursor_shape.rotation = 0.0; if (_input_stream.empty() || _input_stream.front()->Type() != TEXT_SOURCE) @@ -1496,7 +1496,7 @@ void Layout::_calculateCursorShapeForEmpty() _empty_cursor_shape.rotation = caret_slope; if (_input_wrap_shapes.empty()) { - _empty_cursor_shape.position = NR::Point(text_source->x.empty() || !text_source->x.front()._set ? 0.0 : text_source->x.front().computed, + _empty_cursor_shape.position = Geom::Point(text_source->x.empty() || !text_source->x.front()._set ? 0.0 : text_source->x.front().computed, text_source->y.empty() || !text_source->y.front()._set ? 0.0 : text_source->y.front().computed); } else { Direction block_progression = text_source->styleGetBlockProgression(); @@ -1504,9 +1504,9 @@ void Layout::_calculateCursorShapeForEmpty() std::vector scan_runs = scanline_maker.makeScanline(line_height); if (!scan_runs.empty()) { if (block_progression == LEFT_TO_RIGHT || block_progression == RIGHT_TO_LEFT) - _empty_cursor_shape.position = NR::Point(scan_runs.front().y + font_size, scan_runs.front().x_start); + _empty_cursor_shape.position = Geom::Point(scan_runs.front().y + font_size, scan_runs.front().x_start); else - _empty_cursor_shape.position = NR::Point(scan_runs.front().x_start, scan_runs.front().y + font_size); + _empty_cursor_shape.position = Geom::Point(scan_runs.front().x_start, scan_runs.front().y + font_size); } } } diff --git a/src/libnrtype/Layout-TNG-OutIter.cpp b/src/libnrtype/Layout-TNG-OutIter.cpp index 84307c9ce..abe282005 100644 --- a/src/libnrtype/Layout-TNG-OutIter.cpp +++ b/src/libnrtype/Layout-TNG-OutIter.cpp @@ -12,8 +12,7 @@ #include "livarot/Path.h" #include "font-instance.h" #include "svg/svg-length.h" -#include "libnr/nr-matrix-translate-ops.h" -#include "libnr/nr-translate-rotate-ops.h" +#include <2geom/transforms.h> #include "style.h" namespace Inkscape { @@ -86,7 +85,7 @@ Layout::iterator Layout::getNearestCursorPositionTo(double x, double y) const double local_y = y; if (_path_fitted) { - Path::cut_position position = const_cast(_path_fitted)->PointToCurvilignPosition(NR::Point(x, y)); + Path::cut_position position = const_cast(_path_fitted)->PointToCurvilignPosition(Geom::Point(x, y)); local_x = const_cast(_path_fitted)->PositionToLength(position.piece, position.t); return _cursorXOnLineToIterator(0, local_x + _chunks.front().left_x); } @@ -157,11 +156,11 @@ Layout::iterator Layout::getNearestCursorPositionTo(double x, double y) const Layout::iterator Layout::getLetterAt(double x, double y) const { - NR::Point point(x, y); + Geom::Point point(x, y); double rotation; for (iterator it = begin() ; it != end() ; it.nextCharacter()) { - NR::Rect box = characterBoundingBox(it, &rotation); + Geom::Rect box = characterBoundingBox(it, &rotation); // todo: rotation if (box.contains(point)) return it; } @@ -201,20 +200,20 @@ Layout::iterator Layout::sourceToIterator(void *source_cookie) const return sourceToIterator(source_cookie, Glib::ustring::const_iterator(std::string::const_iterator(NULL))); } -boost::optional Layout::glyphBoundingBox(iterator const &it, double *rotation) const +boost::optional 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); } -NR::Point Layout::characterAnchorPoint(iterator const &it) const +Geom::Point Layout::characterAnchorPoint(iterator const &it) const { if (_characters.empty()) return _empty_cursor_shape.position; if (it._char_index == _characters.size()) { - return NR::Point(_chunks.back().left_x + _spans.back().x_end, _lines.back().baseline_y + _spans.back().baseline_shift); + return Geom::Point(_chunks.back().left_x + _spans.back().x_end, _lines.back().baseline_y + _spans.back().baseline_shift); } else { - return NR::Point(_characters[it._char_index].chunk(this).left_x + return Geom::Point(_characters[it._char_index].chunk(this).left_x + _spans[_characters[it._char_index].in_span].x_start + _characters[it._char_index].x, _characters[it._char_index].line(this).baseline_y @@ -222,12 +221,12 @@ NR::Point Layout::characterAnchorPoint(iterator const &it) const } } -NR::Point Layout::chunkAnchorPoint(iterator const &it) const +Geom::Point Layout::chunkAnchorPoint(iterator const &it) const { unsigned chunk_index; if (_chunks.empty()) - return NR::Point(0.0, 0.0); + return Geom::Point(0.0, 0.0); if (_characters.empty()) chunk_index = 0; @@ -237,18 +236,18 @@ NR::Point Layout::chunkAnchorPoint(iterator const &it) const Alignment alignment = _paragraphs[_lines[_chunks[chunk_index].in_line].in_paragraph].alignment; if (alignment == LEFT || alignment == FULL) - return NR::Point(_chunks[chunk_index].left_x, _lines[chunk_index].baseline_y); + return Geom::Point(_chunks[chunk_index].left_x, _lines[chunk_index].baseline_y); double chunk_width = _getChunkWidth(chunk_index); if (alignment == RIGHT) - return NR::Point(_chunks[chunk_index].left_x + chunk_width, _lines[chunk_index].baseline_y); + return Geom::Point(_chunks[chunk_index].left_x + chunk_width, _lines[chunk_index].baseline_y); //centre - return NR::Point(_chunks[chunk_index].left_x + chunk_width * 0.5, _lines[chunk_index].baseline_y); + return Geom::Point(_chunks[chunk_index].left_x + chunk_width * 0.5, _lines[chunk_index].baseline_y); } -NR::Rect Layout::characterBoundingBox(iterator const &it, double *rotation) const +Geom::Rect Layout::characterBoundingBox(iterator const &it, double *rotation) const { - NR::Point top_left, bottom_right; + Geom::Point top_left, bottom_right; unsigned char_index = it._char_index; if (_path_fitted) { @@ -266,11 +265,11 @@ NR::Rect Layout::characterBoundingBox(iterator const &it, double *rotation) cons Span const &span = _characters[char_index].span(this); const_cast(_path_fitted)->PointAndTangentAt(midpoint_otp[0].piece, midpoint_otp[0].t, midpoint, tangent); - top_left[NR::X] = midpoint[NR::X] - cluster_half_width; - top_left[NR::Y] = midpoint[NR::Y] - span.line_height.ascent; - bottom_right[NR::X] = midpoint[NR::X] + cluster_half_width; - bottom_right[NR::Y] = midpoint[NR::Y] + span.line_height.descent; - NR::Point normal = tangent.cw(); + top_left[Geom::X] = midpoint[Geom::X] - cluster_half_width; + top_left[Geom::Y] = midpoint[Geom::Y] - span.line_height.ascent; + bottom_right[Geom::X] = midpoint[Geom::X] + cluster_half_width; + bottom_right[Geom::Y] = midpoint[Geom::Y] + span.line_height.descent; + Geom::Point normal = tangent.cw(); top_left += span.baseline_shift * normal; bottom_right += span.baseline_shift * normal; if (rotation) @@ -279,27 +278,27 @@ NR::Rect Layout::characterBoundingBox(iterator const &it, double *rotation) cons g_free(midpoint_otp); } else { if (it._char_index == _characters.size()) { - top_left[NR::X] = bottom_right[NR::X] = _chunks.back().left_x + _spans.back().x_end; + top_left[Geom::X] = bottom_right[Geom::X] = _chunks.back().left_x + _spans.back().x_end; char_index--; } else { double span_x = _spans[_characters[it._char_index].in_span].x_start + _characters[it._char_index].chunk(this).left_x; - top_left[NR::X] = span_x + _characters[it._char_index].x; + top_left[Geom::X] = span_x + _characters[it._char_index].x; if (it._char_index + 1 == _characters.size() || _characters[it._char_index + 1].in_span != _characters[it._char_index].in_span) - bottom_right[NR::X] = _spans[_characters[it._char_index].in_span].x_end + _characters[it._char_index].chunk(this).left_x; + bottom_right[Geom::X] = _spans[_characters[it._char_index].in_span].x_end + _characters[it._char_index].chunk(this).left_x; else - bottom_right[NR::X] = span_x + _characters[it._char_index + 1].x; + bottom_right[Geom::X] = span_x + _characters[it._char_index + 1].x; } double baseline_y = _characters[char_index].line(this).baseline_y + _characters[char_index].span(this).baseline_shift; if (_directions_are_orthogonal(_blockProgression(), TOP_TO_BOTTOM)) { double span_height = _spans[_characters[char_index].in_span].line_height.ascent + _spans[_characters[char_index].in_span].line_height.descent; - top_left[NR::Y] = top_left[NR::X]; - top_left[NR::X] = baseline_y - span_height * 0.5; - bottom_right[NR::Y] = bottom_right[NR::X]; - bottom_right[NR::X] = baseline_y + span_height * 0.5; + top_left[Geom::Y] = top_left[Geom::X]; + top_left[Geom::X] = baseline_y - span_height * 0.5; + bottom_right[Geom::Y] = bottom_right[Geom::X]; + bottom_right[Geom::X] = baseline_y + span_height * 0.5; } else { - top_left[NR::Y] = baseline_y - _spans[_characters[char_index].in_span].line_height.ascent; - bottom_right[NR::Y] = baseline_y + _spans[_characters[char_index].in_span].line_height.descent; + top_left[Geom::Y] = baseline_y - _spans[_characters[char_index].in_span].line_height.ascent; + bottom_right[Geom::Y] = baseline_y + _spans[_characters[char_index].in_span].line_height.descent; } if (rotation) { @@ -312,12 +311,12 @@ NR::Rect Layout::characterBoundingBox(iterator const &it, double *rotation) cons } } - return NR::Rect(top_left, bottom_right); + return Geom::Rect(top_left, bottom_right); } -std::vector Layout::createSelectionShape(iterator const &it_start, iterator const &it_end, NR::Matrix const &transform) const +std::vector Layout::createSelectionShape(iterator const &it_start, iterator const &it_end, Geom::Matrix const &transform) const { - std::vector quads; + std::vector quads; unsigned char_index; unsigned end_char_index; @@ -336,53 +335,53 @@ std::vector Layout::createSelectionShape(iterator const &it_start, it double char_rotation = _glyphs[_characters[char_index].in_glyph].rotation; unsigned span_index = _characters[char_index].in_span; - NR::Point top_left, bottom_right; + Geom::Point top_left, bottom_right; if (_path_fitted || char_rotation != 0.0) { - NR::Rect box = characterBoundingBox(iterator(this, char_index), &char_rotation); + Geom::Rect box = characterBoundingBox(iterator(this, char_index), &char_rotation); top_left = box.min(); bottom_right = box.max(); char_index++; } else { // for straight text we can be faster by combining all the character boxes in a span into one box double span_x = _spans[span_index].x_start + _spans[span_index].chunk(this).left_x; - top_left[NR::X] = span_x + _characters[char_index].x; + top_left[Geom::X] = span_x + _characters[char_index].x; while (char_index < end_char_index && _characters[char_index].in_span == span_index) char_index++; if (char_index == _characters.size() || _characters[char_index].in_span != span_index) - bottom_right[NR::X] = _spans[span_index].x_end + _spans[span_index].chunk(this).left_x; + bottom_right[Geom::X] = _spans[span_index].x_end + _spans[span_index].chunk(this).left_x; else - bottom_right[NR::X] = span_x + _characters[char_index].x; + bottom_right[Geom::X] = span_x + _characters[char_index].x; double baseline_y = _spans[span_index].line(this).baseline_y + _spans[span_index].baseline_shift; if (_directions_are_orthogonal(_blockProgression(), TOP_TO_BOTTOM)) { double span_height = _spans[span_index].line_height.ascent + _spans[span_index].line_height.descent; - top_left[NR::Y] = top_left[NR::X]; - top_left[NR::X] = baseline_y - span_height * 0.5; - bottom_right[NR::Y] = bottom_right[NR::X]; - bottom_right[NR::X] = baseline_y + span_height * 0.5; + top_left[Geom::Y] = top_left[Geom::X]; + top_left[Geom::X] = baseline_y - span_height * 0.5; + bottom_right[Geom::Y] = bottom_right[Geom::X]; + bottom_right[Geom::X] = baseline_y + span_height * 0.5; } else { - top_left[NR::Y] = baseline_y - _spans[span_index].line_height.ascent; - bottom_right[NR::Y] = baseline_y + _spans[span_index].line_height.descent; + top_left[Geom::Y] = baseline_y - _spans[span_index].line_height.ascent; + bottom_right[Geom::Y] = baseline_y + _spans[span_index].line_height.descent; } } - NR::Rect char_box(top_left, bottom_right); - if (char_box.extent(NR::X) == 0.0 || char_box.extent(NR::Y) == 0.0) + Geom::Rect char_box(top_left, bottom_right); + if (char_box.dimensions()[Geom::X] == 0.0 || char_box.dimensions()[Geom::Y] == 0.0) continue; - NR::Point center_of_rotation((top_left[NR::X] + bottom_right[NR::X]) * 0.5, - top_left[NR::Y] + _spans[span_index].line_height.ascent); - NR::Matrix total_transform = NR::translate(-center_of_rotation) * NR::rotate(char_rotation) * NR::translate(center_of_rotation) * transform; + Geom::Point center_of_rotation((top_left[Geom::X] + bottom_right[Geom::X]) * 0.5, + top_left[Geom::Y] + _spans[span_index].line_height.ascent); + Geom::Matrix total_transform = Geom::Translate(-center_of_rotation) * Geom::Rotate(char_rotation) * Geom::Translate(center_of_rotation) * transform; for(int i = 0; i < 4; i ++) quads.push_back(char_box.corner(i) * total_transform); } return quads; } -void Layout::queryCursorShape(iterator const &it, NR::Point *position, double *height, double *rotation) const +void Layout::queryCursorShape(iterator const &it, Geom::Point &position, double &height, double &rotation) const { if (_characters.empty()) { - *position = _empty_cursor_shape.position; - *height = _empty_cursor_shape.height; - *rotation = _empty_cursor_shape.rotation; + position = _empty_cursor_shape.position; + height = _empty_cursor_shape.height; + rotation = _empty_cursor_shape.rotation; } else { // we want to cursor to be positioned where the left edge of a character that is about to be typed will be. // this means x & rotation are the current values but y & height belong to the previous character. @@ -423,43 +422,47 @@ void Layout::queryCursorShape(iterator const &it, NR::Point *position, double *h point += x * tangent; if (x > path_length ) point += (x - path_length) * tangent; - *rotation = atan2(tangent); - (*position)[NR::X] = point[NR::X] - tangent[NR::Y] * span->baseline_shift; - (*position)[NR::Y] = point[NR::Y] + tangent[NR::X] * span->baseline_shift; + rotation = atan2(tangent); + position[Geom::X] = point[Geom::X] - tangent[Geom::Y] * span->baseline_shift; + position[Geom::Y] = point[Geom::Y] + tangent[Geom::X] * span->baseline_shift; } else { // text is not on a path if (it._char_index >= _characters.size()) { span = &_spans.back(); - (*position)[NR::X] = _chunks[span->in_chunk].left_x + span->x_end; - *rotation = _glyphs.empty() ? 0.0 : _glyphs.back().rotation; + position[Geom::X] = _chunks[span->in_chunk].left_x + span->x_end; + rotation = _glyphs.empty() ? 0.0 : _glyphs.back().rotation; } else { span = &_spans[_characters[it._char_index].in_span]; - (*position)[NR::X] = _chunks[span->in_chunk].left_x + span->x_start + _characters[it._char_index].x; - if (it._glyph_index == -1) *rotation = 0.0; - else if(it._glyph_index == 0) *rotation = _glyphs[0].rotation; - else *rotation = _glyphs[it._glyph_index - 1].rotation; + position[Geom::X] = _chunks[span->in_chunk].left_x + span->x_start + _characters[it._char_index].x; + if (it._glyph_index == -1) { + rotation = 0.0; + } else if(it._glyph_index == 0) { + rotation = _glyphs[0].rotation; + } else{ + rotation = _glyphs[it._glyph_index - 1].rotation; + } // the first char in a line wants to have the y of the new line, so in that case we don't switch to the previous span if (it._char_index != 0 && _characters[it._char_index - 1].chunk(this).in_line == _chunks[span->in_chunk].in_line) span = &_spans[_characters[it._char_index - 1].in_span]; } - (*position)[NR::Y] = span->line(this).baseline_y + span->baseline_shift; + position[Geom::Y] = span->line(this).baseline_y + span->baseline_shift; } // up to now *position is the baseline point, not the final point which will be the bottom of the descent if (_directions_are_orthogonal(_blockProgression(), TOP_TO_BOTTOM)) { - *height = span->line_height.ascent + span->line_height.descent; - *rotation += M_PI / 2; - std::swap((*position)[NR::X], (*position)[NR::Y]); - (*position)[NR::X] -= sin(*rotation) * *height * 0.5; - (*position)[NR::Y] += cos(*rotation) * *height * 0.5; + height = span->line_height.ascent + span->line_height.descent; + rotation += M_PI / 2; + std::swap(position[Geom::X], position[Geom::Y]); + position[Geom::X] -= sin(rotation) * height * 0.5; + position[Geom::Y] += cos(rotation) * height * 0.5; } else { double caret_slope_run = 0.0, caret_slope_rise = 1.0; if (span->font) const_cast(span->font)->FontSlope(caret_slope_run, caret_slope_rise); double caret_slope = atan2(caret_slope_run, caret_slope_rise); - *height = (span->line_height.ascent + span->line_height.descent) / cos(caret_slope); - *rotation += caret_slope; - (*position)[NR::X] -= sin(*rotation) * span->line_height.descent; - (*position)[NR::Y] += cos(*rotation) * span->line_height.descent; + height = (span->line_height.ascent + span->line_height.descent) / cos(caret_slope); + rotation += caret_slope; + position[Geom::X] -= sin(rotation) * span->line_height.descent; + position[Geom::Y] += cos(rotation) * span->line_height.descent; } } } diff --git a/src/libnrtype/Layout-TNG-Output.cpp b/src/libnrtype/Layout-TNG-Output.cpp index a3857b476..d4df3ee37 100644 --- a/src/libnrtype/Layout-TNG-Output.cpp +++ b/src/libnrtype/Layout-TNG-Output.cpp @@ -59,7 +59,7 @@ void Layout::LineHeight::max(LineHeight const &other) if (other.leading > leading) leading = other.leading; } -void Layout::_getGlyphTransformMatrix(int glyph_index, NR::Matrix *matrix) const +void Layout::_getGlyphTransformMatrix(int glyph_index, Geom::Matrix *matrix) const { Span const &span = _glyphs[glyph_index].span(this); double sin_rotation = sin(_glyphs[glyph_index].rotation); @@ -90,9 +90,9 @@ void Layout::show(NRArenaGroup *in_arena, NRRect const *paintbox) const nr_arena_glyphs_group_set_style(nr_group, text_source->style); while (glyph_index < (int)_glyphs.size() && _characters[_glyphs[glyph_index].in_character].in_span == span_index) { if (_characters[_glyphs[glyph_index].in_character].in_glyph != -1) { - NR::Matrix glyph_matrix; + Geom::Matrix glyph_matrix; _getGlyphTransformMatrix(glyph_index, &glyph_matrix); - nr_arena_glyphs_group_add_component(nr_group, _spans[span_index].font, _glyphs[glyph_index].glyph, &glyph_matrix); + nr_arena_glyphs_group_add_component(nr_group, _spans[span_index].font, _glyphs[glyph_index].glyph, glyph_matrix); } glyph_index++; } @@ -101,7 +101,7 @@ void Layout::show(NRArenaGroup *in_arena, NRRect const *paintbox) const nr_arena_item_request_update(NR_ARENA_ITEM(in_arena), NR_ARENA_ITEM_STATE_ALL, FALSE); } -void Layout::getBoundingBox(NRRect *bounding_box, NR::Matrix const &transform, int start, int length) const +void Layout::getBoundingBox(NRRect *bounding_box, Geom::Matrix const &transform, int start, int length) const { for (unsigned glyph_index = 0 ; glyph_index < _glyphs.size() ; glyph_index++) { if (_characters[_glyphs[glyph_index].in_character].in_glyph == -1) continue; @@ -112,20 +112,20 @@ void Layout::getBoundingBox(NRRect *bounding_box, NR::Matrix const &transform, i if ((int) _glyphs[glyph_index].in_character > start + length) continue; } // this could be faster - NR::Matrix glyph_matrix; + Geom::Matrix glyph_matrix; _getGlyphTransformMatrix(glyph_index, &glyph_matrix); - NR::Matrix total_transform = glyph_matrix; + Geom::Matrix total_transform = glyph_matrix; total_transform *= transform; if(_glyphs[glyph_index].span(this).font) { - boost::optional glyph_rect = _glyphs[glyph_index].span(this).font->BBox(_glyphs[glyph_index].glyph); + boost::optional 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]); + Geom::Point bmi = glyph_rect->min(), bma = glyph_rect->max(); + Geom::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 = Geom::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]; @@ -139,7 +139,7 @@ void Layout::getBoundingBox(NRRect *bounding_box, NR::Matrix const &transform, i void Layout::print(SPPrintContext *ctx, NRRect const *pbox, NRRect const *dbox, NRRect const *bbox, - NR::Matrix const &ctm) const + Geom::Matrix const &ctm) const { if (_input_stream.empty()) return; @@ -154,7 +154,7 @@ void Layout::print(SPPrintContext *ctx, glyph_index++; continue; } - NR::Matrix glyph_matrix; + Geom::Matrix glyph_matrix; Span const &span = _spans[_characters[_glyphs[glyph_index].in_character].in_span]; InputStreamTextSource const *text_source = static_cast(_input_stream[span.in_input_stream_item]); if (text_to_path || _path_fitted) { @@ -169,8 +169,8 @@ void Layout::print(SPPrintContext *ctx, } glyph_index++; } else { - NR::Point g_pos(0,0); // all strings are output at (0,0) because we do the translation using the matrix - glyph_matrix = NR::Matrix(NR::scale(1.0, -1.0) * NR::Matrix(NR::rotate(_glyphs[glyph_index].rotation))); + Geom::Point g_pos(0,0); // all strings are output at (0,0) because we do the translation using the matrix + glyph_matrix = Geom::Scale(1.0, -1.0) * (Geom::Matrix)Geom::Rotate(_glyphs[glyph_index].rotation); if (block_progression == LEFT_TO_RIGHT || block_progression == RIGHT_TO_LEFT) { glyph_matrix[4] = span.line(this).baseline_y + span.baseline_shift; // since we're outputting character codes, not glyphs, we want the character x @@ -230,7 +230,7 @@ void Layout::showGlyphs(CairoRenderContext *ctx) const Span const &span = _spans[_characters[_glyphs[glyph_index].in_character].in_span]; InputStreamTextSource const *text_source = static_cast(_input_stream[span.in_input_stream_item]); - NR::Matrix glyph_matrix; + Geom::Matrix glyph_matrix; _getGlyphTransformMatrix(glyph_index, &glyph_matrix); if (clip_mode) { Geom::PathVector const *pathv = span.font->PathVector(_glyphs[glyph_index].glyph); @@ -243,13 +243,13 @@ void Layout::showGlyphs(CairoRenderContext *ctx) const continue; } - NR::Matrix font_matrix; + Geom::Matrix font_matrix; if (_path_fitted == NULL) { font_matrix = glyph_matrix; font_matrix[4] = 0; font_matrix[5] = 0; } else { - font_matrix.set_identity(); + font_matrix.setIdentity(); } Glib::ustring::const_iterator span_iter = span.input_stream_first_character; @@ -300,14 +300,14 @@ void Layout::showGlyphs(CairoRenderContext *ctx) const if (_path_fitted) { ctx->pushState(); - ctx->transform(&to_2geom(glyph_matrix)); + ctx->transform(&glyph_matrix); } else if (opacity != 1.0) { ctx->pushState(); ctx->setStateForStyle(style); ctx->pushLayer(); } if (glyph_index - first_index > 0) - ctx->renderGlyphtext(span.font->pFont, &to_2geom(font_matrix), glyphtext, style); + ctx->renderGlyphtext(span.font->pFont, &font_matrix, glyphtext, style); if (_path_fitted) ctx->popState(); else if (opacity != 1.0) { @@ -440,7 +440,7 @@ void Layout::fitToPathAlign(SVGLength const &startOffset, Path const &path) NR::Point tangent; const_cast(path).PointAndTangentAt(point_otp[0].piece, point_otp[0].t, point, tangent); _empty_cursor_shape.position = point; - _empty_cursor_shape.rotation = atan2(tangent[NR::Y], tangent[NR::X]); + _empty_cursor_shape.rotation = atan2(tangent[Geom::Y], tangent[Geom::X]); } } @@ -478,7 +478,6 @@ void Layout::fitToPathAlign(SVGLength const &startOffset, Path const &path) if (midpoint_offset >= 0.0 && midpoint_otp != NULL && midpoint_otp[0].piece >= 0) { NR::Point midpoint; NR::Point tangent; - const_cast(path).PointAndTangentAt(midpoint_otp[0].piece, midpoint_otp[0].t, midpoint, tangent); if (start_offset >= 0.0 && end_offset >= 0.0) { @@ -504,7 +503,7 @@ void Layout::fitToPathAlign(SVGLength const &startOffset, Path const &path) tangent = endpoint - startpoint; tangent.normalize(); } else { - tangent = NR::Point (0,0); + tangent = Geom::Point (0,0); } } g_free(end_otp); @@ -544,7 +543,7 @@ SPCurve *Layout::convertToCurves(iterator const &from_glyph, iterator const &to_ GSList *cc = NULL; for (int glyph_index = from_glyph._glyph_index ; glyph_index < to_glyph._glyph_index ; glyph_index++) { - NR::Matrix glyph_matrix; + Geom::Matrix glyph_matrix; Span const &span = _glyphs[glyph_index].span(this); _getGlyphTransformMatrix(glyph_index, &glyph_matrix); @@ -573,12 +572,12 @@ SPCurve *Layout::convertToCurves(iterator const &from_glyph, iterator const &to_ return curve; } -void Layout::transform(NR::Matrix const &transform) +void Layout::transform(Geom::Matrix const &transform) { // this is all massively oversimplified // I can't actually think of anybody who'll want to use it at the moment, so it'll stay simple for (unsigned glyph_index = 0 ; glyph_index < _glyphs.size() ; glyph_index++) { - NR::Point point(_glyphs[glyph_index].x, _glyphs[glyph_index].y); + Geom::Point point(_glyphs[glyph_index].x, _glyphs[glyph_index].y); point *= transform; _glyphs[glyph_index].x = point[0]; _glyphs[glyph_index].y = point[1]; diff --git a/src/libnrtype/Layout-TNG-Scanline-Makers.cpp b/src/libnrtype/Layout-TNG-Scanline-Makers.cpp index bff94c151..1bfde1f2d 100644 --- a/src/libnrtype/Layout-TNG-Scanline-Makers.cpp +++ b/src/libnrtype/Layout-TNG-Scanline-Makers.cpp @@ -85,9 +85,9 @@ Layout::ShapeScanlineMaker::ShapeScanlineMaker(Shape const *shape, Layout::Direc _shape_needs_freeing = true; temp_rotated_shape->Copy(const_cast(shape)); switch (block_progression) { - case BOTTOM_TO_TOP: temp_rotated_shape->Transform(NR::Matrix(1.0, 0.0, 0.0, -1.0, 0.0, 0.0)); break; // reflect about x axis - case LEFT_TO_RIGHT: temp_rotated_shape->Transform(NR::Matrix(0.0, 1.0, 1.0, 0.0, 0.0, 0.0)); break; // reflect about y=x - case RIGHT_TO_LEFT: temp_rotated_shape->Transform(NR::Matrix(0.0, -1.0, 1.0, 0.0, 0.0, 0.0)); break; // reflect about y=-x + case BOTTOM_TO_TOP: temp_rotated_shape->Transform(Geom::Matrix(1.0, 0.0, 0.0, -1.0, 0.0, 0.0)); break; // reflect about x axis + case LEFT_TO_RIGHT: temp_rotated_shape->Transform(Geom::Matrix(0.0, 1.0, 1.0, 0.0, 0.0, 0.0)); break; // reflect about y=x + case RIGHT_TO_LEFT: temp_rotated_shape->Transform(Geom::Matrix(0.0, -1.0, 1.0, 0.0, 0.0, 0.0)); break; // reflect about y=-x default: break; } _rotated_shape = new Shape; diff --git a/src/libnrtype/Layout-TNG.h b/src/libnrtype/Layout-TNG.h index cea97ff2a..3d0c57288 100644 --- a/src/libnrtype/Layout-TNG.h +++ b/src/libnrtype/Layout-TNG.h @@ -14,10 +14,11 @@ #ifdef HAVE_CONFIG_H # include "config.h" #endif -#include "libnr/nr-rect.h" -#include "libnr/nr-matrix.h" -#include "libnr/nr-matrix-ops.h" -#include "libnr/nr-rotate-ops.h" +#include +#include +#include +#include <2geom/d2.h> +#include <2geom/matrix.h> #include #include #include @@ -332,7 +333,7 @@ public: \param transform The transform to be applied to the entire object prior to calculating its bounds. */ - void getBoundingBox(NRRect *bounding_box, NR::Matrix const &transform, int start = -1, int length = -1) const; + void getBoundingBox(NRRect *bounding_box, Geom::Matrix const &transform, int start = -1, int length = -1) const; /** Sends all the glyphs to the given print context. \param ctx I have @@ -341,7 +342,7 @@ public: \param bbox parameters \param ctm do yet */ - void print(SPPrintContext *ctx, NRRect const *pbox, NRRect const *dbox, NRRect const *bbox, NR::Matrix const &ctm) const; + void print(SPPrintContext *ctx, NRRect const *pbox, NRRect const *dbox, NRRect const *bbox, Geom::Matrix const &ctm) const; #ifdef HAVE_CAIRO_PDF /** Renders all the glyphs to the given Cairo rendering context. @@ -375,7 +376,7 @@ public: /** Apply the given transform to all the output presently stored in this object. This only transforms the glyph positions, The glyphs themselves will not be transformed. */ - void transform(NR::Matrix const &transform); + void transform(Geom::Matrix const &transform); //@} @@ -418,13 +419,13 @@ public: /** Returns an iterator pointing to the cursor position for a mouse click at the given coordinates. */ iterator getNearestCursorPositionTo(double x, double y) const; - inline iterator getNearestCursorPositionTo(NR::Point &point) const; + inline iterator getNearestCursorPositionTo(Geom::Point const &point) const; /** Returns an iterator pointing to the letter whose bounding box contains the given coordinates. end() if the point is not over any letter. The iterator will \em not point at the specific glyph within the character. */ iterator getLetterAt(double x, double y) const; - inline iterator getLetterAt(NR::Point &point) const; + inline iterator getLetterAt(Geom::Point &point) const; /** Returns an iterator pointing to the character in the output which was created from the given input. If the character at the given byte @@ -448,7 +449,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. */ - boost::optional glyphBoundingBox(iterator const &it, double *rotation) const; + boost::optional glyphBoundingBox(iterator const &it, double *rotation) const; /** Returns the zero-based line number of the character pointed to by \a it. */ @@ -477,22 +478,22 @@ public: void getSourceOfCharacter(iterator const &it, void **source_cookie, Glib::ustring::iterator *text_iterator = NULL) const; /** For latin text, the left side of the character, on the baseline */ - NR::Point characterAnchorPoint(iterator const &it) const; + Geom::Point characterAnchorPoint(iterator const &it) const; /** This is that value to apply to the x,y attributes of tspan role=line elements, and hence it takes alignment into account. */ - NR::Point chunkAnchorPoint(iterator const &it) const; + Geom::Point chunkAnchorPoint(iterator const &it) const; /** Returns the box extents (not ink extents) of the given character. The centre of rotation is at the horizontal centre of the box on the text baseline. */ - NR::Rect characterBoundingBox(iterator const &it, double *rotation = NULL) const; + Geom::Rect characterBoundingBox(iterator const &it, double *rotation = NULL) const; /** Basically uses characterBoundingBox() on all the characters from \a start to \a end and returns the union of these boxes. The return value is a list of zero or more quadrilaterals specified by a group of four points for each, thus size() is always a multiple of four. */ - std::vector createSelectionShape(iterator const &it_start, iterator const &it_end, NR::Matrix const &transform) const; + std::vector createSelectionShape(iterator const &it_start, iterator const &it_end, Geom::Matrix const &transform) const; /** Returns true if \a it points to a character which is a valid cursor position, as defined by Pango. */ @@ -507,7 +508,7 @@ public: \param rotation The angle to draw from \a position. Radians, zero up, increasing clockwise. */ - void queryCursorShape(iterator const &it, NR::Point *position, double *height, double *rotation) const; + void queryCursorShape(iterator const &it, Geom::Point &position, double &height, double &rotation) const; /** Returns true if \a it points to a character which is a the start of a word, as defined by Pango. */ @@ -652,7 +653,7 @@ private: void _calculateCursorShapeForEmpty(); struct CursorShape { - NR::Point position; + Geom::Point position; double height; double rotation; } _empty_cursor_shape; @@ -737,7 +738,7 @@ private: /** gets the overall matrix that transforms the given glyph from local space to world space. */ - void _getGlyphTransformMatrix(int glyph_index, NR::Matrix *matrix) const; + void _getGlyphTransformMatrix(int glyph_index, Geom::Matrix *matrix) const; // loads of functions to drill down the object tree, all of them // annoyingly similar and all of them requiring predicate functors. @@ -954,10 +955,10 @@ inline void Layout::validateIterator(Layout::iterator *it) const it->_glyph_index = _characters[it->_char_index].in_glyph; } -inline Layout::iterator Layout::getNearestCursorPositionTo(NR::Point &point) const +inline Layout::iterator Layout::getNearestCursorPositionTo(Geom::Point const &point) const {return getNearestCursorPositionTo(point[0], point[1]);} -inline Layout::iterator Layout::getLetterAt(NR::Point &point) const +inline Layout::iterator Layout::getLetterAt(Geom::Point &point) const {return getLetterAt(point[0], point[1]);} inline unsigned Layout::lineIndex(iterator const &it) const diff --git a/src/libnrtype/RasterFont.cpp b/src/libnrtype/RasterFont.cpp index 10e653664..3fbbe62d7 100644 --- a/src/libnrtype/RasterFont.cpp +++ b/src/libnrtype/RasterFont.cpp @@ -26,7 +26,7 @@ void font_style::Apply(Path* src,Shape* dest) { if ( stroke_width > 0 ) { if ( nbDash > 0 ) { double dlen = 0.0; - const float scale = 1/*NR::expansion(transform)*/; + const float scale = 1/*Geom::expansion(transform)*/; for (int i = 0; i < nbDash; i++) dlen += dashes[i] * scale; if (dlen >= 0.01) { float sc_offset = dash_offset * scale; @@ -96,26 +96,26 @@ raster_glyph* raster_font::GetGlyph(int glyph_id) } return res; } -NR::Point raster_font::Advance(int glyph_id) +Geom::Point raster_font::Advance(int glyph_id) { - if ( daddy == NULL ) return NR::Point(0,0); + if ( daddy == NULL ) return Geom::Point(0,0); double a=daddy->Advance(glyph_id,style.vertical); - NR::Point f_a=(style.vertical)?NR::Point(0,a):NR::Point(a,0); + Geom::Point f_a=(style.vertical)?Geom::Point(0,a):Geom::Point(a,0); return f_a*style.transform; } void raster_font::BBox(int glyph_id,NRRect *area) { area->x0=area->y0=area->x1=area->y1=0; if ( daddy == NULL ) return; - boost::optional res=daddy->BBox(glyph_id); + boost::optional 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]); + Geom::Point bmi=res->min(),bma=res->max(); + Geom::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=Geom::Rect(tlp,trp); res->expandTo(blp); res->expandTo(brp); area->x0=(res->min())[0]; @@ -356,7 +356,7 @@ void raster_glyph::LoadSubPixelPosition(int no) delete theI; } -void raster_glyph::Blit(const NR::Point &at,NRPixBlock &over) +void raster_glyph::Blit(const Geom::Point &at,NRPixBlock &over) { if ( nb_sub_pixel <= 0 ) return; int pv=(int)ceil(at[1]); diff --git a/src/libnrtype/RasterFont.h b/src/libnrtype/RasterFont.h index 268b7c58f..015121b42 100644 --- a/src/libnrtype/RasterFont.h +++ b/src/libnrtype/RasterFont.h @@ -36,7 +36,7 @@ public: void Ref(void); // utility functions - NR::Point Advance(int glyph_id); + Geom::Point Advance(int glyph_id); void BBox(int glyph_id,NRRect *area); // attempts to load a glyph and return a raster_glyph on which you can call Blit diff --git a/src/libnrtype/font-instance.h b/src/libnrtype/font-instance.h index f2e3438f1..2c8340e8a 100644 --- a/src/libnrtype/font-instance.h +++ b/src/libnrtype/font-instance.h @@ -13,6 +13,7 @@ #include #include #include "libnr/nr-rect.h" +#include <2geom/d2.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,10 +78,10 @@ public: bool FontMetrics(double &ascent, double &descent, double &leading); bool FontSlope(double &run, double &rise); // for generating slanted cursors for oblique fonts - boost::optional BBox(int glyph_id); + boost::optional BBox(int glyph_id); // creates a rasterfont for the given style - raster_font* RasterFont(NR::Matrix const &trs, double stroke_width, + raster_font* RasterFont(Geom::Matrix const &trs, double stroke_width, bool vertical = false, JoinType stroke_join = join_straight, ButtType stroke_cap = butt_straight, float miter_limit = 4.0); // the dashes array in iStyle is copied diff --git a/src/libnrtype/font-style.h b/src/libnrtype/font-style.h index 748d2020a..20f03df86 100644 --- a/src/libnrtype/font-style.h +++ b/src/libnrtype/font-style.h @@ -1,7 +1,7 @@ #ifndef SEEN_LIBNRTYPE_FONT_STYLE_H #define SEEN_LIBNRTYPE_FONT_STYLE_H -#include +#include <2geom/matrix.h> #include #include @@ -9,7 +9,7 @@ // Different raster styles. struct font_style { - NR::Matrix transform; // the ctm. contains the font-size + Geom::Matrix transform; // the ctm. contains the font-size bool vertical; // should be rendered vertically or not? // good font support would take the glyph alternates for vertical mode, when present double stroke_width; // if 0, the glyph is filled; otherwise stroked diff --git a/src/libnrtype/raster-glyph.h b/src/libnrtype/raster-glyph.h index d8a85a4a1..82a0b3f8e 100644 --- a/src/libnrtype/raster-glyph.h +++ b/src/libnrtype/raster-glyph.h @@ -31,7 +31,7 @@ public: // the interesting function: blits the glyph onto over // over should be a mask, ie a NRPixBlock with one 8bit plane - void Blit(NR::Point const &at, NRPixBlock &over); // alpha only + void Blit(Geom::Point const &at, NRPixBlock &over); // alpha only }; diff --git a/src/nodepath.cpp b/src/nodepath.cpp index 5345485e2..2b3ae46fc 100644 --- a/src/nodepath.cpp +++ b/src/nodepath.cpp @@ -3712,7 +3712,7 @@ node_request(SPKnot */*knot*/, NR::Point *p, guint state, gpointer data) } } - n->subpath->nodepath->desktop->scroll_to_point(p); + n->subpath->nodepath->desktop->scroll_to_point(*p); return TRUE; } diff --git a/src/rubberband.cpp b/src/rubberband.cpp index bfe73a43d..97a260f0f 100644 --- a/src/rubberband.cpp +++ b/src/rubberband.cpp @@ -79,7 +79,7 @@ void Inkscape::Rubberband::move(NR::Point const &p) return; _end = p; - _desktop->scroll_to_point(&p); + _desktop->scroll_to_point(p); _touchpath_curve->lineto(p); NR::Point next = _desktop->d2w(p); diff --git a/src/selcue.cpp b/src/selcue.cpp index 2ce9a8b50..d8d624e94 100644 --- a/src/selcue.cpp +++ b/src/selcue.cpp @@ -126,7 +126,7 @@ void Inkscape::SelCue::_updateItemBboxes() if (SP_IS_TEXT(item) || SP_IS_FLOWTEXT(item)) { // visualize baseline Inkscape::Text::Layout const *layout = te_get_layout(item); if (layout != NULL) { - NR::Point a = layout->characterAnchorPoint(layout->begin()) * from_2geom(sp_item_i2d_affine(item)); + Geom::Point a = layout->characterAnchorPoint(layout->begin()) * sp_item_i2d_affine(item); baseline_point = sp_canvas_item_new(sp_desktop_controls(_desktop), SP_TYPE_CTRL, "mode", SP_CTRL_MODE_XOR, "size", 4.0, diff --git a/src/select-context.cpp b/src/select-context.cpp index 7c966c9b9..acbeb2c18 100644 --- a/src/select-context.cpp +++ b/src/select-context.cpp @@ -530,7 +530,7 @@ sp_select_context_root_handler(SPEventContext *event_context, GdkEvent *event) } if (!seltrans->isEmpty()) seltrans->moveTo(p, event->button.state); - desktop->scroll_to_point(&p); + desktop->scroll_to_point(p); gobble_motion_events(GDK_BUTTON1_MASK); ret = TRUE; } else { diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index f47d4b0b7..3e0da0571 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -50,6 +50,8 @@ #include "libnr/nr-matrix-translate-ops.h" #include "libnr/nr-rotate-fns.h" #include "libnr/nr-scale-ops.h" +#include +#include #include "libnr/nr-scale-translate-ops.h" #include "libnr/nr-translate-matrix-ops.h" #include "libnr/nr-translate-scale-ops.h" @@ -152,7 +154,7 @@ GSList *sp_selection_paste_impl (SPDocument *doc, SPObject *parent, GSList **cli NR::Matrix local (sp_item_i2doc_affine(SP_ITEM(parent))); if (!local.test_identity()) { gchar const *t_str = copy->attribute("transform"); - NR::Matrix item_t (NR::identity()); + Geom::Matrix item_t (NR::identity()); if (t_str) sp_svg_transform_read(t_str, &item_t); item_t *= local.inverse(); @@ -489,7 +491,7 @@ void sp_selection_group(SPDesktop *desktop) // At this point, current may already have no item, due to its being a clone whose original is already moved away // So we copy it artificially calculating the transform from its repr->attr("transform") and the parent transform gchar const *t_str = current->attribute("transform"); - NR::Matrix item_t (NR::identity()); + Geom::Matrix item_t (NR::identity()); if (t_str) sp_svg_transform_read(t_str, &item_t); item_t *= sp_item_i2doc_affine(SP_ITEM(doc->getObjectByRepr(current->parent()))); diff --git a/src/shape-editor.cpp b/src/shape-editor.cpp index 32c20ace6..d59e7f0bc 100644 --- a/src/shape-editor.cpp +++ b/src/shape-editor.cpp @@ -565,7 +565,7 @@ void ShapeEditor::select_next () { if (this->nodepath) { sp_nodepath_select_next (this->nodepath); if (this->nodepath->numSelected() >= 1) { - this->desktop->scroll_to_point(&(this->nodepath->singleSelectedCoords()), 1.0); + this->desktop->scroll_to_point(this->nodepath->singleSelectedCoords(), 1.0); } } } @@ -573,7 +573,7 @@ void ShapeEditor::select_prev () { if (this->nodepath) { sp_nodepath_select_prev (this->nodepath); if (this->nodepath->numSelected() >= 1) { - this->desktop->scroll_to_point(&(this->nodepath->singleSelectedCoords()), 1.0); + this->desktop->scroll_to_point(this->nodepath->singleSelectedCoords(), 1.0); } } } diff --git a/src/sp-text.cpp b/src/sp-text.cpp index 59ced44e5..fcfb84968 100644 --- a/src/sp-text.cpp +++ b/src/sp-text.cpp @@ -432,7 +432,7 @@ static void sp_text_snappoints(SPItem const *item, SnapPointsIter p) // the baseline anchor of the first char Inkscape::Text::Layout const *layout = te_get_layout((SPItem *) item); if(layout != NULL) { - *p = layout->characterAnchorPoint(layout->begin()) * from_2geom(sp_item_i2d_affine(item)); + *p = layout->characterAnchorPoint(layout->begin()) * sp_item_i2d_affine(item); } } diff --git a/src/text-context.cpp b/src/text-context.cpp index 4c3329fb7..2a804dfbd 100644 --- a/src/text-context.cpp +++ b/src/text-context.cpp @@ -1568,29 +1568,29 @@ sp_text_context_update_cursor(SPTextContext *tc, bool scroll_to_see) if (!tc->desktop) return; if (tc->text) { - NR::Point p0, p1; + Geom::Point p0, p1; sp_te_get_cursor_coords(tc->text, tc->text_sel_end, p0, p1); - NR::Point const d0 = p0 * from_2geom(sp_item_i2d_affine(SP_ITEM(tc->text))); - NR::Point const d1 = p1 * from_2geom(sp_item_i2d_affine(SP_ITEM(tc->text))); + Geom::Point const d0 = p0 * sp_item_i2d_affine(SP_ITEM(tc->text)); + Geom::Point const d1 = p1 * sp_item_i2d_affine(SP_ITEM(tc->text)); // scroll to show cursor if (scroll_to_see) { - NR::Point const center = SP_EVENT_CONTEXT(tc)->desktop->get_display_area().midpoint(); + Geom::Point const center = SP_EVENT_CONTEXT(tc)->desktop->get_display_area().midpoint(); if (NR::L2(d0 - center) > NR::L2(d1 - center)) // unlike mouse moves, here we must scroll all the way at first shot, so we override the autoscrollspeed - SP_EVENT_CONTEXT(tc)->desktop->scroll_to_point(&d0, 1.0); + SP_EVENT_CONTEXT(tc)->desktop->scroll_to_point(d0, 1.0); else - SP_EVENT_CONTEXT(tc)->desktop->scroll_to_point(&d1, 1.0); + SP_EVENT_CONTEXT(tc)->desktop->scroll_to_point(d1, 1.0); } sp_canvas_item_show(tc->cursor); sp_ctrlline_set_coords(SP_CTRLLINE(tc->cursor), d0, d1); /* fixme: ... need another transformation to get canvas widget coordinate space? */ - im_cursor.x = (int) floor(d0[NR::X]); - im_cursor.y = (int) floor(d0[NR::Y]); - im_cursor.width = (int) floor(d1[NR::X]) - im_cursor.x; - im_cursor.height = (int) floor(d1[NR::Y]) - im_cursor.y; + im_cursor.x = (int) floor(d0[Geom::X]); + im_cursor.y = (int) floor(d0[Geom::Y]); + im_cursor.width = (int) floor(d1[Geom::X]) - im_cursor.x; + im_cursor.height = (int) floor(d1[Geom::Y]) - im_cursor.y; tc->show = TRUE; tc->phase = 1; @@ -1636,7 +1636,7 @@ static void sp_text_context_update_text_selection(SPTextContext *tc) } tc->text_selection_quads.clear(); - std::vector quads; + std::vector quads; if (tc->text != NULL) quads = sp_te_create_selection_quads(tc->text, tc->text_sel_start, tc->text_sel_end, sp_item_i2d_affine(tc->text)); for (unsigned i = 0 ; i < quads.size() ; i += 4) { diff --git a/src/text-editing.cpp b/src/text-editing.cpp index be098b7e9..48266cfce 100644 --- a/src/text-editing.cpp +++ b/src/text-editing.cpp @@ -78,34 +78,34 @@ sp_te_input_is_empty (SPObject const *item) } Inkscape::Text::Layout::iterator -sp_te_get_position_by_coords (SPItem const *item, NR::Point &i_p) +sp_te_get_position_by_coords (SPItem const *item, Geom::Point const &i_p) { - NR::Matrix im (sp_item_i2d_affine (item)); + Geom::Matrix im (sp_item_i2d_affine (item)); im = im.inverse(); - NR::Point p = i_p * im; + Geom::Point p = i_p * im; Inkscape::Text::Layout const *layout = te_get_layout(item); return layout->getNearestCursorPositionTo(p); } -std::vector sp_te_create_selection_quads(SPItem const *item, Inkscape::Text::Layout::iterator const &start, Inkscape::Text::Layout::iterator const &end, NR::Matrix const &transform) +std::vector sp_te_create_selection_quads(SPItem const *item, Inkscape::Text::Layout::iterator const &start, Inkscape::Text::Layout::iterator const &end, Geom::Matrix const &transform) { if (start == end) - return std::vector(); + return std::vector(); Inkscape::Text::Layout const *layout = te_get_layout(item); if (layout == NULL) - return std::vector(); + return std::vector(); return layout->createSelectionShape(start, end, transform); } void -sp_te_get_cursor_coords (SPItem const *item, Inkscape::Text::Layout::iterator const &position, NR::Point &p0, NR::Point &p1) +sp_te_get_cursor_coords (SPItem const *item, Inkscape::Text::Layout::iterator const &position, Geom::Point &p0, Geom::Point &p1) { Inkscape::Text::Layout const *layout = te_get_layout(item); double height, rotation; - layout->queryCursorShape(position, &p0, &height, &rotation); - p1 = NR::Point(p0[NR::X] + height * sin(rotation), p0[NR::Y] - height * cos(rotation)); + layout->queryCursorShape(position, p0, height, rotation); + p1 = Geom::Point(p0[NR::X] + height * sin(rotation), p0[NR::Y] - height * cos(rotation)); } SPStyle const * sp_te_style_at_position(SPItem const *text, Inkscape::Text::Layout::iterator const &position) diff --git a/src/text-editing.h b/src/text-editing.h index 2f3e5363c..bdb6664ee 100644 --- a/src/text-editing.h +++ b/src/text-editing.h @@ -32,10 +32,10 @@ bool sp_te_input_is_empty (SPObject const *item); unsigned sp_text_get_length(SPObject const *item); unsigned sp_text_get_length_upto(SPObject const *item, SPObject const *upto); -std::vector sp_te_create_selection_quads(SPItem const *item, Inkscape::Text::Layout::iterator const &start, Inkscape::Text::Layout::iterator const &end, NR::Matrix const &transform); +std::vector sp_te_create_selection_quads(SPItem const *item, Inkscape::Text::Layout::iterator const &start, Inkscape::Text::Layout::iterator const &end, Geom::Matrix const &transform); -Inkscape::Text::Layout::iterator sp_te_get_position_by_coords (SPItem const *item, NR::Point &i_p); -void sp_te_get_cursor_coords (SPItem const *item, Inkscape::Text::Layout::iterator const &position, NR::Point &p0, NR::Point &p1); +Inkscape::Text::Layout::iterator sp_te_get_position_by_coords (SPItem const *item, Geom::Point const &i_p); +void sp_te_get_cursor_coords (SPItem const *item, Inkscape::Text::Layout::iterator const &position, Geom::Point &p0, Geom::Point &p1); double sp_te_get_average_linespacing (SPItem *text); diff --git a/src/ui/dialog/align-and-distribute.cpp b/src/ui/dialog/align-and-distribute.cpp index e83907f49..0e93ecb12 100644 --- a/src/ui/dialog/align-and-distribute.cpp +++ b/src/ui/dialog/align-and-distribute.cpp @@ -694,7 +694,7 @@ private : { if (SP_IS_TEXT (*it) || SP_IS_FLOWTEXT (*it)) { Inkscape::Text::Layout const *layout = te_get_layout(*it); - Geom::Point base = layout->characterAnchorPoint(layout->begin()) * from_2geom(sp_item_i2d_affine(*it)); + Geom::Point base = layout->characterAnchorPoint(layout->begin()) * sp_item_i2d_affine(*it); if (base[Geom::X] < b_min[Geom::X]) b_min[Geom::X] = base[Geom::X]; if (base[Geom::Y] < b_min[Geom::Y]) b_min[Geom::Y] = base[Geom::Y]; if (base[Geom::X] > b_max[Geom::X]) b_max[Geom::X] = base[Geom::X]; @@ -735,7 +735,7 @@ private : { if (SP_IS_TEXT (*it) || SP_IS_FLOWTEXT (*it)) { Inkscape::Text::Layout const *layout = te_get_layout(*it); - Geom::Point base = layout->characterAnchorPoint(layout->begin()) * from_2geom(sp_item_i2d_affine(*it)); + Geom::Point base = layout->characterAnchorPoint(layout->begin()) * sp_item_i2d_affine(*it); Geom::Point t(0.0, 0.0); t[_orientation] = b_min[_orientation] - base[_orientation]; sp_item_move_rel(*it, NR::translate(t)); diff --git a/src/widgets/font-selector.cpp b/src/widgets/font-selector.cpp index 5c6aa35e7..577efe7c1 100644 --- a/src/widgets/font-selector.cpp +++ b/src/widgets/font-selector.cpp @@ -671,7 +671,7 @@ static gint sp_font_preview_expose(GtkWidget *widget, GdkEventExpose *event) hpos[len] = base_pt[0]; len++; if ( curF ) { - boost::optional nbbox = curF->BBox(str_text->glyph_text[i].gl); + boost::optional nbbox = curF->BBox(str_text->glyph_text[i].gl); if (nbbox) { bbox.x0 = MIN(bbox.x0, base_pt[Geom::X] + theSize * (nbbox->min())[0]); bbox.y0 = MIN(bbox.y0, base_pt[Geom::Y] - theSize * (nbbox->max())[1]);