{ Reads a MathML Document License: The same modified LGPL as the Free Pascal RTL See the file COPYING.modifiedLGPL for more details AUTHORS: Felipe Monteiro de Carvalho } unit mathmlvectorialreader; {$mode objfpc}{$H+} interface uses Classes, SysUtils, math, xmlread, dom, fpvectorial, fpvutils; type { TvMathMLVectorialReader } TvMathMLVectorialReader = class(TvCustomVectorialReader) private FPointSeparator, FCommaSeparator: TFormatSettings; function StringToFloat(AStr: string): Single; public { General reading methods } constructor Create; override; Destructor Destroy; override; procedure ReadFromStream(AStream: TStream; AData: TvVectorialDocument); override; end; implementation { TvMathMLVectorialReader } function TvMathMLVectorialReader.StringToFloat(AStr: string): Single; begin Result := StrToInt(AStr); end; constructor TvMathMLVectorialReader.Create; begin inherited Create; FPointSeparator := DefaultFormatSettings; FPointSeparator.DecimalSeparator := '.'; FPointSeparator.ThousandSeparator := '#';// disable the thousand separator end; destructor TvMathMLVectorialReader.Destroy; begin inherited Destroy; end; procedure TvMathMLVectorialReader.ReadFromStream(AStream: TStream; AData: TvVectorialDocument); var Doc: TXMLDocument; lFirstLayer, lCurNode: TDOMNode; lPage: TvVectorialPage; begin try // Read in xml file from the stream ReadXMLFile(Doc, AStream); {// Read the properties of the tag AData.Width := StringWithUnitToFloat(Doc.DocumentElement.GetAttribute('width')); AData.Height := StringWithUnitToFloat(Doc.DocumentElement.GetAttribute('height'));} // Now process the elements inside the first layer lFirstLayer := Doc.DocumentElement.FirstChild; lCurNode := lFirstLayer.FirstChild; lPage := AData.AddPage(); lPage.Width := AData.Width; lPage.Height := AData.Height; while Assigned(lCurNode) do begin //ReadFormulaFromNode(lCurNode, lPage, AData); lCurNode := lCurNode.NextSibling; end; finally // finally, free the document Doc.Free; end; end; initialization RegisterVectorialReader(TvMathMLVectorialReader, vfMathML); end.