From fdff92b568bae87c3056623fcda99c74f5fbccaa Mon Sep 17 00:00:00 2001 From: sekelsenmat Date: Fri, 7 Feb 2014 19:55:36 +0000 Subject: [PATCH] fpvectorial: Improves ODG support for custom shape, not yet fully working git-svn-id: trunk@43942 - --- components/fpvectorial/odgvectorialreader.pas | 62 ++++++++++++++++++- 1 file changed, 59 insertions(+), 3 deletions(-) diff --git a/components/fpvectorial/odgvectorialreader.pas b/components/fpvectorial/odgvectorialreader.pas index 55e5d3fbfa..f3dc119bf4 100644 --- a/components/fpvectorial/odgvectorialreader.pas +++ b/components/fpvectorial/odgvectorialreader.pas @@ -115,6 +115,8 @@ type TCustomShapeInfo = packed record Width, Height: Double; // in milimiters ViewBox_Left, ViewBox_Top, ViewBox_Width, ViewBox_Height: Double; // unitless + VariableNames: array of string; + VariableValues: array of Double; end; { TvODGVectorialReader } @@ -687,16 +689,23 @@ end; procedure TvODGVectorialReader.ReadEnhancedGeometryNodeToTPath(ANode: TDOMNode; AData: TvVectorialPage; ADest: TPath; ADeltaX, ADeltaY: Double; var AInfo: TCustomShapeInfo); var - i: Integer; - lNodeName, lNodeValue: string; + i, Len: Integer; + lNodeName, lNodeValue, lAttrName, lAttrValue: string; l10Strings: T10Strings; + lCurNode: TDOMNode; begin + // Initial values to avoid invalid initial ones + AInfo.ViewBox_Left := 0; + AInfo.ViewBox_Top := 0; + AInfo.ViewBox_Width := 10000; + AInfo.ViewBox_Height := 10000; + // First of all we need the viewBox, or else we can't map the coordinates for i := 0 to ANode.Attributes.Length - 1 do begin lNodeName := ANode.Attributes.Item[i].NodeName; lNodeValue := ANode.Attributes.Item[i].NodeValue; - if lNodeName = 'draw:viewBox' then + if (lNodeName = 'draw:viewBox') or (lNodeName = 'svg:viewBox') then begin // From OpenDocument 1.1 specs page 300 // The syntax for using this attribute is the same as the [SVG] syntax. @@ -711,6 +720,53 @@ begin end; end; + // Read child elements + lCurNode := ANode.FirstChild; + while lCurNode <> nil do + begin + lNodeName := lCurNode.NodeName; + + case lNodeName of + // Read variables + // + // + 'draw:equation': + begin + for i := 0 to lCurNode.Attributes.Length - 1 do + begin + lAttrName := lCurNode.Attributes.Item[i].NodeName; + lAttrValue := lCurNode.Attributes.Item[i].NodeValue; + + if (lAttrName = 'draw:name') then + begin + Len := Length(AInfo.VariableNames); + SetLength(AInfo.VariableNames, Len+1); + AInfo.VariableNames[Len] := lAttrValue; + end + else if (lAttrName = 'draw:formula') then + begin + Len := Length(AInfo.VariableValues); + SetLength(AInfo.VariableValues, Len+1); + // ToDo: Implement a real formula calculation + lAttrValue := StringReplace(lAttrValue, '$0', '0', [rfReplaceAll, rfIgnoreCase]); + lAttrValue := StringReplace(lAttrValue, '-0', '', [rfReplaceAll, rfIgnoreCase]); + + AInfo.VariableValues[Len] := StrToFloat(lAttrValue); + end; + end; + end; + // + 'draw:handle': + begin + + end; + end; + + lCurNode := lCurNode.NextSibling; + end; + + // read the attributes for i := 0 to ANode.Attributes.Length - 1 do begin