From 9b62a19cf42b3daab1da50f2e89352edeb031644 Mon Sep 17 00:00:00 2001 From: Hermann Kraus Date: Mon, 19 Mar 2012 17:12:53 +0100 Subject: [PATCH] Implement justify-alignment=auto. Closes #1125. --- bindings/python/mapnik_text_placement.cpp | 1 + include/mapnik/placement_finder.hpp | 1 + include/mapnik/text_properties.hpp | 1 + src/placement_finder.cpp | 44 ++++++++++++++---- src/text_properties.cpp | 2 +- src/text_symbolizer.cpp | 1 + .../jalign-auto-200-reference.png | Bin 0 -> 2316 bytes tests/visual_tests/jalign-auto.xml | 30 ++++++++++++ tests/visual_tests/test.py | 3 +- 9 files changed, 71 insertions(+), 12 deletions(-) create mode 100644 tests/visual_tests/jalign-auto-200-reference.png create mode 100644 tests/visual_tests/jalign-auto.xml diff --git a/bindings/python/mapnik_text_placement.cpp b/bindings/python/mapnik_text_placement.cpp index c9f1ac4e5..13de8478b 100644 --- a/bindings/python/mapnik_text_placement.cpp +++ b/bindings/python/mapnik_text_placement.cpp @@ -329,6 +329,7 @@ void export_text_placement() .value("LEFT",J_LEFT) .value("MIDDLE",J_MIDDLE) .value("RIGHT",J_RIGHT) + .value("AUTO", J_AUTO) ; enumeration_("text_transform") diff --git a/include/mapnik/placement_finder.hpp b/include/mapnik/placement_finder.hpp index 1ee636349..57d6ee2ab 100644 --- a/include/mapnik/placement_finder.hpp +++ b/include/mapnik/placement_finder.hpp @@ -137,6 +137,7 @@ private: double first_line_space_; vertical_alignment_e valign_; horizontal_alignment_e halign_; + justify_alignment_e jalign_; std::vector line_breaks_; std::vector > line_sizes_; std::queue< box2d > envelopes_; diff --git a/include/mapnik/text_properties.hpp b/include/mapnik/text_properties.hpp index 9f12b3663..7b6ab953a 100644 --- a/include/mapnik/text_properties.hpp +++ b/include/mapnik/text_properties.hpp @@ -110,6 +110,7 @@ enum justify_alignment J_LEFT = 0, J_MIDDLE, J_RIGHT, + J_AUTO, justify_alignment_MAX }; diff --git a/src/placement_finder.cpp b/src/placement_finder.cpp index 719b56dee..5419cb8b6 100644 --- a/src/placement_finder.cpp +++ b/src/placement_finder.cpp @@ -305,23 +305,47 @@ template void placement_finder::init_alignment() { valign_ = p.valign; - if (valign_ == V_AUTO) { + if (valign_ == V_AUTO) + { if (p.displacement.second > 0.0) + { valign_ = V_BOTTOM; - else if (p.displacement.second < 0.0) + } else if (p.displacement.second < 0.0) + { valign_ = V_TOP; - else + } else + { valign_ = V_MIDDLE; + } } halign_ = p.halign; - if (halign_ == H_AUTO) { + if (halign_ == H_AUTO) + { if (p.displacement.first > 0.0) + { halign_ = H_RIGHT; - else if (p.displacement.first < 0.0) + } else if (p.displacement.first < 0.0) + { halign_ = H_LEFT; - else + } else + { halign_ = H_MIDDLE; + } + } + + jalign_ = p.jalign; + if (jalign_ == J_AUTO) + { + if (p.displacement.first > 0.0) + { + jalign_ = J_LEFT; + } else if (p.displacement.first < 0.0) + { + jalign_ = J_RIGHT; + } else { + jalign_ = J_MIDDLE; + } } } @@ -389,9 +413,9 @@ void placement_finder::find_point_placement(double label_x, if (info_.get_rtl()) y = -y; // adjust for desired justification - if (p.jalign == J_LEFT) + if (jalign_ == J_LEFT) x = -(string_width_ / 2.0); - else if (p.jalign == J_RIGHT) + else if (jalign_ == J_RIGHT) x = (string_width_ / 2.0) - line_width; else /* J_MIDDLE */ x = -(line_width / 2.0); @@ -420,9 +444,9 @@ void placement_finder::find_point_placement(double label_x, } // reset to begining of line position - if (p.jalign == J_LEFT) + if (jalign_ == J_LEFT) x = -(string_width_ / 2.0); - else if (p.jalign == J_RIGHT) + else if (jalign_ == J_RIGHT) x = (string_width_ / 2.0) - line_width; else x = -(line_width / 2.0); diff --git a/src/text_properties.cpp b/src/text_properties.cpp index 4587cb5e4..89e4ee6cd 100644 --- a/src/text_properties.cpp +++ b/src/text_properties.cpp @@ -40,7 +40,7 @@ text_symbolizer_properties::text_symbolizer_properties() : displacement(0,0), label_placement(POINT_PLACEMENT), halign(H_AUTO), - jalign(J_MIDDLE), + jalign(J_AUTO), valign(V_AUTO), label_spacing(0), label_position_tolerance(0), diff --git a/src/text_symbolizer.cpp b/src/text_symbolizer.cpp index c060e43d1..75e76849b 100644 --- a/src/text_symbolizer.cpp +++ b/src/text_symbolizer.cpp @@ -69,6 +69,7 @@ static const char * justify_alignment_strings[] = { "left", "center", "right", + "auto", "" }; diff --git a/tests/visual_tests/jalign-auto-200-reference.png b/tests/visual_tests/jalign-auto-200-reference.png new file mode 100644 index 0000000000000000000000000000000000000000..6acf39cdcda902403d7997b85918ab1092898dfa GIT binary patch literal 2316 zcmd5;Yc$(w9u7*CYHeGlrD+*dl^Rv0?xE5!BwA7FP)w=1Z;qPQR4T%Z7S%;f-APdq zRI+Yy>1b-)gLEng73{VWl1Mn@LNx5(?0lF#XV2Nw`LrM2%kR9u_dL(<^1SEGxPpLb zsOhMIKp+hdcQ+qk9o!wND!|-uom372sWLp=TztPT70kljeFKjV#3jVO|61L|B)y5K zYDr7a^m~|6|Nh92N6gO{W?H+rKv!}|Pv59krq1<7>ECoyhU&bAv|7XdB)I2a1G_i^(f1^fJs_hZ;9fR^39d4M_Evg2Mhidn`0H-#{QB zrT;JEQjo%?m|wtZk2BzZWYl=yZ`fFTi#OPoY_5k-x1ob&wkCn}ANC$x5YE2hY%MY8 z)5gh-KcOJlPaFF73BvEPuhshvRYD(+?Z_p9nbLxF&Zuq?aF9-=Chr8@9xXNse*GY~ z3YN`bw7kqW4?I(kBGWrbUZP=be`>!^cg=NU@AB``=px~)z3si_!sWTH8SuVwfC+nz zJWYPD@KA7z^)YkBZ#<0`$>)}ReNpAWXbH(2di zFmg9+{nO_9&uR$j2Og^NzIr;=fsS_$HowuXckrasPkoQS7zX$(Y)My|ZVeqmwUpSP zX_;E4EZCBW%V2NIx7L=Yn?;sB%HEDttla;UcexoxDtrcvpnSpZI&FeuAPIdK@0(LvfrdAaR9o5hsqr>V>?dF)NBgL zIhNIa^)|iKB<~db4%9h8cwDX%4urj8qb43)U1NK0N(3b<&}Q?=3!L`614mU=ztz*j z=@W4qCuY_ch7Q|eBrk7t-03^ZFz)hXO-ww)B3#LbxbTkrd~GhDzdruUPMlm;oSCa z$f_skt6Azf^-Gq*XkK>LS0)<*=H3^pxx-+Obg}Q|=7c0EKS`X) zW+ZWZG^YN*D6y_?ZIWIXrBkV=^dUYbdrazGW;dZxv1+81GajFm)aC2v*9pG7V!K4I z5;2}rD1LVK_SLnu9#K(IBWxaq$K(CndY(}H@bm`G5Ij?L$p}DS{M)iqn0oq&A|#DQ zV>QpMjxql38!$XP40AmD4(v1F97#>es0CO%>3IOGO}Yv2lFKX?iGBdYKOlfXu2HP) z=@mzmO;1)-RQzR_FBIOJcb08!by0ppqTv=SDKMLb{IdbKwj=^*WHbqA!8@G!<|i&Z zf#6wYX6DUHL%$(pTI%u8p%@{n!@$VMNJxBHV=Ma=Uo3kX4N*~1VXc^2ot6;C^Sww z9*Qvc@<%3&oNDoNb;!o)Ztr@LdML=sA8{Gg`0?# zTYyvdUcf1@f-vN^>qG}%fS;n_P6Im)U`NC)nD#e1R#XvspkU4CQ~&Pi&x`i=JNL)Z zu&D^M9C!VOQ)$0D)#e$+pALh2&ZQ`OwP;uCGGtlCYT zVq;^+7>vA#ZxYkoXNU!UcO`^Bis#%2x9sx;bEv0ut`_&AoX_W1H#Ln3EE38^?P^wb%N{Wa3kwr|gZ`cydA+WI z&1P4X=Pw*vM8c!=S)sciukp-C5t#m|8UCPh=_>Zwa! + + + + + My Style + + shape + points.shp + + + + + + diff --git a/tests/visual_tests/test.py b/tests/visual_tests/test.py index 804137c0b..8d9d3166f 100755 --- a/tests/visual_tests/test.py +++ b/tests/visual_tests/test.py @@ -28,7 +28,8 @@ files = [ ("formating-4", 500), ("shieldsymbolizer-1", 490, 495, 497, 498, 499, 500, 501, 502, 505, 510), ("expressionformat", 500), - ("rtl-point", (200, 200)) + ("rtl-point", (200, 200)), + ("jalign-auto", (200, 200)) ] def render(filename, width, height=100):