1 --- filter/source/svg/gfxtypes.hxx.old2 2008-10-21 18:47:16.000000000 +0200
2 +++ filter/source/svg/gfxtypes.hxx 2008-10-21 17:57:49.000000000 +0200
25 maFontFamily(), // app-default
27 - meFontStyle(STYLE_NORMAL),
28 - meFontVariant(VARIANT_NORMAL),
29 + maFontStyle(RTL_CONSTASCII_USTRINGPARAM("normal")),
30 + maFontVariant(RTL_CONSTASCII_USTRINGPARAM("normal")),
33 meTextDisplayAlign(BEFORE),
38 - FontStyle meFontStyle;
39 - FontVariant meFontVariant;
40 + rtl::OUString maFontStyle;
41 + rtl::OUString maFontVariant;
44 TextAlign meTextAnchor; // text-anchor
46 rLHS.maViewBox==rRHS.maViewBox &&
47 rLHS.maFontFamily==rRHS.maFontFamily &&
48 rLHS.mnFontSize==rRHS.mnFontSize &&
49 - rLHS.meFontStyle==rRHS.meFontStyle &&
50 - rLHS.meFontVariant==rRHS.meFontVariant &&
51 + rLHS.maFontStyle==rRHS.maFontStyle &&
52 + rLHS.maFontVariant==rRHS.maFontVariant &&
53 rLHS.mnFontWeight==rRHS.mnFontWeight &&
54 rLHS.meTextAnchor==rRHS.meTextAnchor &&
55 rLHS.meTextDisplayAlign==rRHS.meTextDisplayAlign &&
57 ^ size_t(rState.maViewBox.getHeight())
58 ^ size_t(rState.maFontFamily.hashCode())
59 ^ size_t(rState.mnFontSize)
60 - ^ size_t(rState.meFontStyle)
61 - ^ size_t(rState.meFontVariant)
62 + ^ size_t(rState.maFontStyle.hashCode())
63 + ^ size_t(rState.maFontVariant.hashCode())
64 ^ size_t(rState.mnFontWeight)
65 ^ size_t(rState.meTextAnchor)
66 ^ size_t(rState.meTextDisplayAlign)
67 --- filter/source/svg/svgreader.cxx.old2 2008-10-21 16:36:18.000000000 +0200
68 +++ filter/source/svg/svgreader.cxx 2008-10-21 18:40:22.000000000 +0200
70 return aBuf.makeStringAndClear();
73 + rtl::OUString getOdfAlign( TextAlign eAlign )
75 + static ::rtl::OUString aStart(USTR("start"));
76 + static ::rtl::OUString aEnd(USTR("end"));
77 + // static ::rtl::OUString aJustify(USTR("justify"));
78 + static ::rtl::OUString aCenter(USTR("center"));
91 bool writeStyle(State& rState, const sal_Int32 nTagId)
93 rtl::Reference<SvXMLAttributeList> xAttrs( new SvXMLAttributeList() );
95 // do we have a gradient fill? then write out gradient as well
96 if( rState.meFillType == GRADIENT && rState.maFillGradient.maStops.size() > 1 )
98 - // TODO(F3): ODF12 supposedly also groks svg:linear/radialGradient
99 + // TODO(F3): ODF12 supposedly also groks svg:linear/radialGradient. But CL says: nope.
100 xAttrs->AddAttribute( USTR( "draw:name" ), getStyleName("svggradient", rState.maFillGradient.mnId) );
101 if( rState.maFillGradient.meType == Gradient::LINEAR )
106 // serialize to automatic-style section
107 + if( nTagId == XML_TEXT )
109 + // write paragraph style attributes
112 + xAttrs->AddAttribute( USTR( "style:name" ), getStyleName("svgparagraphstyle", mnCurrStateId) );
113 + xAttrs->AddAttribute( USTR( "style:family" ), USTR("paragraph") );
114 + mxDocumentHandler->startElement( USTR("style:style"),
118 + xAttrs->AddAttribute( USTR( "fo:text-align"), getOdfAlign(rState.meTextAnchor));
120 + mxDocumentHandler->startElement( USTR("style:paragraph-properties"),
122 + mxDocumentHandler->endElement( USTR("style:paragraph-properties") );
123 + mxDocumentHandler->endElement( USTR("style:style") );
125 + // write text style attributes
128 + xAttrs->AddAttribute( USTR( "style:name" ), getStyleName("svgtextstyle", mnCurrStateId) );
129 + xAttrs->AddAttribute( USTR( "style:family" ), USTR("text") );
130 + mxDocumentHandler->startElement( USTR("style:style"),
133 + xAttrs->AddAttribute( USTR( "fo:font-family"), rState.maFontFamily);
134 + xAttrs->AddAttribute( USTR( "fo:font-size"),
135 + rtl::OUString::valueOf(pt2mm(rState.mnFontSize))+USTR("mm"));
136 + xAttrs->AddAttribute( USTR( "fo:font-style"), rState.maFontStyle);
137 + xAttrs->AddAttribute( USTR( "fo:font-variant"), rState.maFontVariant);
138 + xAttrs->AddAttribute( USTR( "fo:font-weight"),
139 + rtl::OUString::valueOf(rState.mnFontWeight));
140 + xAttrs->AddAttribute( USTR( "fo:color"), getOdfColor(rState.maFillColor));
142 + mxDocumentHandler->startElement( USTR("style:text-properties"),
144 + mxDocumentHandler->endElement( USTR("style:text-properties") );
145 + mxDocumentHandler->endElement( USTR("style:style") );
149 xAttrs->AddAttribute( USTR( "style:name" ), getStyleName("svggraphicstyle", mnCurrStateId) );
150 xAttrs->AddAttribute( USTR( "style:family" ), USTR("graphic") );
151 @@ -928,13 +987,16 @@
152 maCurrState.mnFontSize=convLength(sValue,maCurrState,'v');
155 - maCurrState.meFontStyle=STYLE_ITALIC; // TODO: sValue.toStyleId();
156 + parseFontStyle(maCurrState,sValue,aValueUtf8.getStr());
158 case XML_FONT_WEIGHT:
159 maCurrState.mnFontWeight=sValue.toDouble();
161 case XML_FONT_VARIANT:
162 - maCurrState.meFontVariant=VARIANT_SMALLCAPS; // TODO: sValue.toDouble();
163 + parseFontVariant(maCurrState,sValue,aValueUtf8.getStr());
165 + case XML_TEXT_ANCHOR:
166 + parseTextAlign(maCurrState,aValueUtf8.getStr());
169 if( maGradientVector.empty() ||
170 @@ -987,6 +1049,34 @@
171 while( nIndex != -1 );
174 + void parseFontStyle( State& io_rInitialState,
175 + const rtl::OUString& rValue,
176 + const char* sValue )
178 + if( strcmp(sValue,"inherit") != 0 )
179 + io_rInitialState.maFontStyle = rValue;
182 + void parseFontVariant( State& io_rInitialState,
183 + const rtl::OUString& rValue,
184 + const char* sValue )
186 + if( strcmp(sValue,"inherit") != 0 )
187 + io_rInitialState.maFontVariant = rValue;
190 + void parseTextAlign( State& io_rInitialState,
191 + const char* sValue )
193 + if( strcmp(sValue,"start") == 0 )
194 + io_rInitialState.meTextAnchor = BEFORE;
195 + else if( strcmp(sValue,"middle") == 0 )
196 + io_rInitialState.meTextAnchor = CENTER;
197 + else if( strcmp(sValue,"end") == 0 )
198 + io_rInitialState.meTextAnchor = AFTER;
199 + // keep current val for sValue == "inherit"
202 void parsePaint( const rtl::OUString& rValue,
205 @@ -1391,6 +1481,10 @@
206 // actually export text
209 + // some heuristic attempts to have text output
210 + // baseline-relative
211 + y -= 2.0*maCurrState.mnFontSize/3.0;
213 // extract basic transformations out of CTM
214 basegfx::B2DTuple aScale, aTranslate;
215 double fRotate, fShearX;
216 @@ -1423,9 +1517,16 @@
219 mxDocumentHandler->startElement(USTR("draw:text-box"),xUnoAttrs);
220 - // TODO: put text style in here
221 + xAttrs->AddAttribute( USTR( "text:style-name" ), USTR("svgparagraphstyle")+sStyleId);
222 mxDocumentHandler->startElement(USTR("text:p"),xUnoAttrs);
225 + xAttrs->AddAttribute( USTR( "text:style-name" ), USTR("svgtextstyle")+sStyleId);
226 + mxDocumentHandler->startElement(USTR("text:span"),xUnoAttrs);
229 mxDocumentHandler->characters(sText.makeStringAndClear());
230 + mxDocumentHandler->endElement(USTR("text:span"));
231 mxDocumentHandler->endElement(USTR("text:p"));
232 mxDocumentHandler->endElement(USTR("draw:text-box"));
233 mxDocumentHandler->endElement(USTR("draw:frame"));
234 @@ -2292,6 +2393,14 @@
235 Font aFont(maCurrState.maFontFamily,
237 basegfx::fround(pt100thmm(maCurrState.mnFontSize))));
238 + aFont.SetAlign(ALIGN_BASELINE);
239 + aFont.SetColor(getVclColor(maCurrState.maFillColor));
240 + aFont.SetFillColor(getVclColor(maCurrState.maFillColor));
242 + if( !maCurrState.maFontStyle.equalsAscii("normal") )
243 + aFont.SetItalic(ITALIC_NORMAL); // TODO: discriminate
244 + if( !maCurrState.mnFontWeight != 400.0 )
245 + aFont.SetWeight(WEIGHT_BOLD); // TODO: discriminate
247 // extract basic transformations out of CTM
248 basegfx::B2DTuple aScale, aTranslate;
249 @@ -2313,9 +2422,27 @@
251 // TODO(F2): update bounds
252 mrOutDev.SetFont(aFont);
253 + const ::rtl::OUString aText( sText.makeStringAndClear() );
254 + switch( maCurrState.meTextAnchor )
262 + const long nWidth=mrOutDev.GetTextWidth(aText);
268 + x -= mrOutDev.GetTextWidth(aText);
271 mrOutDev.DrawText(Point(basegfx::fround(pt100thmm(x)),
272 basegfx::fround(pt100thmm(y))),
273 - sText.makeStringAndClear());
278 @@ -2585,6 +2712,7 @@
280 aVDev.EnableOutput( FALSE );
281 aMtf.Record( &aVDev );
282 + aVDev.SetTextAlign(ALIGN_BASELINE);
284 // parse styles and fill state stack
285 svgi::State aInitialState;