diff --git a/components/fpvectorial/fpvectorial.pas b/components/fpvectorial/fpvectorial.pas index 8ad9465932..c90d445ebf 100644 --- a/components/fpvectorial/fpvectorial.pas +++ b/components/fpvectorial/fpvectorial.pas @@ -5016,23 +5016,22 @@ procedure TvVectorialDocument.AddStandardTextDocumentStyles; var lCurStyle: TvStyle; begin + lCurStyle := AddStyle(); lCurStyle.Name := 'Text Body'; lCurStyle.Font.Size := 12; lCurStyle.Font.Name := 'Times New Roman'; + lCurStyle.SetElements := [spbfFontSize, spbfFontName]; lCurStyle.MarginTop := 0; lCurStyle.MarginBottom := 2.12; - lCurStyle.SetElements := [spbfFontSize, spbfFontName]; lCurStyle := AddStyle(); lCurStyle.Name := 'Heading 1'; lCurStyle.Font.Size := 16; lCurStyle.Font.Name := 'Arial'; lCurStyle.Font.Bold := True; - lCurStyle.MarginTop := 4.23; - lCurStyle.MarginBottom := 2.12; - lCurStyle.MarginTop := 4.23; - lCurStyle.MarginBottom := 2.12; lCurStyle.SetElements := [spbfFontSize, spbfFontName, spbfFontBold, spbfFontItalic]; + lCurStyle.MarginTop := 4.23; + lCurStyle.MarginBottom := 2.12; lCurStyle := AddStyle(); lCurStyle.Name := 'Heading 2'; @@ -5041,6 +5040,8 @@ begin lCurStyle.Font.Bold := True; lCurStyle.Font.Italic := True; lCurStyle.SetElements := [spbfFontSize, spbfFontName, spbfFontBold, spbfFontItalic]; + lCurStyle.MarginTop := 4.23; + lCurStyle.MarginBottom := 2.12; end; function TvVectorialDocument.GetStyleCount: Integer; diff --git a/components/fpvectorial/odtvectorialwriter.pas b/components/fpvectorial/odtvectorialwriter.pas index 76fd89ba2a..237dca88f0 100644 --- a/components/fpvectorial/odtvectorialwriter.pas +++ b/components/fpvectorial/odtvectorialwriter.pas @@ -62,12 +62,15 @@ type // Strings with the contents of files FMeta, FSettings, FStyles, FContent, FMimetype: string; FMetaInfManifest: string; + // helper routines + function StyleNameToODTStyleName(AData: TvVectorialDocument; AStyleIndex: Integer; AToContentAutoStyle: Boolean): string; + function FloatToODTText(AFloat: Double): string; // Routines to write those files procedure WriteMimetype; procedure WriteMetaInfManifest; procedure WriteMeta; procedure WriteSettings; - procedure WriteStyles; + procedure WriteStyles(AData: TvVectorialDocument); procedure WriteDocument(AData: TvVectorialDocument); procedure WritePage(ACurPage: TvTextPageSequence); // Routines to write parts of those files @@ -148,6 +151,27 @@ const FLOAT_MILIMETERS_PER_PIXEL = 0.2822; // DPI 90 = 1 / 90 inches per pixel FLOAT_PIXELS_PER_MILIMETER = 3.5433; // DPI 90 = 1 / 90 inches per pixel +function TvODTVectorialWriter.StyleNameToODTStyleName( + AData: TvVectorialDocument; AStyleIndex: Integer; AToContentAutoStyle: Boolean): string; +var + lStyle: TvStyle; +begin + lStyle := AData.GetStyle(AStyleIndex); + if AToContentAutoStyle then + begin + Result := 'P' + IntToStr(AStyleIndex); + end + else + begin + Result := StringReplace(lStyle.Name, ' ', '_', [rfReplaceAll, rfIgnoreCase]); + end; +end; + +function TvODTVectorialWriter.FloatToODTText(AFloat: Double): string; +begin + Result := FloatToStr(AFloat, FPointSeparator); +end; + procedure TvODTVectorialWriter.WriteMimetype; begin FMimetype := 'application/vnd.oasis.opendocument.text'; @@ -308,45 +332,53 @@ begin ''; end; -procedure TvODTVectorialWriter.WriteStyles; +procedure TvODTVectorialWriter.WriteStyles(AData: TvVectorialDocument); +var + i: Integer; + CurStyle: TvStyle; + lTextPropsStr, lParagraphPropsStr, lCurStyleTmpStr: string; begin FStyles := XML_HEADER + LineEnding + '' + LineEnding + -{ -xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" -xmlns:xlink="http://www.w3.org/1999/xlink" -xmlns:dc="http://purl.org/dc/elements/1.1/" -xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" -xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" -xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" -xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" -xmlns:math="http://www.w3.org/1998/Math/MathML" -xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" -xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" -xmlns:ooo="http://openoffice.org/2004/office" -xmlns:ooow="http://openoffice.org/2004/writer" -xmlns:oooc="http://openoffice.org/2004/calc" -xmlns:dom="http://www.w3.org/2001/xml-events" -xmlns:rpt="http://openoffice.org/2005/report" -xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" -xmlns:xhtml="http://www.w3.org/1999/xhtml" -xmlns:grddl="http://www.w3.org/2003/g/data-view#" -xmlns:officeooo="http://openoffice.org/2009/office" -xmlns:tableooo="http://openoffice.org/2009/table" -xmlns:drawooo="http://openoffice.org/2010/draw" -xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0" -xmlns:css3t="http://www.w3.org/TR/css3-text/" office:version="1.2">} + ' xmlns:table="' + SCHEMAS_XMLNS_TABLE + '"' + + ' xmlns:draw="' + SCHEMAS_XMLNS_DRAW + '"' + + ' xmlns:fo="' + SCHEMAS_XMLNS_FO + '"' + + ' xmlns:xlink="' + SCHEMAS_XMLNS_XLINK + '"' + + ' xmlns:dc="' + SCHEMAS_XMLNS_DC + '"' + + ' xmlns:meta="' + SCHEMAS_XMLNS_META + '"' + + ' xmlns:number="' + SCHEMAS_XMLNS_NUMBER + '"' + + ' xmlns:svg="' + SCHEMAS_XMLNS_SVG + '"' + + ' xmlns:chart="' + SCHEMAS_XMLNS_CHART + '"' + + ' xmlns:dr3d="' + SCHEMAS_XMLNS_DR3D + '"' + + ' xmlns:math="' + SCHEMAS_XMLNS_MATH + '"' + + ' xmlns:form="' + SCHEMAS_XMLNS_FORM + '"' + + ' xmlns:script="' + SCHEMAS_XMLNS_SCRIPT + '"' + + ' xmlns:ooo="' + SCHEMAS_XMLNS_OOO + '"' + + ' xmlns:ooow="' + SCHEMAS_XMLNS_OOOW + '"' + + ' xmlns:oooc="' + SCHEMAS_XMLNS_OOOC + '"' + + ' xmlns:dom="' + SCHEMAS_XMLNS_DOM + '"' + + ' xmlns:rpt="' + SCHEMAS_XMLNS_RPT + '"' + + ' xmlns:of="' + SCHEMAS_XMLNS_OF + '"' + + ' xmlns:xhtml="' + SCHEMAS_XMLNS_XHTML + '"' + + ' xmlns:grddl="' + SCHEMAS_XMLNS_GRDDL + '"' + + ' xmlns:officeooo="' + SCHEMAS_XMLNS_OFFICEOOO + '"' + + ' xmlns:tableooo="' + SCHEMAS_XMLNS_TABLEOOO + '"' + + ' xmlns:drawooo="' + SCHEMAS_XMLNS_DRAWOOO + '"' + + ' xmlns:calcext="' + SCHEMAS_XMLNS_CALCEXT + '"' + + ' xmlns:css3t="' + SCHEMAS_XMLNS_CSS3T + '"' + + ' office:version="1.2">' + LineEnding; + FStyles := FStyles + '' + LineEnding + - ' ' + LineEnding + + ' ' + LineEnding + + ' ' + LineEnding + ' ' + LineEnding + + ' ' + LineEnding + + ' ' + LineEnding + + ' ' + LineEnding + + ' ' + LineEnding + '' + LineEnding + // up to here done +/- @@ -374,10 +406,11 @@ xmlns:css3t="http://www.w3.org/TR/css3-text/" office:version="1.2">} ' ' + LineEnding + ' ' + LineEnding + ' ' + LineEnding + - '' + LineEnding + - ''; -{ - + '' + LineEnding; + + FStyles := FStyles + + '' + LineEnding; + { @@ -395,14 +428,54 @@ xmlns:css3t="http://www.w3.org/TR/css3-text/" office:version="1.2">} - + } + + FStyles := FStyles + + ' ' + LineEnding; + + for i := 0 to AData.GetStyleCount() - 1 do + begin + lTextPropsStr := ''; + lParagraphPropsStr := ''; + CurStyle := AData.GetStyle(i); + + if spbfFontSize in CurStyle.SetElements then + begin + lTextPropsStr := lTextPropsStr + ' fo:font-size="'+IntToStr(CurStyle.Font.Size)+'pt" '; + lTextPropsStr := lTextPropsStr + ' fo:font-size-asian="'+IntToStr(CurStyle.Font.Size)+'pt" '; + lTextPropsStr := lTextPropsStr + ' fo:font-size-complex="'+IntToStr(CurStyle.Font.Size)+'pt" '; + end; + if spbfFontName in CurStyle.SetElements then + begin + lTextPropsStr := lTextPropsStr + ' style:font-name="'+CurStyle.Font.Name+'" '; + lTextPropsStr := lTextPropsStr + ' style:font-name-asian="Microsoft YaHei" '; + lTextPropsStr := lTextPropsStr + ' style:font-name-complex="Mangal" '; + end; + if (spbfFontBold in CurStyle.SetElements) and CurStyle.Font.Bold then + begin + lTextPropsStr := lTextPropsStr + ' fo:font-weight="bold" '; + lTextPropsStr := lTextPropsStr + ' style:font-weight-asian="bold" '; + lTextPropsStr := lTextPropsStr + ' style:font-weight-complex="bold" '; + end; + if (spbfFontItalic in CurStyle.SetElements) and CurStyle.Font.Italic then + begin + lTextPropsStr := lTextPropsStr + ' fo:font-style="italic" '; + lTextPropsStr := lTextPropsStr + ' style:font-style-asian="italic" '; + lTextPropsStr := lTextPropsStr + ' style:font-style-complex="italic" '; + end; + + lCurStyleTmpStr := // tmp string to help see the text in the debugger + ' ' + LineEnding + + ' ' + LineEnding + + ' ' + LineEnding + + ' ' + LineEnding; + FStyles := FStyles + lCurStyleTmpStr; + +{ - - - @@ -426,6 +499,10 @@ xmlns:css3t="http://www.w3.org/TR/css3-text/" office:version="1.2">} +} + end; + +{ @@ -497,8 +574,9 @@ xmlns:css3t="http://www.w3.org/TR/css3-text/" office:version="1.2">} - } + FStyles := FStyles + + ''; end; procedure TvODTVectorialWriter.WriteDocument(AData: TvVectorialDocument); @@ -751,7 +829,7 @@ begin WriteMetaInfManifest(); WriteMeta(); WriteSettings(); - WriteStyles(); + WriteStyles(AData); WriteDocument(AData); { Write the data to streams }