From 74776f467779da71fc45a09f7a1868f21b57f2ea Mon Sep 17 00:00:00 2001 From: sekelsenmat Date: Tue, 19 May 2015 15:20:47 +0000 Subject: [PATCH] fpvectorial: Fixes multiline table row, fixes crash in html with images, fixes style of table header git-svn-id: trunk@49103 - --- components/fpvectorial/fpvectorial.pas | 21 ++++++-- .../fpvectorial/htmlvectorialreader.pas | 50 ++++++++++--------- components/fpvectorial/svgvectorialreader.pas | 4 +- 3 files changed, 45 insertions(+), 30 deletions(-) diff --git a/components/fpvectorial/fpvectorial.pas b/components/fpvectorial/fpvectorial.pas index ef3f63bb6b..2141c445da 100644 --- a/components/fpvectorial/fpvectorial.pas +++ b/components/fpvectorial/fpvectorial.pas @@ -1301,8 +1301,8 @@ type // List of common styles, for conveniently finding them StyleTextBody, StyleHeading1, StyleHeading2, StyleHeading3, StyleHeading4, StyleHeading5, StyleHeading6: TvStyle; - StyleTextBodyCentralized, StyleHeading1Centralized, - StyleHeading2Centralized, StyleHeading3Centralized: TvStyle; + StyleTextBodyCentralized, StyleTextBodyBold: TvStyle; // text body modifications + StyleHeading1Centralized, StyleHeading2Centralized, StyleHeading3Centralized: TvStyle; // heading modifications StyleBulletList, StyleNumberList : TvListStyle; StyleTextSpanBold, StyleTextSpanItalic, StyleTextSpanUnderline: TvStyle; { Base methods } @@ -1529,6 +1529,7 @@ type protected FFilename: string; class function GetTextContentsFromNode(ANode: TDOMNode): DOMString; + class function RemoveLineEndingsAndTrim(AStr: string): string; public { General reading methods } constructor Create; virtual; @@ -4244,7 +4245,7 @@ var lTextWidth: Integer; {$endif} begin - //lText := Value.Text; // for debugging + lText := Value.Text + Format(' F=%d', [ADest.Font.Size]); // for debugging inherited Render(ADest, ARenderInfo, ADestX, ADestY, AMulX, AMulY, ADoDraw); InitializeRenderInfo(ARenderInfo); @@ -4285,6 +4286,7 @@ begin Render_NextText_X := CoordToCanvasX(X)+XAnchorAdjustment; if ADoDraw then ADest.TextOut(Render_NextText_X, Round(LowerDim.Y), lText); + //lText := lText + Format(' F=%d', [ADest.Font.Size]); // for debugging CalcEntityCanvasMinMaxXY(ARenderInfo, Render_NextText_X, Round(LowerDim.Y)); lTextSize := ACanvas.TextExtent(lText); @@ -8343,6 +8345,12 @@ begin StyleTextBodyCentralized.Alignment := vsaCenter; StyleTextBodyCentralized.SetElements := StyleTextBodyCentralized.SetElements + [spbfAlignment]; + StyleTextBodyBold := AddStyle(); + StyleTextBodyBold.ApplyOver(StyleTextBody); + StyleTextBodyBold.Name := 'Text Body Bold'; + StyleTextBodyBold.Font.Bold := True; + StyleTextBodyBold.SetElements := StyleTextBodyCentralized.SetElements + [spbfFontBold]; + StyleHeading1Centralized := AddStyle(); StyleHeading1Centralized.ApplyOver(StyleHeading1); StyleHeading1Centralized.Name := 'Heading 1 Centered'; @@ -8530,6 +8538,13 @@ begin end; end; +class function TvCustomVectorialReader.RemoveLineEndingsAndTrim(AStr: string): string; +begin + Result := Trim(AStr); + Result := StringReplace(Result, #13, '', [rfReplaceAll]); + Result := StringReplace(Result, #10, '', [rfReplaceAll]); +end; + constructor TvCustomVectorialReader.Create; begin inherited Create; diff --git a/components/fpvectorial/htmlvectorialreader.pas b/components/fpvectorial/htmlvectorialreader.pas index d80c4040e8..a9f04e9550 100644 --- a/components/fpvectorial/htmlvectorialreader.pas +++ b/components/fpvectorial/htmlvectorialreader.pas @@ -133,8 +133,7 @@ procedure TvHTMLVectorialReader.ReadParagraphFromNode(ADest: TvParagraph; ANode: AData: TvTextPageSequence; ADoc: TvVectorialDocument); var lText: TvText = nil; - lTextSeparatedByBR: Boolean = False; - lTextStr: string; + lTextStr: string = ''; lCurNode: TDOMNode; lNodeName, lNodeValue, lAttrName, lAttrValue: DOMString; lCurAttr: TDOMNode; @@ -150,6 +149,19 @@ var lImageData: array of Byte; lImageDataStream: TMemoryStream; lImageReader: TFPCustomImageReader; + + procedure TextMerging(); + begin + if lTextStr <> '' then + begin + if lText = nil then + lText := ADest.AddText(lTextStr) + else + lText.Value.Add(lTextStr); + lTextStr := ''; + end; + end; + begin ADest.Style := ADoc.StyleTextBody; @@ -159,31 +171,18 @@ begin lNodeName := LowerCase(lCurNode.NodeName); lNodeValue := lCurNode.NodeValue; - if (lCurNode is TDOMText) and not lTextSeparatedByBR then + if (lCurNode is TDOMText) then begin - lTextStr := lNodeValue; - lText := ADest.AddText(lTextStr); - lCurNode := lCurNode.NextSibling; - Continue; - end - // If after a text we get a
or a TDOMText, merge them - else if (lNodeName = 'br') and (lText <> nil) then - begin - lTextSeparatedByBR := True; - lCurNode := lCurNode.NextSibling; - Continue; - end - else if (lCurNode is TDOMText) and lTextSeparatedByBR then - begin - lTextStr := lNodeValue; - lText.Value.Add(lTextStr); + lTextStr += RemoveLineEndingsAndTrim(lNodeValue); lCurNode := lCurNode.NextSibling; Continue; end; + // text merging + TextMerging(); // reset text merging - lText := nil; - lTextSeparatedByBR := False; + if lNodeName <> 'br' then + lText := nil; case lNodeName of // @@ -198,8 +197,9 @@ begin for i := 0 to lCurNode.Attributes.Length - 1 do begin - lAttrName := lCurNode.Attributes.Item[i].NodeName; - lAttrValue := lCurNode.Attributes.Item[i].NodeValue; + lCurAttr := lCurNode.Attributes.Item[i]; + lAttrName := lCurAttr.NodeName; + lAttrValue := lCurAttr.NodeValue; case lAttrName of 'alt': @@ -284,6 +284,8 @@ begin lCurNode := lCurNode.NextSibling; end; + + TextMerging(); end; function TvHTMLVectorialReader.ReadSVGFromNode(ANode: TDOMNode; @@ -443,7 +445,7 @@ begin begin CurCell := CurRow.AddCell(); CurCellPara := CurCell.AddParagraph(); - CurCellPara.Style := ADoc.StyleTextSpanBold; + CurCellPara.Style := ADoc.StyleTextBodyBold; CurCellPara.AddText(GetTextContentFromNode(lCurNode)); end; 'td': diff --git a/components/fpvectorial/svgvectorialreader.pas b/components/fpvectorial/svgvectorialreader.pas index c784b718a1..483195ed3d 100644 --- a/components/fpvectorial/svgvectorialreader.pas +++ b/components/fpvectorial/svgvectorialreader.pas @@ -2647,9 +2647,7 @@ var else if lNodeName = 'textpath' then begin lTextStr := GetTextContentFromNode(lCurNode); - lTextStr := StringReplace(lTextStr, #13#10, '', [rfReplaceAll]); - lTextStr := StringReplace(lTextStr, #13, '', [rfReplaceAll]); - lTextStr := StringReplace(lTextStr, #10, '', [rfReplaceAll]); + lTextStr := RemoveLineEndingsAndTrim(lTextStr); lTextStr := Trim(lTextStr); lCText := lParagraph.AddCurvedText(lTextStr);