add text-transform:reverse + full test coverage for text-transform uppercase/lowercase/capitalize - closes #2634

This commit is contained in:
Dane Springmeyer 2015-01-12 15:38:21 -08:00
parent 248c8a79c2
commit 056feb4daa
10 changed files with 88 additions and 78 deletions

View file

@ -125,6 +125,7 @@ enum text_transform_enum : std::uint8_t
UPPERCASE, UPPERCASE,
LOWERCASE, LOWERCASE,
CAPITALIZE, CAPITALIZE,
REVERSE,
text_transform_enum_MAX text_transform_enum_MAX
}; };

View file

@ -160,6 +160,7 @@ static const char * text_transform_strings[] = {
"uppercase", "uppercase",
"lowercase", "lowercase",
"capitalize", "capitalize",
"reverse",
"" ""
}; };

View file

@ -28,6 +28,7 @@
#include <mapnik/text/text_properties.hpp> #include <mapnik/text/text_properties.hpp>
#include <mapnik/xml_node.hpp> #include <mapnik/xml_node.hpp>
#include <mapnik/text/text_layout.hpp> #include <mapnik/text/text_layout.hpp>
#include <mapnik/debug.hpp>
// boost // boost
#include <boost/property_tree/ptree.hpp> #include <boost/property_tree/ptree.hpp>
@ -53,21 +54,28 @@ node_ptr text_node::from_xml(xml_node const& xml, fontset_map const& fontsets)
void text_node::apply(evaluated_format_properties_ptr const& p, feature_impl const& feature, attributes const& vars, text_layout &output) const void text_node::apply(evaluated_format_properties_ptr const& p, feature_impl const& feature, attributes const& vars, text_layout &output) const
{ {
mapnik::value_unicode_string text_str = util::apply_visitor(evaluate<feature_impl,value_type,attributes>(feature,vars), *text_).to_unicode(); mapnik::value_unicode_string text_str = util::apply_visitor(evaluate<feature_impl,value_type,attributes>(feature,vars), *text_).to_unicode();
if (p->text_transform == UPPERCASE) switch (p->text_transform)
{ {
text_str = text_str.toUpper(); case UPPERCASE:
} text_str.toUpper();
else if (p->text_transform == LOWERCASE) break;
{ case LOWERCASE:
text_str = text_str.toLower(); text_str.toLower();
} break;
case REVERSE:
text_str.reverse();
break;
case CAPITALIZE:
#if !UCONFIG_NO_BREAK_ITERATION #if !UCONFIG_NO_BREAK_ITERATION
else if (p->text_transform == CAPITALIZE)
{
// note: requires BreakIterator support in ICU which is optional // note: requires BreakIterator support in ICU which is optional
text_str = text_str.toTitle(nullptr); text_str.toTitle(nullptr);
} #else
MAPNIK_LOG_DEBUG(text_node) << "text capitalize (toTitle) disabled because ICU was built without UCONFIG_NO_BREAK_ITERATION";
#endif #endif
break;
default:
break;
}
if (text_str.length() > 0) { if (text_str.length() > 0) {
output.add_text(text_str, p); output.add_text(text_str, p);
} }

View file

@ -2,8 +2,8 @@
"keys": [ "keys": [
"", "",
"9", "9",
"2",
"1", "1",
"2",
"8", "8",
"3", "3",
"4", "4",
@ -35,23 +35,23 @@
" !! ", " !! ",
" ! ! ", " ! ! ",
" ! ", " ! ",
" # !! ", " !! ",
" $ ### %% %%% ! ", " # $$ %% %%% ! ",
" $ # % % % !! ", " # $ & % % % !! ",
" $ $$ # & & && %% % % !!! ", " # ## $ &&& & %% % % !!! ",
" $$$ $ ## & & & ' ( )) * % ! ++ + + ", " ### # $$$ & && & ' ( )) * % ! ++ + + ",
" $ $ &&& &&& ( )) + + ++ ", " # # & & ''' ( )) + + ++ ",
" $$$ ### '' ( ) + + ++ ", " ### $ '' ( ) + + ++ ",
" $ ### ' ' ( ( ) * * ** ", " # $ ' ' ( ( ) * * ** ",
" '' ' ' ( ( )) * * * ", " '' ( ( )) * * * ",
" '' ' ''' ( *** *** ", " ' ' ( *** *** ",
" ' '' ''' (( )) ", " '' '' ' (( )) ",
" ' ' '' ( ) ) ", " ' ' '' ( ) ) ",
" '''' '' ",
" ' ' ", " ' ' ",
" ''' ",
" '' ", " '' ",
" '' ", " ",
" '' ",
" '' ",
" ", " ",
" ", " ",
" ", " ",

View file

@ -1,6 +1,7 @@
{ {
"keys": [ "keys": [
"", "",
"9",
"1", "1",
"2", "2",
"8", "8",
@ -9,7 +10,6 @@
"5", "5",
"6", "6",
"7", "7",
"9",
"10" "10"
], ],
"data": {}, "data": {},
@ -24,45 +24,45 @@
" ", " ",
" ", " ",
" ", " ",
" ", " !! ",
" ", " ! ! ",
" ", " ! !! ",
" ", " ! !! ",
" ", " ! ! ",
" ", " !! ",
" ", " !! ",
" ", " !!! ",
" ! ## # ", " # !! ",
" !! # # # $ $$$ $$$$$$ ", " ## $$ % %%% %%%%!% ",
" ! ! # # # $$ $ $$ $ $$ ", " # # $$$ %% % %% % !% ",
" ! ! # ## $$ $$$ $ ", " # # $ $$ & %% %%% %!! !! ",
" ! ! !! # # %%%%% % % % $$ $ $ ", " # # ## &&&& & & & %% % % !! ",
" ! !!! ## % % % %% $$$ $ $ ", " # ### $$ & && & & %%% % % !! ! ",
" ! ! !! ## %% % % % $ $ $ $ ", " # # ## $$ & & & && % % % % ! ! ",
" !!! ! #### %% % % & ' ( ) $ * +++++ + + ++ ", " ### # $$$$$ & & && & ' ( ) * % ! +++++ + + ++ ",
" ! ! ## % % % % % ' (( ( + + + ++ ", " # # $$ $ &&&& & & &&& ( )) ) + + + ++ ",
" ! ! # % %% % % % '' ( ( ( ++ + +++ ", " # # & & ' ''' (( ) ) ) ++ + +++ ",
" !!!! # # ' ' ( ((( ++ + + ", " #### $ $ ''' ' ( ( ) ))) ++ + + ",
" !!!!! ## ## ' ' ' ( (( + + + + + ", " ##### $$ ''' ' ( ( ( ) )) + + + + + ",
" ! ## ' ' ' ( ))))) ) ) ) +++++++ ++ + ++ ", " # $$$$ ' '' ' ( ( ( ) ***** * * * +++++++ ++ + ++ ",
" ! ## # ' '' (( ) ) ) ) ", " # $ $ ' '' ( (( )) * * * * ",
" ! # # '' ' ' (( )) ) ))) ", " # ' (( ( ( )) ** * *** ",
" ' '' (((( )) ) ) ", " '''' ' ( (( )))) ** * * ",
" ' ' ( ) ) ) ) ) ", " ' ' ( ( ) * * * * * ",
" ' ( )))))) )))) )) ", " '' ' ( ) ****** **** ** ",
" ''''' ( ( ", " '' '' ' '' ((((( ) ) ",
" ' '' (( ( ", " '' ' ' '' ' ( (( )) ) ",
" ' (( ", " ' ' ' '' ' ( )) ",
" ' ( (( ", " ' ' ' '' ( ) )) ",
" ( ( ", " ' '' '' ' ) ) ",
" ", " '' ' ' ' ",
" ", " '''' ' ' ",
" ", " ' ' ",
" ", " '''' ' ",
" ", " ' ' ",
" ", " '' ' ",
" ", " '' ' ",
" ", " ' ",
" " " "
] ]
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 6 KiB

View file

@ -17,52 +17,52 @@
<Style name="My Style"> <Style name="My Style">
<Rule> <Rule>
<Filter>[nr] = 1</Filter> <Filter>[nr] = 1</Filter>
<TextSymbolizer face-name="DejaVu Sans Book" size="16" placement="point" orientation="rad_to_deg*0.7853981633974483">"XYZ"</TextSymbolizer> <TextSymbolizer face-name="DejaVu Sans Book" size="16" placement="point" allow-overlap="true" text-transform="uppercase" orientation="rad_to_deg*0.7853981633974483">"XYZ"</TextSymbolizer>
<PointSymbolizer allow-overlap="true"/> <PointSymbolizer allow-overlap="true"/>
</Rule> </Rule>
<Rule> <Rule>
<Filter>[nr] = 2</Filter> <Filter>[nr] = 2</Filter>
<TextSymbolizer face-name="DejaVu Sans Book" size="16" placement="point" orientation="180/pi*1.5707963267948966">"XYZ"</TextSymbolizer> <TextSymbolizer face-name="DejaVu Sans Book" size="16" placement="point" allow-overlap="true" text-transform="lowercase" orientation="180/pi*1.5707963267948966">"XYZ"</TextSymbolizer>
<PointSymbolizer allow-overlap="true"/> <PointSymbolizer allow-overlap="true"/>
</Rule> </Rule>
<Rule> <Rule>
<Filter>[nr] = 3</Filter> <Filter>[nr] = 3</Filter>
<TextSymbolizer face-name="DejaVu Sans Book" size="16" placement="point" orientation="180">"XYZ"</TextSymbolizer> <TextSymbolizer face-name="DejaVu Sans Book" size="16" placement="point" allow-overlap="true" text-transform="capitalize" orientation="180">"XYZ"</TextSymbolizer>
<PointSymbolizer allow-overlap="true"/> <PointSymbolizer allow-overlap="true"/>
</Rule> </Rule>
<Rule> <Rule>
<Filter>[nr] = 4</Filter> <Filter>[nr] = 4</Filter>
<TextSymbolizer face-name="DejaVu Sans Book" size="16" placement="point" orientation="45" dy="10">"Line&#10;break"</TextSymbolizer> <TextSymbolizer face-name="DejaVu Sans Book" size="16" placement="point" allow-overlap="true" text-transform="reverse" orientation="45" dy="10">"Line&#10;break"</TextSymbolizer>
<PointSymbolizer allow-overlap="true"/> <PointSymbolizer allow-overlap="true"/>
</Rule> </Rule>
<Rule> <Rule>
<Filter>[nr] = 5</Filter> <Filter>[nr] = 5</Filter>
<TextSymbolizer face-name="DejaVu Sans Book" size="16" placement="point" orientation="45" dy="10">"XYZ"</TextSymbolizer> <TextSymbolizer face-name="DejaVu Sans Book" size="16" placement="point" allow-overlap="true" orientation="45" dy="10">"XYZ"</TextSymbolizer>
<PointSymbolizer allow-overlap="true"/> <PointSymbolizer allow-overlap="true"/>
</Rule> </Rule>
<Rule> <Rule>
<Filter>[nr] = 6</Filter> <Filter>[nr] = 6</Filter>
<TextSymbolizer face-name="DejaVu Sans Book" size="16" placement="point" orientation="90" dy="10">"XYZ"</TextSymbolizer> <TextSymbolizer face-name="DejaVu Sans Book" size="16" placement="point" allow-overlap="true" orientation="90" dy="10">"XYZ"</TextSymbolizer>
<PointSymbolizer allow-overlap="true"/> <PointSymbolizer allow-overlap="true"/>
</Rule> </Rule>
<Rule> <Rule>
<Filter>[nr] = 7</Filter> <Filter>[nr] = 7</Filter>
<TextSymbolizer face-name="DejaVu Sans Book" size="16" placement="point" orientation="180" dy="10">"XYZ"</TextSymbolizer> <TextSymbolizer face-name="DejaVu Sans Book" size="16" placement="point" allow-overlap="true" orientation="180" dy="10">"XYZ"</TextSymbolizer>
<PointSymbolizer allow-overlap="true"/> <PointSymbolizer allow-overlap="true"/>
</Rule> </Rule>
<Rule> <Rule>
<Filter>[nr] = 8</Filter> <Filter>[nr] = 8</Filter>
<TextSymbolizer face-name="DejaVu Sans Book" size="16" placement="point" orientation="0" horizontal-alignment="right" vertical-alignment="top" rotate-displacement="true">"XYZ"</TextSymbolizer> <TextSymbolizer face-name="DejaVu Sans Book" size="16" placement="point" allow-overlap="true" orientation="0" horizontal-alignment="right" vertical-alignment="top" rotate-displacement="true">"XYZ"</TextSymbolizer>
<PointSymbolizer allow-overlap="true"/> <PointSymbolizer allow-overlap="true"/>
</Rule> </Rule>
<Rule> <Rule>
<Filter>[nr] = 9</Filter> <Filter>[nr] = 9</Filter>
<TextSymbolizer face-name="DejaVu Sans Book" size="16" placement="point" orientation="90" horizontal-alignment="right" vertical-alignment="top" rotate-displacement="true">"XYZ"</TextSymbolizer> <TextSymbolizer face-name="DejaVu Sans Book" size="16" placement="point" allow-overlap="true" orientation="90" horizontal-alignment="right" vertical-alignment="top" rotate-displacement="true">"XYZ"</TextSymbolizer>
<PointSymbolizer allow-overlap="true"/> <PointSymbolizer allow-overlap="true"/>
</Rule> </Rule>
<Rule> <Rule>
<Filter>[nr] = 10</Filter> <Filter>[nr] = 10</Filter>
<TextSymbolizer face-name="DejaVu Sans Book" size="16" placement="point" orientation="180" horizontal-alignment="right" vertical-alignment="top" rotate-displacement="true">"XYZ"</TextSymbolizer> <TextSymbolizer face-name="DejaVu Sans Book" size="16" placement="point" allow-overlap="true" orientation="180" horizontal-alignment="right" vertical-alignment="top" rotate-displacement="true">"XYZ"</TextSymbolizer>
<PointSymbolizer allow-overlap="true"/> <PointSymbolizer allow-overlap="true"/>
</Rule> </Rule>
</Style> </Style>