update dev300-m58
[ooovba.git] / applied_patches / 0391-svg-import-textimport.diff
blob9bd37ee14e92cc008f9d7d834c15bc61751feefb
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
3 @@ -155,19 +155,6 @@
4 ROUND
5 };
7 -enum FontStyle
8 -{
9 - STYLE_NORMAL,
10 - STYLE_OBLIQUE,
11 - STYLE_ITALIC
12 -};
14 -enum FontVariant
16 - VARIANT_NORMAL,
17 - VARIANT_SMALLCAPS
18 -};
20 struct State
22 State() :
23 @@ -177,8 +164,8 @@
24 maViewBox(),
25 maFontFamily(), // app-default
26 mnFontSize(12.0),
27 - meFontStyle(STYLE_NORMAL),
28 - meFontVariant(VARIANT_NORMAL),
29 + maFontStyle(RTL_CONSTASCII_USTRINGPARAM("normal")),
30 + maFontVariant(RTL_CONSTASCII_USTRINGPARAM("normal")),
31 mnFontWeight(400.0),
32 meTextAnchor(BEFORE),
33 meTextDisplayAlign(BEFORE),
34 @@ -220,8 +207,8 @@
37 double mnFontSize;
38 - FontStyle meFontStyle;
39 - FontVariant meFontVariant;
40 + rtl::OUString maFontStyle;
41 + rtl::OUString maFontVariant;
42 double mnFontWeight;
44 TextAlign meTextAnchor; // text-anchor
45 @@ -265,8 +252,8 @@
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 &&
56 @@ -310,8 +297,8 @@
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
69 @@ -415,6 +415,24 @@
70 return aBuf.makeStringAndClear();
73 + rtl::OUString getOdfAlign( TextAlign eAlign )
74 + {
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"));
79 + switch(eAlign)
80 + {
81 + default:
82 + case BEFORE:
83 + return aStart;
84 + case CENTER:
85 + return aCenter;
86 + case AFTER:
87 + return aEnd;
88 + }
89 + }
91 bool writeStyle(State& rState, const sal_Int32 nTagId)
93 rtl::Reference<SvXMLAttributeList> xAttrs( new SvXMLAttributeList() );
94 @@ -443,7 +461,7 @@
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 )
103 @@ -515,6 +533,47 @@
106 // serialize to automatic-style section
107 + if( nTagId == XML_TEXT )
109 + // write paragraph style attributes
110 + xAttrs->Clear();
112 + xAttrs->AddAttribute( USTR( "style:name" ), getStyleName("svgparagraphstyle", mnCurrStateId) );
113 + xAttrs->AddAttribute( USTR( "style:family" ), USTR("paragraph") );
114 + mxDocumentHandler->startElement( USTR("style:style"),
115 + xUnoAttrs );
117 + xAttrs->Clear();
118 + xAttrs->AddAttribute( USTR( "fo:text-align"), getOdfAlign(rState.meTextAnchor));
120 + mxDocumentHandler->startElement( USTR("style:paragraph-properties"),
121 + xUnoAttrs );
122 + mxDocumentHandler->endElement( USTR("style:paragraph-properties") );
123 + mxDocumentHandler->endElement( USTR("style:style") );
125 + // write text style attributes
126 + xAttrs->Clear();
128 + xAttrs->AddAttribute( USTR( "style:name" ), getStyleName("svgtextstyle", mnCurrStateId) );
129 + xAttrs->AddAttribute( USTR( "style:family" ), USTR("text") );
130 + mxDocumentHandler->startElement( USTR("style:style"),
131 + xUnoAttrs );
132 + xAttrs->Clear();
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"),
143 + xUnoAttrs );
144 + mxDocumentHandler->endElement( USTR("style:text-properties") );
145 + mxDocumentHandler->endElement( USTR("style:style") );
148 xAttrs->Clear();
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');
153 break;
154 case XML_FONT_STYLE:
155 - maCurrState.meFontStyle=STYLE_ITALIC; // TODO: sValue.toStyleId();
156 + parseFontStyle(maCurrState,sValue,aValueUtf8.getStr());
157 break;
158 case XML_FONT_WEIGHT:
159 maCurrState.mnFontWeight=sValue.toDouble();
160 break;
161 case XML_FONT_VARIANT:
162 - maCurrState.meFontVariant=VARIANT_SMALLCAPS; // TODO: sValue.toDouble();
163 + parseFontVariant(maCurrState,sValue,aValueUtf8.getStr());
164 + break;
165 + case XML_TEXT_ANCHOR:
166 + parseTextAlign(maCurrState,aValueUtf8.getStr());
167 break;
168 case XML_STOP_COLOR:
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,
203 const char* sValue,
204 PaintType& rType,
205 @@ -1391,6 +1481,10 @@
206 // actually export text
207 xAttrs->Clear();
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 @@
218 xAttrs->Clear();
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);
224 + xAttrs->Clear();
225 + xAttrs->AddAttribute( USTR( "text:style-name" ), USTR("svgtextstyle")+sStyleId);
226 + mxDocumentHandler->startElement(USTR("text:span"),xUnoAttrs);
228 + xAttrs->Clear();
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,
236 Size(0,
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 )
256 + default:
257 + case BEFORE:
258 + break;
260 + case CENTER:
262 + const long nWidth=mrOutDev.GetTextWidth(aText);
263 + x -= nWidth/2;
265 + break;
267 + case AFTER:
268 + x -= mrOutDev.GetTextWidth(aText);
269 + break;
271 mrOutDev.DrawText(Point(basegfx::fround(pt100thmm(x)),
272 basegfx::fround(pt100thmm(y))),
273 - sText.makeStringAndClear());
274 + aText);
275 break;
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;