diff options
| author | Diederik van Lierop <mail@diedenrezi.nl> | 2012-01-04 22:00:14 +0000 |
|---|---|---|
| committer | Diederik van Lierop <mail@diedenrezi.nl> | 2012-01-04 22:00:14 +0000 |
| commit | 06c98445aa4d1471952df089d636e6e288587edc (patch) | |
| tree | f85777707fe6e6c6f86541ee7367e21f21575380 /src | |
| parent | Final fix for CanvasText alignment bugs (diff) | |
| download | inkscape-06c98445aa4d1471952df089d636e6e288587edc.tar.gz inkscape-06c98445aa4d1471952df089d636e6e288587edc.zip | |
CanvasText: reinstate ability to set anchor position manually
(bzr r10841)
Diffstat (limited to 'src')
| -rw-r--r-- | src/display/canvas-text.cpp | 19 | ||||
| -rw-r--r-- | src/display/canvas-text.h | 6 | ||||
| -rw-r--r-- | src/live_effects/parameter/text.cpp | 8 | ||||
| -rw-r--r-- | src/lpe-tool-context.cpp | 6 |
4 files changed, 23 insertions, 16 deletions
diff --git a/src/display/canvas-text.cpp b/src/display/canvas-text.cpp index 998b7054f..3a51fc570 100644 --- a/src/display/canvas-text.cpp +++ b/src/display/canvas-text.cpp @@ -74,6 +74,8 @@ static void sp_canvastext_init (SPCanvasText *canvastext) { canvastext->anchor_position = TEXT_ANCHOR_CENTER; + canvastext->anchor_pos_x_manual = 0; + canvastext->anchor_pos_y_manual = 0; canvastext->anchor_offset_x = 0; canvastext->anchor_offset_y = 0; canvastext->rgba = 0x33337fff; @@ -231,6 +233,10 @@ sp_canvastext_update (SPCanvasItem *item, Geom::Affine const &affine, unsigned i cl->anchor_offset_x = 0; cl->anchor_offset_y = 0; break; + case TEXT_ANCHOR_MANUAL: + cl->anchor_offset_x = (1 + cl->anchor_pos_x_manual) * extents.width/2; + cl->anchor_offset_y = -(1 + cl->anchor_pos_y_manual) * extents.height/2; + break; case TEXT_ANCHOR_CENTER: default: cl->anchor_offset_x = extents.width/2; @@ -328,12 +334,13 @@ sp_canvastext_set_fontsize (SPCanvasText *ct, double size) ct->fontsize = size; } -//void -//sp_canvastext_set_anchor (SPCanvasText *ct, double anchor_x, double anchor_y) -//{ -// ct->anchor_x = anchor_x; -// ct->anchor_y = anchor_y; -//} +void +sp_canvastext_set_anchor_manually (SPCanvasText *ct, double anchor_x, double anchor_y) +{ + ct->anchor_pos_x_manual = anchor_x; + ct->anchor_pos_y_manual = anchor_y; + ct->anchor_position = TEXT_ANCHOR_MANUAL; +} /* diff --git a/src/display/canvas-text.h b/src/display/canvas-text.h index 4a7e4f16c..ecdb77f1c 100644 --- a/src/display/canvas-text.h +++ b/src/display/canvas-text.h @@ -29,7 +29,8 @@ enum CanvasTextAnchorPositionEnum { TEXT_ANCHOR_BOTTOM, TEXT_ANCHOR_LEFT, TEXT_ANCHOR_RIGHT, - TEXT_ANCHOR_ZERO + TEXT_ANCHOR_ZERO, + TEXT_ANCHOR_MANUAL }; struct SPCanvasText : public SPCanvasItem { @@ -46,6 +47,8 @@ struct SPCanvasText : public SPCanvasItem { gchar* text; Geom::Point s; // Is the coordinate of the anchor, which is related to the rectangle filled with the background color CanvasTextAnchorPositionEnum anchor_position; // The anchor position specifies where the anchor is with respect to the rectangle filled with the background color + double anchor_pos_x_manual; + double anchor_pos_y_manual; Geom::Affine affine; double fontsize; double anchor_offset_x; @@ -63,6 +66,7 @@ void sp_canvastext_set_coords (SPCanvasText *ct, const Geom::Point start); void sp_canvastext_set_text (SPCanvasText *ct, gchar const* new_text); void sp_canvastext_set_number_as_text (SPCanvasText *ct, int num); void sp_canvastext_set_fontsize (SPCanvasText *ct, double size); +void sp_canvastext_set_anchor_manually (SPCanvasText *ct, double anchor_x, double anchor_y); #endif // SEEN_SP_CANVASTEXT_H diff --git a/src/live_effects/parameter/text.cpp b/src/live_effects/parameter/text.cpp index 8b77427c4..be36627a1 100644 --- a/src/live_effects/parameter/text.cpp +++ b/src/live_effects/parameter/text.cpp @@ -62,12 +62,10 @@ TextParam::setPosAndAnchor(const Geom::Piecewise<Geom::D2<Geom::SBasis> > &pwd2, Point pos = pwd2_reparam.valueAt(t_reparam); Point dir = unit_vector(derivative(pwd2_reparam).valueAt(t_reparam)); Point n = -rot90(dir); - // double angle = Geom::angle_between(dir, Point(1,0)); + double angle = Geom::angle_between(dir, Point(1,0)); sp_canvastext_set_coords(canvas_text, pos + n * length); - // Canvastext currently no longer allows for setting a custom anchor position, - // This functionality was broken as of rev. #10331 (2011-06-21), and for now completely removed as of 2012-01-01 - //sp_canvastext_set_anchor(canvas_text, std::sin(angle), -std::cos(angle)); + sp_canvastext_set_anchor_manually(canvas_text, std::sin(angle), -std::cos(angle)); } void @@ -75,7 +73,7 @@ TextParam::setAnchor(double x_value, double y_value) { anchor_x = x_value; anchor_y = y_value; - //sp_canvastext_set_anchor (canvas_text, anchor_x, anchor_y); + sp_canvastext_set_anchor_manually (canvas_text, anchor_x, anchor_y); } bool diff --git a/src/lpe-tool-context.cpp b/src/lpe-tool-context.cpp index eb4cd0876..c4d38c400 100644 --- a/src/lpe-tool-context.cpp +++ b/src/lpe-tool-context.cpp @@ -446,12 +446,10 @@ set_pos_and_anchor(SPCanvasText *canvas_text, const Geom::Piecewise<Geom::D2<Geo Point pos = pwd2_reparam.valueAt(t_reparam); Point dir = unit_vector(derivative(pwd2_reparam).valueAt(t_reparam)); Point n = -rot90(dir); - // double angle = Geom::angle_between(dir, Point(1,0)); + double angle = Geom::angle_between(dir, Point(1,0)); sp_canvastext_set_coords(canvas_text, pos + n * length); - // Canvastext currently no longer allows for setting a custom anchor position, - // This functionality was broken as of rev. #10331, and completely removed as of 2012-01-01 - //sp_canvastext_set_anchor(canvas_text, std::sin(angle), -std::cos(angle)); + sp_canvastext_set_anchor_manually(canvas_text, std::sin(angle), -std::cos(angle)); } void |
