diff --git a/.gitignore b/.gitignore deleted file mode 100644 index a7aeee8..0000000 --- a/.gitignore +++ /dev/null @@ -1,33 +0,0 @@ -#ignorar miniaturas creadas por windows -Thumbs.db -#Ignorar archivos construidos por Visual Studio -*.obj -*.exe -*.pdb -*.user -*.aps -*.pch -*.vspscc -*_i.c -*_p.c -*.ncb -*.suo -*.tlb -*.tlh -*.bak -*.cache -*.ilk -*.log -[Bb]in -[Dd]ebug*/ -*.lib -*.sbr -obj/ -[Rr]elease*/ -_ReSharper*/ -*.userprefs -*.nupkg - -.vs -PDFTests -Doc \ No newline at end of file diff --git a/LICENSE.txt b/LICENSE.txt deleted file mode 100644 index 20f6367..0000000 --- a/LICENSE.txt +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2016-2019 Valeriano Alfonso Rodriguez - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md deleted file mode 100644 index a297b9c..0000000 --- a/README.md +++ /dev/null @@ -1,53 +0,0 @@ -# .Net library and tool to work with PDF files - -## Usage - -### VAR.PdfTools -Add the resulting assembly as reference in your projects, and this line on code: - -```csharp -using VAR.PdfTools; -``` - -Then extract the contents of a data column using: - -```csharp -var columnData = new List(); -PdfDocument doc = PdfDocument.Load("document.pdf"); -foreach (PdfDocumentPage page in doc.Pages) -{ - PdfTextExtractor extractor = new PdfTextExtractor(page); - columnData.AddRange(extractor.GetColumnAsStrings("Column")); -} -``` - -Or the content of a field (text on the right of the indicated text): - -```csharp -var fieldData = new List(); -PdfDocument doc = PdfDocument.Load("document.pdf"); -foreach (PdfDocumentPage page in doc.Pages) -{ - PdfTextExtractor extractor = new PdfTextExtractor(page); - fieldData.Add(extractor.GetFieldAsString(txtFieldName.Text)); -} -``` - -### VAR.PdfTools.Workbench -It is a simple Windows.Forms application, to test basic funcitionallity of the library. - -## Building -A Visual Studio solution is provided. Simply, click build on the IDE. - -The build generates a DLL and a Nuget package. - -## Contributing -1. Fork it! -2. Create your feature branch: `git checkout -b my-new-feature` -3. Commit your changes: `git commit -am 'Add some feature'` -4. Push to the branch: `git push origin my-new-feature` -5. Submit a pull request :D - -## Credits -* Valeriano Alfonso Rodriguez. - diff --git a/VAR.PdfTools.Workbench/Configuration.cs b/VAR.PdfTools.Workbench/Configuration.cs deleted file mode 100644 index b9c9df2..0000000 --- a/VAR.PdfTools.Workbench/Configuration.cs +++ /dev/null @@ -1,117 +0,0 @@ -using System.Collections.Generic; -using System.IO; -using System.Text; - -namespace VAR.PdfTools.Workbench -{ - public class Configuration - { - private Dictionary _configItems = new Dictionary(); - - private static string GetConfigFileName() - { - string location = System.Reflection.Assembly.GetEntryAssembly().Location; - string path = Path.GetDirectoryName(location); - string filenameWithoutExtension = Path.GetFileNameWithoutExtension(location); - - string configFile = string.Format("{0}/{1}.cfg", path, filenameWithoutExtension); - return configFile; - } - - private static string[] GetConfigurationLines() - { - string configFile = GetConfigFileName(); - string[] config; - if (File.Exists(configFile) == false) - { - config = new string[0]; - } - else - { - config = File.ReadAllLines(configFile); - } - return config; - } - - public void Load() - { - _configItems.Clear(); - string[] configLines = GetConfigurationLines(); - foreach (string configLine in configLines) - { - int idxSplit = configLine.IndexOf('|'); - if (idxSplit < 0) { continue; } - string configName = configLine.Substring(0, idxSplit); - string configData = configLine.Substring(idxSplit + 1); - - if (_configItems.ContainsKey(configName)) - { - _configItems[configName] = configData; - } - else - { - _configItems.Add(configName, configData); - } - } - } - - public void Save() - { - StringBuilder sbConfig = new StringBuilder(); - foreach (KeyValuePair pair in _configItems) - { - sbConfig.AppendFormat("{0}|{1}\n", pair.Key, pair.Value); - } - string configFileName = GetConfigFileName(); - File.WriteAllText(configFileName, sbConfig.ToString()); - } - - public string Get(string key, string defaultValue) - { - if (_configItems == null) { return defaultValue; } - if (_configItems.ContainsKey(key)) - { - return _configItems[key]; - } - return defaultValue; - } - - public bool Get(string key, bool defaultValue) - { - if (_configItems == null) { return defaultValue; } - if (_configItems.ContainsKey(key)) - { - string value = _configItems[key]; - return (value == "true"); - } - return defaultValue; - } - - public void Set(string key, string value) - { - if (_configItems == null) { return; } - if (_configItems.ContainsKey(key)) - { - _configItems[key] = value; - } - else - { - _configItems.Add(key, value); - } - } - - public void Set(string key, bool value) - { - if (_configItems == null) { return; } - if (_configItems.ContainsKey(key)) - { - _configItems[key] = value ? "true" : "false"; - } - else - { - _configItems.Add(key, value ? "true" : "false"); - } - } - - } -} diff --git a/VAR.PdfTools.Workbench/FrmPdfInfo.Designer.cs b/VAR.PdfTools.Workbench/FrmPdfInfo.Designer.cs deleted file mode 100644 index 744b721..0000000 --- a/VAR.PdfTools.Workbench/FrmPdfInfo.Designer.cs +++ /dev/null @@ -1,319 +0,0 @@ -namespace VAR.PdfTools.Workbench -{ - partial class FrmPdfInfo - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.lblOutputs = new System.Windows.Forms.Label(); - this.lblInputs = new System.Windows.Forms.Label(); - this.btnBrowse = new System.Windows.Forms.Button(); - this.txtPdfPath = new System.Windows.Forms.TextBox(); - this.txtOutput = new System.Windows.Forms.TextBox(); - this.btnProcess = new System.Windows.Forms.Button(); - this.btnGetColumn1 = new System.Windows.Forms.Button(); - this.txtField1 = new System.Windows.Forms.TextBox(); - this.btnGetField1 = new System.Windows.Forms.Button(); - this.btnHasText1 = new System.Windows.Forms.Button(); - this.btnRender = new System.Windows.Forms.Button(); - this.btnHasText2 = new System.Windows.Forms.Button(); - this.btnGetField2 = new System.Windows.Forms.Button(); - this.txtField2 = new System.Windows.Forms.TextBox(); - this.btnGetColumn2 = new System.Windows.Forms.Button(); - this.btnHasText3 = new System.Windows.Forms.Button(); - this.btnGetField3 = new System.Windows.Forms.Button(); - this.txtField3 = new System.Windows.Forms.TextBox(); - this.btnGetColumn3 = new System.Windows.Forms.Button(); - this.txtPages = new System.Windows.Forms.TextBox(); - this.chkRender = new System.Windows.Forms.CheckBox(); - this.SuspendLayout(); - // - // lblOutputs - // - this.lblOutputs.AutoSize = true; - this.lblOutputs.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.lblOutputs.Location = new System.Drawing.Point(12, 143); - this.lblOutputs.Name = "lblOutputs"; - this.lblOutputs.Size = new System.Drawing.Size(51, 13); - this.lblOutputs.TabIndex = 11; - this.lblOutputs.Text = "Outputs"; - // - // lblInputs - // - this.lblInputs.AutoSize = true; - this.lblInputs.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.lblInputs.Location = new System.Drawing.Point(12, 9); - this.lblInputs.Name = "lblInputs"; - this.lblInputs.Size = new System.Drawing.Size(42, 13); - this.lblInputs.TabIndex = 10; - this.lblInputs.Text = "Inputs"; - // - // btnBrowse - // - this.btnBrowse.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.btnBrowse.Location = new System.Drawing.Point(316, 23); - this.btnBrowse.Name = "btnBrowse"; - this.btnBrowse.Size = new System.Drawing.Size(75, 23); - this.btnBrowse.TabIndex = 9; - this.btnBrowse.Text = "Browse"; - this.btnBrowse.UseVisualStyleBackColor = true; - this.btnBrowse.Click += new System.EventHandler(this.btnBrowse_Click); - // - // txtPdfPath - // - this.txtPdfPath.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.txtPdfPath.Location = new System.Drawing.Point(15, 25); - this.txtPdfPath.Name = "txtPdfPath"; - this.txtPdfPath.Size = new System.Drawing.Size(295, 20); - this.txtPdfPath.TabIndex = 8; - // - // txtOutput - // - this.txtOutput.AcceptsReturn = true; - this.txtOutput.AcceptsTab = true; - this.txtOutput.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.txtOutput.Font = new System.Drawing.Font("Consolas", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.txtOutput.Location = new System.Drawing.Point(15, 159); - this.txtOutput.Multiline = true; - this.txtOutput.Name = "txtOutput"; - this.txtOutput.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; - this.txtOutput.Size = new System.Drawing.Size(457, 290); - this.txtOutput.TabIndex = 7; - // - // btnProcess - // - this.btnProcess.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.btnProcess.Location = new System.Drawing.Point(397, 23); - this.btnProcess.Name = "btnProcess"; - this.btnProcess.Size = new System.Drawing.Size(75, 23); - this.btnProcess.TabIndex = 6; - this.btnProcess.Text = "Process"; - this.btnProcess.UseVisualStyleBackColor = true; - this.btnProcess.Click += new System.EventHandler(this.btnProcess_Click); - // - // btnGetColumn1 - // - this.btnGetColumn1.Location = new System.Drawing.Point(292, 51); - this.btnGetColumn1.Name = "btnGetColumn1"; - this.btnGetColumn1.Size = new System.Drawing.Size(69, 23); - this.btnGetColumn1.TabIndex = 12; - this.btnGetColumn1.Text = "GetColumn"; - this.btnGetColumn1.UseVisualStyleBackColor = true; - this.btnGetColumn1.Click += new System.EventHandler(this.btnGetColumn1_Click); - // - // txtField1 - // - this.txtField1.Location = new System.Drawing.Point(15, 53); - this.txtField1.Name = "txtField1"; - this.txtField1.Size = new System.Drawing.Size(142, 20); - this.txtField1.TabIndex = 13; - // - // btnGetField1 - // - this.btnGetField1.Location = new System.Drawing.Point(226, 51); - this.btnGetField1.Name = "btnGetField1"; - this.btnGetField1.Size = new System.Drawing.Size(60, 23); - this.btnGetField1.TabIndex = 14; - this.btnGetField1.Text = "GetField"; - this.btnGetField1.UseVisualStyleBackColor = true; - this.btnGetField1.Click += new System.EventHandler(this.btnGetField1_Click); - // - // btnHasText1 - // - this.btnHasText1.Location = new System.Drawing.Point(163, 51); - this.btnHasText1.Name = "btnHasText1"; - this.btnHasText1.Size = new System.Drawing.Size(57, 23); - this.btnHasText1.TabIndex = 16; - this.btnHasText1.Text = "HasText"; - this.btnHasText1.UseVisualStyleBackColor = true; - this.btnHasText1.Click += new System.EventHandler(this.btnHasText1_Click); - // - // btnRender - // - this.btnRender.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.btnRender.Location = new System.Drawing.Point(397, 52); - this.btnRender.Name = "btnRender"; - this.btnRender.Size = new System.Drawing.Size(75, 23); - this.btnRender.TabIndex = 18; - this.btnRender.Text = "Render"; - this.btnRender.UseVisualStyleBackColor = true; - this.btnRender.Click += new System.EventHandler(this.btnRender_Click); - // - // btnHasText2 - // - this.btnHasText2.Location = new System.Drawing.Point(163, 80); - this.btnHasText2.Name = "btnHasText2"; - this.btnHasText2.Size = new System.Drawing.Size(57, 23); - this.btnHasText2.TabIndex = 22; - this.btnHasText2.Text = "HasText"; - this.btnHasText2.UseVisualStyleBackColor = true; - this.btnHasText2.Click += new System.EventHandler(this.btnHasText2_Click); - // - // btnGetField2 - // - this.btnGetField2.Location = new System.Drawing.Point(226, 80); - this.btnGetField2.Name = "btnGetField2"; - this.btnGetField2.Size = new System.Drawing.Size(60, 23); - this.btnGetField2.TabIndex = 21; - this.btnGetField2.Text = "GetField"; - this.btnGetField2.UseVisualStyleBackColor = true; - this.btnGetField2.Click += new System.EventHandler(this.btnGetField2_Click); - // - // txtField2 - // - this.txtField2.Location = new System.Drawing.Point(15, 82); - this.txtField2.Name = "txtField2"; - this.txtField2.Size = new System.Drawing.Size(142, 20); - this.txtField2.TabIndex = 20; - // - // btnGetColumn2 - // - this.btnGetColumn2.Location = new System.Drawing.Point(292, 80); - this.btnGetColumn2.Name = "btnGetColumn2"; - this.btnGetColumn2.Size = new System.Drawing.Size(69, 23); - this.btnGetColumn2.TabIndex = 19; - this.btnGetColumn2.Text = "GetColumn"; - this.btnGetColumn2.UseVisualStyleBackColor = true; - this.btnGetColumn2.Click += new System.EventHandler(this.btnGetColumn2_Click); - // - // btnHasText3 - // - this.btnHasText3.Location = new System.Drawing.Point(163, 109); - this.btnHasText3.Name = "btnHasText3"; - this.btnHasText3.Size = new System.Drawing.Size(57, 23); - this.btnHasText3.TabIndex = 26; - this.btnHasText3.Text = "HasText"; - this.btnHasText3.UseVisualStyleBackColor = true; - this.btnHasText3.Click += new System.EventHandler(this.btnHasText3_Click); - // - // btnGetField3 - // - this.btnGetField3.Location = new System.Drawing.Point(226, 109); - this.btnGetField3.Name = "btnGetField3"; - this.btnGetField3.Size = new System.Drawing.Size(60, 23); - this.btnGetField3.TabIndex = 25; - this.btnGetField3.Text = "GetField"; - this.btnGetField3.UseVisualStyleBackColor = true; - this.btnGetField3.Click += new System.EventHandler(this.btnGetField3_Click); - // - // txtField3 - // - this.txtField3.Location = new System.Drawing.Point(15, 111); - this.txtField3.Name = "txtField3"; - this.txtField3.Size = new System.Drawing.Size(142, 20); - this.txtField3.TabIndex = 24; - // - // btnGetColumn3 - // - this.btnGetColumn3.Location = new System.Drawing.Point(292, 109); - this.btnGetColumn3.Name = "btnGetColumn3"; - this.btnGetColumn3.Size = new System.Drawing.Size(69, 23); - this.btnGetColumn3.TabIndex = 23; - this.btnGetColumn3.Text = "GetColumn"; - this.btnGetColumn3.UseVisualStyleBackColor = true; - this.btnGetColumn3.Click += new System.EventHandler(this.btnGetColumn3_Click); - // - // txtPages - // - this.txtPages.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.txtPages.Location = new System.Drawing.Point(397, 82); - this.txtPages.Name = "txtPages"; - this.txtPages.Size = new System.Drawing.Size(75, 20); - this.txtPages.TabIndex = 27; - // - // chkRender - // - this.chkRender.AutoSize = true; - this.chkRender.Location = new System.Drawing.Point(292, 138); - this.chkRender.Name = "chkRender"; - this.chkRender.Size = new System.Drawing.Size(61, 17); - this.chkRender.TabIndex = 28; - this.chkRender.Text = "Render"; - this.chkRender.UseVisualStyleBackColor = true; - // - // FrmPdfInfo - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(484, 461); - this.Controls.Add(this.chkRender); - this.Controls.Add(this.txtPages); - this.Controls.Add(this.btnHasText3); - this.Controls.Add(this.btnGetField3); - this.Controls.Add(this.txtField3); - this.Controls.Add(this.btnGetColumn3); - this.Controls.Add(this.btnHasText2); - this.Controls.Add(this.btnGetField2); - this.Controls.Add(this.txtField2); - this.Controls.Add(this.btnGetColumn2); - this.Controls.Add(this.btnRender); - this.Controls.Add(this.btnHasText1); - this.Controls.Add(this.btnGetField1); - this.Controls.Add(this.txtField1); - this.Controls.Add(this.btnGetColumn1); - this.Controls.Add(this.lblOutputs); - this.Controls.Add(this.lblInputs); - this.Controls.Add(this.btnBrowse); - this.Controls.Add(this.txtPdfPath); - this.Controls.Add(this.txtOutput); - this.Controls.Add(this.btnProcess); - this.Name = "FrmPdfInfo"; - this.Text = "PdfInfo"; - this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FrmPdfInfo_FormClosing); - this.Load += new System.EventHandler(this.FrmPdfInfo_Load); - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - - private System.Windows.Forms.Label lblOutputs; - private System.Windows.Forms.Label lblInputs; - private System.Windows.Forms.Button btnBrowse; - private System.Windows.Forms.TextBox txtPdfPath; - private System.Windows.Forms.TextBox txtOutput; - private System.Windows.Forms.Button btnProcess; - private System.Windows.Forms.Button btnGetColumn1; - private System.Windows.Forms.TextBox txtField1; - private System.Windows.Forms.Button btnGetField1; - private System.Windows.Forms.Button btnHasText1; - private System.Windows.Forms.Button btnRender; - private System.Windows.Forms.Button btnHasText2; - private System.Windows.Forms.Button btnGetField2; - private System.Windows.Forms.TextBox txtField2; - private System.Windows.Forms.Button btnGetColumn2; - private System.Windows.Forms.Button btnHasText3; - private System.Windows.Forms.Button btnGetField3; - private System.Windows.Forms.TextBox txtField3; - private System.Windows.Forms.Button btnGetColumn3; - private System.Windows.Forms.TextBox txtPages; - private System.Windows.Forms.CheckBox chkRender; - } -} \ No newline at end of file diff --git a/VAR.PdfTools.Workbench/FrmPdfInfo.cs b/VAR.PdfTools.Workbench/FrmPdfInfo.cs deleted file mode 100644 index 9223b5d..0000000 --- a/VAR.PdfTools.Workbench/FrmPdfInfo.cs +++ /dev/null @@ -1,382 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Drawing; -using System.Drawing.Imaging; -using System.IO; -using System.Linq; -using System.Text; -using System.Windows.Forms; -using VAR.PdfTools.PdfElements; - -namespace VAR.PdfTools.Workbench -{ - public partial class FrmPdfInfo : Form - { - public FrmPdfInfo() - { - InitializeComponent(); - } - - private void FrmPdfInfo_Load(object sender, EventArgs e) - { - var configuration = new Configuration(); - configuration.Load(); - txtPdfPath.Text = configuration.Get("LastPdfPath", string.Empty); - txtField1.Text = configuration.Get("Field1", string.Empty); - txtField2.Text = configuration.Get("Field2", string.Empty); - txtField3.Text = configuration.Get("Field3", string.Empty); - txtPages.Text = configuration.Get("Pages", string.Empty); - chkRender.Checked = configuration.Get("Render", false); - } - - private void FrmPdfInfo_FormClosing(object sender, FormClosingEventArgs e) - { - var configuration = new Configuration(); - var configItems = new Dictionary(); - configuration.Set("LastPdfPath", txtPdfPath.Text); - configuration.Set("Field1", txtField1.Text); - configuration.Set("Field2", txtField2.Text); - configuration.Set("Field3", txtField3.Text); - configuration.Set("Pages", txtPages.Text); - configuration.Set("Render", chkRender.Checked); - configuration.Save(); - } - - private void btnBrowse_Click(object sender, EventArgs e) - { - var dlgFile = new OpenFileDialog(); - DialogResult result = dlgFile.ShowDialog(); - if (result == DialogResult.OK) - { - txtPdfPath.Text = dlgFile.FileName; - } - } - - private void btnProcess_Click(object sender, EventArgs e) - { - if (System.IO.File.Exists(txtPdfPath.Text) == false) - { - MessageBox.Show("File does not exist"); - return; - } - - PdfDocument doc = PdfDocument.Load(txtPdfPath.Text); - - int nObjects = doc.Objects.Count; - int nRootObject = doc.Objects.Where(obj => obj.UsageCount == 0).Count(); - List streams = doc.Objects - .Where(obj => obj.Data.Type == PdfElementTypes.Stream) - .Select(obj => (PdfStream)obj.Data) - .ToList(); - int nStreams = streams.Count; - int nPages = doc.Pages.Count; - - List lines = new List(); - lines.Add(string.Format("Filename : {0}", System.IO.Path.GetFileNameWithoutExtension(txtPdfPath.Text))); - lines.Add(string.Format("Number of Objects : {0}", nObjects)); - lines.Add(string.Format("Number of Roots : {0}", nRootObject)); - lines.Add(string.Format("Number of Streams : {0}", nStreams)); - lines.Add(string.Format("Number of Pages : {0}", nPages)); - - int pageNumber = 1; - foreach (PdfDocumentPage page in doc.Pages) - { - lines.Add("-----------------------------------------------------------------------------------------"); - if (page.BaseData.Values.ContainsKey("CropBox")) - { - PdfArray cropBox = page.BaseData.Values["CropBox"] as PdfArray; - lines.Add(string.Format("Page({0} of {1}): {2} {3} {4} {5}", pageNumber, doc.Pages.Count, - PdfElementUtils.GetReal(cropBox.Values[0], 0), - PdfElementUtils.GetReal(cropBox.Values[1], 0), - PdfElementUtils.GetReal(cropBox.Values[2], 0), - PdfElementUtils.GetReal(cropBox.Values[3], 0))); - } - else - { - lines.Add(string.Format("Page({0} of {1}): ", pageNumber, doc.Pages.Count)); - } - pageNumber++; - - PdfTextExtractor extractor = new PdfTextExtractor(page); - foreach (PdfTextElement textElement in extractor.Elements) - { - string fontName = textElement.Font == null ? "#NULL#" : textElement.Font.Name; - if (fontName == "#NULL#" && textElement.Childs.Count > 0) - { - var fontNames = textElement.Childs.Select(c => c.Font == null ? "#NULL#" : c.Font.Name); - StringBuilder sbFontName = new StringBuilder(); - foreach (string fontNameAux in fontNames) - { - if (sbFontName.Length > 0) { sbFontName.Append(";"); } - sbFontName.Append(fontNameAux); - } - fontName = sbFontName.ToString(); - } - - lines.Add(string.Format("Text({0}, {1})({2}, {3})[{4}]: \"{5}\"", - Math.Round(textElement.Matrix.Matrix[0, 2], 2), - Math.Round(textElement.Matrix.Matrix[1, 2], 2), - Math.Round(textElement.VisibleWidth, 2), - Math.Round(textElement.VisibleHeight, 2), - fontName, - textElement.VisibleText)); - } - } - - txtOutput.Lines = lines.ToArray(); - } - - private void btnHasText1_Click(object sender, EventArgs e) - { - string pdfPath = txtPdfPath.Text; - string text = txtField1.Text; - - Action_HasText(pdfPath, text); - } - - private void btnGetField1_Click(object sender, EventArgs e) - { - string pdfPath = txtPdfPath.Text; - string field = txtField1.Text; - - Action_GetField(pdfPath, field); - } - - private void btnGetColumn1_Click(object sender, EventArgs e) - { - string pdfPath = txtPdfPath.Text; - string column = txtField1.Text; - - Action_GetColumn(pdfPath, column); - } - - private void btnHasText2_Click(object sender, EventArgs e) - { - string pdfPath = txtPdfPath.Text; - string text = txtField2.Text; - - Action_HasText(pdfPath, text); - } - - private void btnGetField2_Click(object sender, EventArgs e) - { - string pdfPath = txtPdfPath.Text; - string field = txtField2.Text; - - Action_GetField(pdfPath, field); - } - - private void btnGetColumn2_Click(object sender, EventArgs e) - { - string pdfPath = txtPdfPath.Text; - string column = txtField2.Text; - - Action_GetColumn(pdfPath, column); - } - - private void btnHasText3_Click(object sender, EventArgs e) - { - string pdfPath = txtPdfPath.Text; - string text = txtField3.Text; - - Action_HasText(pdfPath, text); - } - - private void btnGetField3_Click(object sender, EventArgs e) - { - string pdfPath = txtPdfPath.Text; - string field = txtField3.Text; - - Action_GetField(pdfPath, field); - } - - private void btnGetColumn3_Click(object sender, EventArgs e) - { - string pdfPath = txtPdfPath.Text; - string column = txtField3.Text; - - Action_GetColumn(pdfPath, column); - } - - private IEnumerable GetSelectedPages(int maxPages) - { - string pages = txtPages.Text; - if (string.IsNullOrEmpty(pages)) - { - return Enumerable.Range(1, maxPages); - } - - string[] pagesParts; - if (pages.Contains(",")) - { - pagesParts = pages.Split(','); - } - else - { - pagesParts = new string[] { pages }; - } - List listPages = new List(); - foreach (string part in pagesParts) - { - if (part.Contains("-")) - { - string[] range = part.Split('-'); - if (range.Length == 2) - { - int pageStart; - int pageEnd; - if (int.TryParse(range[0], out pageStart) && int.TryParse(range[1], out pageEnd)) - { - listPages.AddRange(Enumerable.Range(pageStart, (pageEnd - pageStart) + 1)); - } - } - } - else - { - int pageNum; - if (int.TryParse(part, out pageNum)) - { - listPages.Add(pageNum); - } - } - } - if (listPages.Count == 0) - { - listPages.AddRange(Enumerable.Range(1, maxPages)); - } - return listPages; - } - - private void Action_HasText(string pdfPath, string text) - { - if (System.IO.File.Exists(pdfPath) == false) - { - MessageBox.Show("File does not exist"); - return; - } - - PdfDocument doc = PdfDocument.Load(pdfPath); - - IEnumerable selectedPages = GetSelectedPages(doc.Pages.Count); - List lines = new List(); - int pageNum = 0; - foreach (PdfDocumentPage page in doc.Pages) - { - pageNum++; - if (selectedPages.Contains(pageNum) == false) { continue; } - PdfTextExtractor extractor = new PdfTextExtractor(page); - lines.Add(string.Format("Page({0}) : {1}", pageNum, Convert.ToString(extractor.HasText(text)))); - } - txtOutput.Lines = lines.ToArray(); - } - - private void Action_GetField(string pdfPath, string field) - { - if (System.IO.File.Exists(pdfPath) == false) - { - MessageBox.Show("File does not exist"); - return; - } - - PdfDocument doc = PdfDocument.Load(pdfPath); - - IEnumerable selectedPages = GetSelectedPages(doc.Pages.Count); - var fieldData = new List(); - int pageNum = 0; - foreach (PdfDocumentPage page in doc.Pages) - { - pageNum++; - if (selectedPages.Contains(pageNum) == false) { continue; } - PdfTextExtractor extractor = new PdfTextExtractor(page); - fieldData.Add(extractor.GetFieldAsString(field)); - } - txtOutput.Lines = fieldData.ToArray(); - } - - private void Action_GetColumn(string pdfPath, string column) - { - if (System.IO.File.Exists(pdfPath) == false) - { - MessageBox.Show("File does not exist"); - return; - } - - PdfDocument doc = PdfDocument.Load(pdfPath); - string baseDocumentPath = Path.GetDirectoryName(txtPdfPath.Text); - string baseDocumentFilename = Path.GetFileNameWithoutExtension(txtPdfPath.Text); - - IEnumerable selectedPages = GetSelectedPages(doc.Pages.Count); - var columns = new List(); - int pageNum = 0; - foreach (PdfDocumentPage page in doc.Pages) - { - pageNum++; - if (selectedPages.Contains(pageNum) == false) { continue; } - PdfTextExtractor extractor = new PdfTextExtractor(page); - PdfTextElementColumn columnData; - if (column.StartsWith("#")) - { - string[] columnParts = column.Substring(1).Split(';'); - double y = Convert.ToDouble(columnParts[0]); - double x1 = Convert.ToDouble(columnParts[1]); - double x2 = Convert.ToDouble(columnParts[2]); - columnData = extractor.GetColumn(null, y, x1, x2, x1, x2); - } - else - { - columnData = extractor.GetColumn(column); - } - if (chkRender.Checked) - { - var pdfPageRenderer = new PdfPageRenderer(extractor); - Bitmap bmp = pdfPageRenderer.Render(); - pdfPageRenderer.RenderColumn(columnData, bmp); - string fileName = Path.Combine(baseDocumentPath, string.Format("{0}_{1:0000}.png", baseDocumentFilename, pageNum)); - bmp.Save(fileName, ImageFormat.Png); - bmp.Dispose(); - GC.Collect(); - } - columns.AddRange(columnData.Elements.Select(t => t.VisibleText)); - } - txtOutput.Lines = columns.ToArray(); - } - - private void btnRender_Click(object sender, EventArgs e) - { - if (File.Exists(txtPdfPath.Text) == false) - { - MessageBox.Show("File does not exist"); - return; - } - - PdfDocument doc = PdfDocument.Load(txtPdfPath.Text); - string baseDocumentPath = Path.GetDirectoryName(txtPdfPath.Text); - string baseDocumentFilename = Path.GetFileNameWithoutExtension(txtPdfPath.Text); - - List lines = new List(); - lines.Add(string.Format("Filename : {0}", baseDocumentFilename)); - lines.Add(string.Format("Number of Pages : {0}", doc.Pages.Count)); - - IEnumerable selectedPages = GetSelectedPages(doc.Pages.Count); - int pageNum = 0; - foreach (PdfDocumentPage page in doc.Pages) - { - pageNum++; - if (selectedPages.Contains(pageNum) == false) { continue; } - - PdfPageRenderer pdfPageRenderer = new PdfPageRenderer(page); - Bitmap bmp = pdfPageRenderer.Render(); - - lines.Add(string.Format("Page {0:0000} TextElements : {1}", pageNum, pdfPageRenderer.Extractor.Elements.Count)); - - // Save image to disk - string fileName = Path.Combine(baseDocumentPath, string.Format("{0}_{1:0000}.png", baseDocumentFilename, pageNum)); - bmp.Save(fileName, ImageFormat.Png); - bmp.Dispose(); - GC.Collect(); - } - - txtOutput.Lines = lines.ToArray(); - } - } -} diff --git a/VAR.PdfTools.Workbench/FrmPdfInfo.resx b/VAR.PdfTools.Workbench/FrmPdfInfo.resx deleted file mode 100644 index 1af7de1..0000000 --- a/VAR.PdfTools.Workbench/FrmPdfInfo.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/VAR.PdfTools.Workbench/Program.cs b/VAR.PdfTools.Workbench/Program.cs deleted file mode 100644 index 6e31e45..0000000 --- a/VAR.PdfTools.Workbench/Program.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Windows.Forms; - -namespace VAR.PdfTools.Workbench -{ - static class Program - { - /// - /// The main entry point for the application. - /// - [STAThread] - static void Main() - { - Application.EnableVisualStyles(); - Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new FrmPdfInfo()); - } - } -} diff --git a/VAR.PdfTools.Workbench/Properties/PublishProfiles/FolderProfile.pubxml b/VAR.PdfTools.Workbench/Properties/PublishProfiles/FolderProfile.pubxml deleted file mode 100644 index cca00f5..0000000 --- a/VAR.PdfTools.Workbench/Properties/PublishProfiles/FolderProfile.pubxml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - Release - Any CPU - bin\Release\net5.0-windows\publish\ - FileSystem - net5.0-windows - win-x64 - true - True - False - True - True - - \ No newline at end of file diff --git a/VAR.PdfTools.Workbench/VAR.PdfTools.Workbench.Net35.csproj b/VAR.PdfTools.Workbench/VAR.PdfTools.Workbench.Net35.csproj deleted file mode 100644 index b23ae94..0000000 --- a/VAR.PdfTools.Workbench/VAR.PdfTools.Workbench.Net35.csproj +++ /dev/null @@ -1,81 +0,0 @@ - - - - - Debug - AnyCPU - {A5825D8E-9F81-49E0-B610-8AE5E46D02EA} - WinExe - Properties - VAR.PdfTools.Workbench - VAR.PdfTools.Workbench - v3.5 - 512 - true - - 10.0.0 - 2.0 - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - - - - Form - - - FrmPdfInfo.cs - - - - - SettingsSingleFileGenerator - Settings.Designer.cs - - - True - Settings.settings - True - - - - - - - {EB7E003A-6A95-4002-809F-926C7C8A11E9} - VAR.PdfTools.Net35 - - - diff --git a/VAR.PdfTools.Workbench/VAR.PdfTools.Workbench.csproj b/VAR.PdfTools.Workbench/VAR.PdfTools.Workbench.csproj deleted file mode 100644 index 4306f83..0000000 --- a/VAR.PdfTools.Workbench/VAR.PdfTools.Workbench.csproj +++ /dev/null @@ -1,26 +0,0 @@ - - - net5.0-windows - WinExe - true - - - VAR.PdfTools.Workbench - VAR.PdfTools.Workbench - 1.6.1 - PdfTools Workbench - VAR - VAR - Copyright © VAR 2016-2019 - false - LICENSE.txt - https://github.com/Kableado/VAR.PdfTools - PDF;PDF Tool - - - - - - - - \ No newline at end of file diff --git a/VAR.PdfTools.sln b/VAR.PdfTools.sln deleted file mode 100644 index ca6e75b..0000000 --- a/VAR.PdfTools.sln +++ /dev/null @@ -1,37 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.31402.337 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VAR.PdfTools", "VAR.PdfTools\VAR.PdfTools.csproj", "{EB7E003A-6A95-4002-809F-926C7C8A11E9}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VAR.PdfTools.Workbench", "VAR.PdfTools.Workbench\VAR.PdfTools.Workbench.csproj", "{A5825D8E-9F81-49E0-B610-8AE5E46D02EA}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Notes", "Notes", "{CE2D7584-5D82-401E-9A88-A9961CBB6959}" - ProjectSection(SolutionItems) = preProject - LICENSE.txt = LICENSE.txt - README.md = README.md - EndProjectSection -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {EB7E003A-6A95-4002-809F-926C7C8A11E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {EB7E003A-6A95-4002-809F-926C7C8A11E9}.Debug|Any CPU.Build.0 = Debug|Any CPU - {EB7E003A-6A95-4002-809F-926C7C8A11E9}.Release|Any CPU.ActiveCfg = Release|Any CPU - {EB7E003A-6A95-4002-809F-926C7C8A11E9}.Release|Any CPU.Build.0 = Release|Any CPU - {A5825D8E-9F81-49E0-B610-8AE5E46D02EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A5825D8E-9F81-49E0-B610-8AE5E46D02EA}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A5825D8E-9F81-49E0-B610-8AE5E46D02EA}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A5825D8E-9F81-49E0-B610-8AE5E46D02EA}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {7E5F981A-8918-4C9E-AC9C-A798E2F3DA69} - EndGlobalSection -EndGlobal diff --git a/VAR.PdfTools/Maths/Matrix3x3.cs b/VAR.PdfTools/Maths/Matrix3x3.cs deleted file mode 100644 index 6853d4f..0000000 --- a/VAR.PdfTools/Maths/Matrix3x3.cs +++ /dev/null @@ -1,121 +0,0 @@ -using System; - -namespace VAR.PdfTools.Maths -{ - public class Matrix3x3 - { - #region Declarations - - public double[,] _matrix = new double[3, 3]; - - #endregion - - #region Properties - - public double[,] Matrix { get { return _matrix; } } - - #endregion - - #region Creator - - public Matrix3x3() - { - Idenity(); - } - - public Matrix3x3(double a, double b, double c, double d, double e, double f) - { - Set(a, b, c, d, e, f); - } - - #endregion - - #region Public methods - - public void Idenity() - { - _matrix[0, 0] = 1.0; - _matrix[0, 1] = 0.0; - _matrix[0, 2] = 0.0; - _matrix[1, 0] = 0.0; - _matrix[1, 1] = 1.0; - _matrix[1, 2] = 0.0; - _matrix[2, 0] = 0.0; - _matrix[2, 1] = 0.0; - _matrix[2, 2] = 1.0; - } - - public void Set(double a, double b, double c, double d, double e, double f) - { - _matrix[0, 0] = a; - _matrix[1, 0] = b; - _matrix[2, 0] = 0; - _matrix[0, 1] = c; - _matrix[1, 1] = d; - _matrix[2, 1] = 0; - _matrix[0, 2] = e; - _matrix[1, 2] = f; - _matrix[2, 2] = 1; - } - - public Vector3D Multiply(Vector3D vect) - { - Vector3D vectResult = new Vector3D(); - - vectResult.Vector[0] = (vect.Vector[0] * _matrix[0, 0]) + (vect.Vector[1] * _matrix[0, 1]) + (vect.Vector[2] * _matrix[0, 2]); - vectResult.Vector[1] = (vect.Vector[0] * _matrix[1, 0]) + (vect.Vector[1] * _matrix[1, 1]) + (vect.Vector[2] * _matrix[1, 2]); - vectResult.Vector[2] = (vect.Vector[0] * _matrix[2, 0]) + (vect.Vector[1] * _matrix[2, 1]) + (vect.Vector[2] * _matrix[2, 2]); - - return vectResult; - } - - public Matrix3x3 Multiply(Matrix3x3 matrix) - { - Matrix3x3 newMatrix = new Matrix3x3(); - - newMatrix._matrix[0, 0] = (_matrix[0, 0] * matrix._matrix[0, 0]) + (_matrix[1, 0] * matrix._matrix[0, 1]) + (_matrix[2, 0] * matrix._matrix[0, 2]); - newMatrix._matrix[0, 1] = (_matrix[0, 1] * matrix._matrix[0, 0]) + (_matrix[1, 1] * matrix._matrix[0, 1]) + (_matrix[2, 1] * matrix._matrix[0, 2]); - newMatrix._matrix[0, 2] = (_matrix[0, 2] * matrix._matrix[0, 0]) + (_matrix[1, 2] * matrix._matrix[0, 1]) + (_matrix[2, 2] * matrix._matrix[0, 2]); - newMatrix._matrix[1, 0] = (_matrix[0, 0] * matrix._matrix[1, 0]) + (_matrix[1, 0] * matrix._matrix[1, 1]) + (_matrix[2, 0] * matrix._matrix[1, 2]); - newMatrix._matrix[1, 1] = (_matrix[0, 1] * matrix._matrix[1, 0]) + (_matrix[1, 1] * matrix._matrix[1, 1]) + (_matrix[2, 1] * matrix._matrix[1, 2]); - newMatrix._matrix[1, 2] = (_matrix[0, 2] * matrix._matrix[1, 0]) + (_matrix[1, 2] * matrix._matrix[1, 1]) + (_matrix[2, 2] * matrix._matrix[1, 2]); - newMatrix._matrix[2, 0] = (_matrix[0, 0] * matrix._matrix[2, 0]) + (_matrix[1, 0] * matrix._matrix[2, 1]) + (_matrix[2, 0] * matrix._matrix[2, 2]); - newMatrix._matrix[2, 1] = (_matrix[0, 1] * matrix._matrix[2, 0]) + (_matrix[1, 1] * matrix._matrix[2, 1]) + (_matrix[2, 1] * matrix._matrix[2, 2]); - newMatrix._matrix[2, 2] = (_matrix[0, 2] * matrix._matrix[2, 0]) + (_matrix[1, 2] * matrix._matrix[2, 1]) + (_matrix[2, 2] * matrix._matrix[2, 2]); - - return newMatrix; - } - - public Matrix3x3 Copy() - { - Matrix3x3 newMatrix = new Matrix3x3(); - - newMatrix._matrix[0, 0] = _matrix[0, 0]; - newMatrix._matrix[0, 1] = _matrix[0, 1]; - newMatrix._matrix[0, 2] = _matrix[0, 2]; - newMatrix._matrix[1, 0] = _matrix[1, 0]; - newMatrix._matrix[1, 1] = _matrix[1, 1]; - newMatrix._matrix[1, 2] = _matrix[1, 2]; - newMatrix._matrix[2, 0] = _matrix[2, 0]; - newMatrix._matrix[2, 1] = _matrix[2, 1]; - newMatrix._matrix[2, 2] = _matrix[2, 2]; - - return newMatrix; - } - - public bool IsCollinear(Matrix3x3 otherMatrix, double horizontalDelta = 0.00001, double verticalDelta = 0.00001) - { - double epsilon = 0.00001; - return ( - Math.Abs(_matrix[0, 0] - otherMatrix.Matrix[0, 0]) <= epsilon && - Math.Abs(_matrix[1, 0] - otherMatrix.Matrix[1, 0]) <= epsilon && - Math.Abs(_matrix[0, 1] - otherMatrix.Matrix[0, 1]) <= epsilon && - Math.Abs(_matrix[1, 1] - otherMatrix.Matrix[1, 1]) <= epsilon && - Math.Abs(_matrix[0, 2] - otherMatrix.Matrix[0, 2]) <= horizontalDelta && - Math.Abs(_matrix[1, 2] - otherMatrix.Matrix[1, 2]) <= verticalDelta && - true); - } - - #endregion - } -} diff --git a/VAR.PdfTools/Maths/Rect.cs b/VAR.PdfTools/Maths/Rect.cs deleted file mode 100644 index 5bd248c..0000000 --- a/VAR.PdfTools/Maths/Rect.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace VAR.PdfTools.Maths -{ - public class Rect - { - public double XMin { get; set; } - public double XMax { get; set; } - public double YMin { get; set; } - public double YMax { get; set; } - - public void Add(Rect rect) - { - if (rect.XMax > XMax) { XMax = rect.XMax; } - if (rect.YMax > YMax) { YMax = rect.YMax; } - if (rect.XMin < XMin) { XMin = rect.XMin; } - if (rect.YMin < YMin) { YMin = rect.YMin; } - } - - } -} diff --git a/VAR.PdfTools/Maths/Vector3D.cs b/VAR.PdfTools/Maths/Vector3D.cs deleted file mode 100644 index 1985ab3..0000000 --- a/VAR.PdfTools/Maths/Vector3D.cs +++ /dev/null @@ -1,33 +0,0 @@ -namespace VAR.PdfTools.Maths -{ - public class Vector3D - { - #region Declarations - - public double[] _vector = new double[3]; - - #endregion - - #region Properties - - public double[] Vector { get { return _vector; } } - - #endregion - - #region Creator - - public Vector3D() - { - Init(); - } - - public void Init() - { - _vector[0] = 0.0; - _vector[1] = 0.0; - _vector[2] = 1.0; - } - - #endregion - } -} diff --git a/VAR.PdfTools/PdfContentAction.cs b/VAR.PdfTools/PdfContentAction.cs deleted file mode 100644 index 83e7410..0000000 --- a/VAR.PdfTools/PdfContentAction.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System.Collections.Generic; -using VAR.PdfTools.PdfElements; - -namespace VAR.PdfTools -{ - public class PdfContentAction - { - #region Declarations - - string _token = null; - - private List _parameters = null; - - #endregion - - #region Properties - - public string Token { get { return _token; } } - - public List Parameters { get { return _parameters; } } - - #endregion - - #region Life cycle - - public PdfContentAction(string token, List parameters) - { - _token = token; - _parameters = parameters; - } - - #endregion - } -} diff --git a/VAR.PdfTools/PdfDocument.cs b/VAR.PdfTools/PdfDocument.cs deleted file mode 100644 index 9b31fe1..0000000 --- a/VAR.PdfTools/PdfDocument.cs +++ /dev/null @@ -1,337 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using VAR.PdfTools.PdfElements; - -namespace VAR.PdfTools -{ - public class PdfDocument - { - #region Declarations - - private List _objects = new List(); - - private PdfDictionary _catalog = null; - - private List _pages = new List(); - - #endregion - - #region Properties - - public List Objects { get { return _objects; } } - - public PdfDictionary Catalog { get { return _catalog; } } - - public List Pages { get { return _pages; } } - - #endregion - - #region Life cycle - - private PdfDocument() { } - - #endregion - - #region Private methods - - private static void ApplyFilterToStream(PdfStream stream, string filter) - { - if(filter == "ASCIIHexDecode") - { - // TODO: Implement ASCIIHexDecode Filter - } - else if (filter == "ASCII85Decode" || filter == "A85") - { - // TODO: Implement ASCII85Decode Filter - } - else if (filter == "LZWDecode") - { - // TODO: Implement LZWDecode Filter - } - else if (filter == "FlateDecode") - { - byte[] decodedStreamData = PdfFilters.FlateDecode.Decode(stream.Data); - stream.Data = decodedStreamData; - } - else if (filter == "RunLengthDecode") - { - // TODO: Implement RunLengthDecode Filter - } - else if (filter == "CCITTFaxDecode") - { - // TODO: Implement CCITTFaxDecode Filter - } - else if (filter == "JBIG2Decode") - { - // TODO: Implement JBIG2Decode Filter - } - else if (filter == "DCTDecode") - { - // TODO: Implement DCTDecode Filter - } - else if (filter == "JPXDecode") - { - // TODO: Implement JPXDecode Filter - } - else if (filter == "Crypt") - { - // TODO: Implement Crypt Filter - } - else - { - // TODO: Handle unknown filters - } - } - - private static void ApplyFiltersToStreams(PdfStream stream) - { - if (stream.Dictionary.Values.ContainsKey("Filter") == false) { return; } - IPdfElement elemFilter = stream.Dictionary.Values["Filter"]; - - stream.OriginalData = stream.Data; - stream.OriginalFilter = stream.Dictionary.Values["Filter"]; - - if (elemFilter is PdfString) - { - ApplyFilterToStream(stream, ((PdfString)elemFilter).Value); - } - else if (elemFilter is PdfName) - { - ApplyFilterToStream(stream, ((PdfName)elemFilter).Value); - } - else if(elemFilter is PdfArray) - { - foreach(IPdfElement elemSubFilter in ((PdfArray)elemFilter).Values) - { - if (elemSubFilter is PdfString) - { - ApplyFilterToStream(stream, ((PdfString)elemSubFilter).Value); - } - else if (elemSubFilter is PdfName) - { - ApplyFilterToStream(stream, ((PdfName)elemSubFilter).Value); - } - else - { - throw new Exception("PdfFilter not correctly specified"); - } - } - } - else - { - throw new Exception("PdfFilter not correctly specified"); - } - - stream.Dictionary.Values["Length"] = new PdfInteger { Value = stream.Data.Length }; - stream.Dictionary.Values.Remove("Filter"); - } - - private static IPdfElement ResolveIndirectReferences(IPdfElement elem, Dictionary dictReferences) - { - if (elem is PdfObjectReference) - { - int objectId = ((PdfObjectReference)elem).ObjectID; - if (dictReferences.ContainsKey(objectId)) - { - PdfObject referencedObject = dictReferences[objectId]; - referencedObject.UsageCount++; - return referencedObject.Data; - } - else - { - return new PdfNull(); - } - } - - PdfObject obj = elem as PdfObject; - if (obj != null) - { - IPdfElement result = ResolveIndirectReferences(obj.Data, dictReferences); - if (result != obj.Data) - { - obj.Data = result; - } - return elem; - } - - PdfArray array = elem as PdfArray; - if (array != null) - { - for (int i = 0; i < array.Values.Count; i++) - { - IPdfElement result = ResolveIndirectReferences(array.Values[i], dictReferences); - if(result != array.Values[i]) - { - array.Values[i] = result; - } - } - return elem; - } - - PdfDictionary dict = elem as PdfDictionary; - if (dict != null) - { - List keys = dict.Values.Keys.ToList(); - foreach (string key in keys) - { - IPdfElement value = dict.Values[key]; - IPdfElement result = ResolveIndirectReferences(value, dictReferences); - if (result != value) - { - dict.Values[key] = result; - } - } - return elem; - } - - return elem; - } - - private static void ExtractPages(PdfDictionary page, PdfDocument doc, PdfDictionary resources) - { - string type = page.GetParamAsString("Type"); - if (type == "Page") - { - PdfDocumentPage docPage = new PdfDocumentPage(page, resources); - doc._pages.Add(docPage); - return; - } - else if (type == "Pages") - { - if (page.Values.ContainsKey("Kids") == false || (page.Values["Kids"] is PdfArray) == false) - { - throw new Exception("PdfDocument: Pages \"Kids\" not found"); - } - PdfArray kids = page.Values["Kids"] as PdfArray; - foreach (IPdfElement elem in kids.Values) - { - PdfDictionary childPage = elem as PdfDictionary; - if (page == null) { continue; } - PdfDictionary resourcesAux = null; - if (page.Values.ContainsKey("Resources")) - { - resourcesAux = page.Values["Resources"] as PdfDictionary; - } - ExtractPages(childPage, doc, resourcesAux); - } - } - else - { - throw new Exception(string.Format("PdfDocument: Unexpected page type, found: {0}", type)); - } - } - - #endregion - - #region Public methods - - public static PdfDocument Load(string filename) - { - byte[] fileBytes = File.ReadAllBytes(filename); - return Load(fileBytes); - } - - public static PdfDocument Load(byte[] data) - { - var doc = new PdfDocument(); - - // Parse data - var parser = new PdfParser(data); - do - { - PdfObject obj = parser.ParseObject(doc.Objects); - if (obj != null && obj.Data != null) - { - if (obj.Data is PdfStream) - { - ApplyFiltersToStreams((PdfStream)obj.Data); - } - doc.Objects.Add(obj); - } - } while (parser.IsEndOfStream() == false); - - // Expand Object Streams - List streamObjects = new List(); - foreach (PdfObject obj in doc.Objects) - { - if (obj.Data.Type != PdfElementTypes.Stream) { continue; } - PdfStream stream = obj.Data as PdfStream; - - string type = stream.Dictionary.GetParamAsString("Type"); - long? number = stream.Dictionary.GetParamAsInt("N"); - long? first = stream.Dictionary.GetParamAsInt("First"); - if (type == "ObjStm" && number != null && first != null) - { - obj.UsageCount++; - PdfParser parserAux = new PdfParser(stream.Data); - streamObjects.AddRange(parserAux.ParseObjectStream((int)number, (long)first)); - } - } - foreach (PdfObject obj in streamObjects) - { - doc.Objects.Add(obj); - } - - // Build cross reference table - Dictionary dictObjects = new Dictionary(); - foreach (PdfObject obj in doc.Objects) - { - if (dictObjects.ContainsKey(obj.ObjectID)) - { - if (dictObjects[obj.ObjectID].ObjectGeneration < obj.ObjectGeneration) - { - dictObjects[obj.ObjectID] = obj; - } - } - else - { - dictObjects.Add(obj.ObjectID, obj); - } - } - - // Iterate full document to resolve all indirect references - foreach(PdfObject obj in doc.Objects) - { - ResolveIndirectReferences(obj, dictObjects); - } - - // Search Catalog - foreach(PdfObject obj in doc.Objects) - { - if ((obj.Data is PdfDictionary) == false) { continue; } - string type = ((PdfDictionary)obj.Data).GetParamAsString("Type"); - if(type == "Catalog") - { - doc._catalog = (PdfDictionary)obj.Data; - break; - } - - } - if(doc._catalog == null) - { - throw new Exception("PdfDocument: Catalog not found"); - } - - // Search pages - if(doc.Catalog.Values.ContainsKey("Pages") == false || - (doc.Catalog.Values["Pages"] is PdfDictionary) == false) - { - throw new Exception("PdfDocument: Pages not found"); - } - PdfDictionary pages = (PdfDictionary)doc.Catalog.Values["Pages"]; - PdfDictionary resources = null; - if (doc.Catalog.Values.ContainsKey("Resources")) - { - resources = doc.Catalog.Values["Resources"] as PdfDictionary; - } - ExtractPages(pages, doc, resources); - - return doc; - } - - #endregion - - } -} diff --git a/VAR.PdfTools/PdfDocumentPage.cs b/VAR.PdfTools/PdfDocumentPage.cs deleted file mode 100644 index e0b6857..0000000 --- a/VAR.PdfTools/PdfDocumentPage.cs +++ /dev/null @@ -1,81 +0,0 @@ -using System; -using System.Collections.Generic; -using VAR.PdfTools.PdfElements; - -namespace VAR.PdfTools -{ - public class PdfDocumentPage - { - #region Declarations - - private PdfDictionary _baseData = null; - - private byte[] _content = null; - - private PdfDictionary _resources = null; - - private Dictionary _fonts = new Dictionary(); - - private List _contentActions = null; - - #endregion - - #region Properties - - public PdfDictionary BaseData { get { return _baseData; } } - - public byte[] Content { get { return _content; } } - - public Dictionary Fonts { get { return _fonts; } } - - public List ContentActions { get { return _contentActions; } } - - #endregion - - #region Life cycle - - public PdfDocumentPage(PdfDictionary baseData, PdfDictionary resources) - { - _baseData = baseData; - string type = baseData.GetParamAsString("Type"); - if (type != "Page") - { - throw new Exception(string.Format("PdfDocumentPage: Expected dictionary of type:\"Page\". Found: {0}", type)); - } - - // Get content, resources and fonts - _content = _baseData.GetParamAsStream("Contents"); - if (_baseData.Values.ContainsKey("Resources") == false) - { - _resources = resources; - } - else - { - _resources = _baseData.Values["Resources"] as PdfDictionary; - } - if (_resources != null && _resources.Values.ContainsKey("Font")) - { - PdfDictionary fonts = _resources.Values["Font"] as PdfDictionary; - foreach (KeyValuePair pair in fonts.Values) - { - var font = new PdfFont(pair.Value as PdfDictionary); - font.Name = pair.Key; - _fonts.Add(pair.Key, font); - } - } - - // Parse content - if (_content != null) - { - PdfParser parser = new PdfParser(_content); - _contentActions = parser.ParseContent(); - } - else - { - _contentActions = new List(); - } - } - - #endregion - } -} diff --git a/VAR.PdfTools/PdfElements/IPdfElement.cs b/VAR.PdfTools/PdfElements/IPdfElement.cs deleted file mode 100644 index cfcf168..0000000 --- a/VAR.PdfTools/PdfElements/IPdfElement.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace VAR.PdfTools.PdfElements -{ - public interface IPdfElement - { - PdfElementTypes Type { get; } - } -} diff --git a/VAR.PdfTools/PdfElements/PdfArray.cs b/VAR.PdfTools/PdfElements/PdfArray.cs deleted file mode 100644 index e0e29fa..0000000 --- a/VAR.PdfTools/PdfElements/PdfArray.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Collections.Generic; - -namespace VAR.PdfTools.PdfElements -{ - public class PdfArray : IPdfElement - { - public PdfElementTypes Type { get { return PdfElementTypes.Array; } } - private List _values = new List(); - public List Values { get { return _values; } } - } -} diff --git a/VAR.PdfTools/PdfElements/PdfBoolean.cs b/VAR.PdfTools/PdfElements/PdfBoolean.cs deleted file mode 100644 index 5ec3adc..0000000 --- a/VAR.PdfTools/PdfElements/PdfBoolean.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace VAR.PdfTools.PdfElements -{ - public class PdfBoolean : IPdfElement - { - public PdfElementTypes Type { get { return PdfElementTypes.Boolean; } } - public bool Value { get; set; } - } -} diff --git a/VAR.PdfTools/PdfElements/PdfDictionary.cs b/VAR.PdfTools/PdfElements/PdfDictionary.cs deleted file mode 100644 index df29824..0000000 --- a/VAR.PdfTools/PdfElements/PdfDictionary.cs +++ /dev/null @@ -1,77 +0,0 @@ -using System.Collections.Generic; -using System.IO; - -namespace VAR.PdfTools.PdfElements -{ - public class PdfDictionary : IPdfElement - { - public PdfElementTypes Type { get { return PdfElementTypes.Dictionary; } } - private Dictionary _values = new Dictionary(); - public Dictionary Values { get { return _values; } } - - public string GetParamAsString(string name) - { - if (Values.ContainsKey(name) == false) { return null; } - - IPdfElement value = Values[name]; - if (value is PdfArray) - { - value = ((PdfArray)value).Values[0]; - } - if (value is PdfName) - { - return ((PdfName)value).Value; - } - if (value is PdfString) - { - return ((PdfString)value).Value; - } - return null; - } - - public long? GetParamAsInt(string name) - { - if (Values.ContainsKey(name) == false) { return null; } - - IPdfElement value = Values[name]; - if (value is PdfArray) - { - value = ((PdfArray)value).Values[0]; - } - if (value is PdfInteger) - { - return ((PdfInteger)value).Value; - } - return null; - } - - public byte[] GetParamAsStream(string name) - { - if (Values.ContainsKey(name) == false) { return null; } - - IPdfElement value = Values[name]; - if (value is PdfArray) - { - PdfArray array = value as PdfArray; - MemoryStream memStream = new MemoryStream(); - foreach (IPdfElement elem in array.Values) - { - PdfStream stream = elem as PdfStream; - if (stream == null) { continue; } - memStream.Write(stream.Data, 0, stream.Data.Length); - } - if (memStream.Length > 0) - { - return memStream.ToArray(); - } - return null; - } - if (value is PdfStream) - { - return ((PdfStream)value).Data; - } - return null; - } - - } -} diff --git a/VAR.PdfTools/PdfElements/PdfElementTypes.cs b/VAR.PdfTools/PdfElements/PdfElementTypes.cs deleted file mode 100644 index 88e6b5f..0000000 --- a/VAR.PdfTools/PdfElements/PdfElementTypes.cs +++ /dev/null @@ -1,18 +0,0 @@ -namespace VAR.PdfTools.PdfElements -{ - public enum PdfElementTypes - { - Undefined, - Boolean, - Integer, - Real, - String, - Name, - Array, - Dictionary, - Null, - ObjectReference, - Object, - Stream, - }; -} diff --git a/VAR.PdfTools/PdfElements/PdfElementUtils.cs b/VAR.PdfTools/PdfElements/PdfElementUtils.cs deleted file mode 100644 index 38fa225..0000000 --- a/VAR.PdfTools/PdfElements/PdfElementUtils.cs +++ /dev/null @@ -1,56 +0,0 @@ -namespace VAR.PdfTools.PdfElements -{ - public static class PdfElementUtils - { - public static double GetReal(IPdfElement elem, double defaultValue) - { - if (elem == null) - { - return defaultValue; - } - if (elem is PdfInteger) - { - return ((PdfInteger)elem).Value; - } - if (elem is PdfReal) - { - return ((PdfReal)elem).Value; - } - return defaultValue; - } - - public static long GetInt(IPdfElement elem, long defaultValue) - { - if (elem == null) - { - return defaultValue; - } - if (elem is PdfInteger) - { - return ((PdfInteger)elem).Value; - } - if (elem is PdfReal) - { - return (long)((PdfReal)elem).Value; - } - return defaultValue; - } - - public static string GetString(IPdfElement elem, string defaultValue) - { - if (elem == null) - { - return defaultValue; - } - if (elem is PdfString) - { - return ((PdfString)elem).Value; - } - if (elem is PdfName) - { - return ((PdfName)elem).Value; - } - return defaultValue; - } - } -} diff --git a/VAR.PdfTools/PdfElements/PdfInteger.cs b/VAR.PdfTools/PdfElements/PdfInteger.cs deleted file mode 100644 index d7280e2..0000000 --- a/VAR.PdfTools/PdfElements/PdfInteger.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace VAR.PdfTools.PdfElements -{ - public class PdfInteger : IPdfElement - { - public PdfElementTypes Type { get { return PdfElementTypes.Integer; } } - public long Value { get; set; } - } -} diff --git a/VAR.PdfTools/PdfElements/PdfName.cs b/VAR.PdfTools/PdfElements/PdfName.cs deleted file mode 100644 index 76f0280..0000000 --- a/VAR.PdfTools/PdfElements/PdfName.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace VAR.PdfTools.PdfElements -{ - public class PdfName : IPdfElement - { - public PdfElementTypes Type { get { return PdfElementTypes.Name; } } - public string Value { get; set; } - } -} diff --git a/VAR.PdfTools/PdfElements/PdfNull.cs b/VAR.PdfTools/PdfElements/PdfNull.cs deleted file mode 100644 index 0652834..0000000 --- a/VAR.PdfTools/PdfElements/PdfNull.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace VAR.PdfTools.PdfElements -{ - public class PdfNull : IPdfElement - { - public PdfElementTypes Type { get { return PdfElementTypes.Null; } } - } -} diff --git a/VAR.PdfTools/PdfElements/PdfObject.cs b/VAR.PdfTools/PdfElements/PdfObject.cs deleted file mode 100644 index 8f65e7c..0000000 --- a/VAR.PdfTools/PdfElements/PdfObject.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace VAR.PdfTools.PdfElements -{ - public class PdfObject : IPdfElement - { - public PdfElementTypes Type { get { return PdfElementTypes.Object; } } - public int ObjectID { get; set; } - public int ObjectGeneration { get; set; } - public IPdfElement Data { get; set; } - public int UsageCount { get; set; } - } -} diff --git a/VAR.PdfTools/PdfElements/PdfObjectReference.cs b/VAR.PdfTools/PdfElements/PdfObjectReference.cs deleted file mode 100644 index c777333..0000000 --- a/VAR.PdfTools/PdfElements/PdfObjectReference.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace VAR.PdfTools.PdfElements -{ - public class PdfObjectReference : IPdfElement - { - public PdfElementTypes Type { get { return PdfElementTypes.ObjectReference; } } - public int ObjectID { get; set; } - public int ObjectGeneration { get; set; } - } -} diff --git a/VAR.PdfTools/PdfElements/PdfReal.cs b/VAR.PdfTools/PdfElements/PdfReal.cs deleted file mode 100644 index 19a5d07..0000000 --- a/VAR.PdfTools/PdfElements/PdfReal.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace VAR.PdfTools.PdfElements -{ - public class PdfReal : IPdfElement - { - public PdfElementTypes Type { get { return PdfElementTypes.Real; } } - public double Value { get; set; } - } -} diff --git a/VAR.PdfTools/PdfElements/PdfStream.cs b/VAR.PdfTools/PdfElements/PdfStream.cs deleted file mode 100644 index 4d4b5c0..0000000 --- a/VAR.PdfTools/PdfElements/PdfStream.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace VAR.PdfTools.PdfElements -{ - public class PdfStream : IPdfElement - { - public PdfElementTypes Type { get { return PdfElementTypes.Stream; } } - public PdfDictionary Dictionary { get; set; } - public byte[] Data { get; set; } - - public byte[] OriginalData { get; set; } - public IPdfElement OriginalFilter { get; set; } - } -} diff --git a/VAR.PdfTools/PdfElements/PdfString.cs b/VAR.PdfTools/PdfElements/PdfString.cs deleted file mode 100644 index 544a488..0000000 --- a/VAR.PdfTools/PdfElements/PdfString.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace VAR.PdfTools.PdfElements -{ - public class PdfString : IPdfElement - { - public PdfElementTypes Type { get { return PdfElementTypes.String; } } - public string Value { get; set; } - } -} diff --git a/VAR.PdfTools/PdfFilters.cs b/VAR.PdfTools/PdfFilters.cs deleted file mode 100644 index 8249914..0000000 --- a/VAR.PdfTools/PdfFilters.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System; -using System.IO; -using System.IO.Compression; - -namespace VAR.PdfTools -{ - public static class PdfFilters - { - public class FlateDecode - { - public byte[] Encode(byte[] streamData) - { - throw new NotImplementedException("FlateFilter.Encode: Not implemented"); - } - - public static byte[] Decode(byte[] streamData) - { - MemoryStream msInput = new MemoryStream(streamData); - MemoryStream msOutput = new MemoryStream(); - - // It seems to work when skipping the first two bytes. - byte header; - header = (byte)msInput.ReadByte(); - header = (byte)msInput.ReadByte(); - - DeflateStream zip = new DeflateStream(msInput, CompressionMode.Decompress, true); - int cbRead; - byte[] abResult = new byte[1024]; - do - { - cbRead = zip.Read(abResult, 0, abResult.Length); - if (cbRead > 0) - { - msOutput.Write(abResult, 0, cbRead); - } - } - while (cbRead > 0); - zip.Close(); - msOutput.Flush(); - if (msOutput.Length >= 0) - { - msOutput.Capacity = (int)msOutput.Length; - return msOutput.GetBuffer(); - } - return null; - } - } - - } -} diff --git a/VAR.PdfTools/PdfFont.cs b/VAR.PdfTools/PdfFont.cs deleted file mode 100644 index e0384bc..0000000 --- a/VAR.PdfTools/PdfFont.cs +++ /dev/null @@ -1,215 +0,0 @@ -using System.Collections.Generic; -using VAR.PdfTools.PdfElements; - -namespace VAR.PdfTools -{ - public class PdfFont - { - #region Declarations - - private PdfDictionary _baseData = null; - - private Dictionary _toUnicode = null; - - private Dictionary _widths = null; - - private double _height = 1.0; - - private string _name = string.Empty; - - private bool _tainted = false; - - #endregion - - #region Properties - - public PdfDictionary BaseData { get { return _baseData; } } - - public double Height { get { return _height; } } - - public string Name { get { return _name; } set { _name = value; } } - - public bool Tainted { get { return _tainted; } } - - #endregion - - #region Life cycle - - public PdfFont(PdfDictionary baseData) - { - _baseData = baseData; - string type = baseData.GetParamAsString("Type"); - if (type != "Font") - { - // NOTE: Type="Font" is Required by the standard, continuing anyway - _tainted = true; - } - - PrepareSizes(baseData); - } - - #endregion - - #region Private methods - - private void PrepareSizes(PdfDictionary baseData) - { - // Set "Times-Roman" as default basefont sizes - _widths = PdfStandar14FontMetrics.Times_Roman.Widths; - _height = PdfStandar14FontMetrics.Times_Roman.ApproxHeight; - - if (baseData.Values.ContainsKey("ToUnicode")) - { - byte[] toUnicodeStream = ((PdfStream)baseData.Values["ToUnicode"]).Data; - PdfParser parser = new PdfParser(toUnicodeStream); - _toUnicode = parser.ParseToUnicode(); - } - - string baseFont = _baseData.GetParamAsString("BaseFont"); - if (string.IsNullOrEmpty(baseFont)) - { - SetBaseFontSizes(baseFont); - } - - if (_baseData.Values.ContainsKey("FirstChar") && _baseData.Values.ContainsKey("LastChar") && _baseData.Values.ContainsKey("Widths")) - { - ParseSizes(); - } - } - - private void ParseSizes() - { - double glyphSpaceToTextSpace = 1000.0; // TODO: PdfFont.ParseSizes: SubType:Type3 Uses a FontMatrix that may not correspond to 1/1000th - _widths = new Dictionary(); - char firstChar = (char)_baseData.GetParamAsInt("FirstChar"); - char lastChar = (char)_baseData.GetParamAsInt("LastChar"); - PdfArray widths = _baseData.Values["Widths"] as PdfArray; - char actualChar = firstChar; - foreach (IPdfElement elem in widths.Values) - { - double width = PdfElementUtils.GetReal(elem, 500); - if (width < 0.0001f && width > -0.0001f) { width = 500; } - _widths.Add(actualChar, width / glyphSpaceToTextSpace); - actualChar++; - } - // FIMXE: Calculate real height - } - - private void SetBaseFontSizes(string baseFont) - { - if (baseFont == "Times-Roman") - { - _widths = PdfStandar14FontMetrics.Times_Roman.Widths; - _height = PdfStandar14FontMetrics.Times_Roman.ApproxHeight; - } - if (baseFont == "Times-Bold") - { - _widths = PdfStandar14FontMetrics.Times_Bold.Widths; - _height = PdfStandar14FontMetrics.Times_Bold.ApproxHeight; - } - if (baseFont == "Times-Italic") - { - _widths = PdfStandar14FontMetrics.Times_Italic.Widths; - _height = PdfStandar14FontMetrics.Times_Italic.ApproxHeight; - } - if (baseFont == "Times-BoldItalic") - { - _widths = PdfStandar14FontMetrics.Times_BoldItalic.Widths; - _height = PdfStandar14FontMetrics.Times_BoldItalic.ApproxHeight; - } - if (baseFont == "Helvetica") - { - _widths = PdfStandar14FontMetrics.Helvetica.Widths; - _height = PdfStandar14FontMetrics.Helvetica.ApproxHeight; - } - if (baseFont == "Helvetica-Bold") - { - _widths = PdfStandar14FontMetrics.Helvetica_Bold.Widths; - _height = PdfStandar14FontMetrics.Helvetica_Bold.ApproxHeight; - } - if (baseFont == "Helvetica-Oblique") - { - _widths = PdfStandar14FontMetrics.Helvetica_Oblique.Widths; - _height = PdfStandar14FontMetrics.Helvetica_Oblique.ApproxHeight; - } - if (baseFont == "Helvetica-BoldOblique") - { - _widths = PdfStandar14FontMetrics.Helvetica_BoldOblique.Widths; - _height = PdfStandar14FontMetrics.Helvetica_BoldOblique.ApproxHeight; - } - if (baseFont == "Courier") - { - _widths = PdfStandar14FontMetrics.Courier.Widths; - _height = PdfStandar14FontMetrics.Courier.ApproxHeight; - } - if (baseFont == "Courier-Bold") - { - _widths = PdfStandar14FontMetrics.Courier_Bold.Widths; - _height = PdfStandar14FontMetrics.Courier_Bold.ApproxHeight; - } - if (baseFont == "Courier-Oblique") - { - _widths = PdfStandar14FontMetrics.Courier_Oblique.Widths; - _height = PdfStandar14FontMetrics.Courier_Oblique.ApproxHeight; - } - if (baseFont == "Courier-BoldOblique") - { - _widths = PdfStandar14FontMetrics.Courier_BoldOblique.Widths; - _height = PdfStandar14FontMetrics.Courier_BoldOblique.ApproxHeight; - } - if (baseFont == "Symbol") - { - _widths = PdfStandar14FontMetrics.Symbol.Widths; - _height = PdfStandar14FontMetrics.Symbol.ApproxHeight; - } - if (baseFont == "ZapfDingbats") - { - _widths = PdfStandar14FontMetrics.ZapfDingbats.Widths; - _height = PdfStandar14FontMetrics.ZapfDingbats.ApproxHeight; - } - } - - #endregion - - #region Public methods - - public string ToUnicode(char character) - { - if (_toUnicode == null) - { - // TODO: PdfFont.ToUnicode: use standar tables - return new string(character, 1); - } - - if (_toUnicode.ContainsKey(character)) - { - return _toUnicode[character]; - } - - return new string(character, 1); - } - - public double GetCharWidth(char character) - { - double charWidth = 0; - if (_widths == null) - { - return charWidth; - } - if (_widths.ContainsKey(character)) - { - charWidth = _widths[character]; - } - - // NOTE: Convert "Zero" to default width of 0.5 - if (charWidth <= 0.0001) - { - charWidth = 0.5; - } - - return charWidth; - } - - #endregion - } -} diff --git a/VAR.PdfTools/PdfPageRenderer.cs b/VAR.PdfTools/PdfPageRenderer.cs deleted file mode 100644 index 0549d88..0000000 --- a/VAR.PdfTools/PdfPageRenderer.cs +++ /dev/null @@ -1,210 +0,0 @@ -using System; -using System.Drawing; -using System.Drawing.Drawing2D; -using System.Drawing.Imaging; -using VAR.PdfTools.Maths; - -namespace VAR.PdfTools -{ - public class PdfPageRenderer - { - private PdfDocumentPage _page; - private PdfTextExtractor _pdfTextExtractor; - private Rect _pageRect; - private int _pageWidth; - private int _pageHeight; - private int _scale = 10; - - private const int MaxSize = 10000; - - - public PdfTextExtractor Extractor { get { return _pdfTextExtractor; } } - - public PdfPageRenderer(PdfDocumentPage page) - { - _page = page; - _pdfTextExtractor = new PdfTextExtractor(_page); - InitPage(); - } - - public PdfPageRenderer(PdfTextExtractor pdfTextExtractor) - { - _pdfTextExtractor = pdfTextExtractor; - _page = pdfTextExtractor.Page; - InitPage(); - } - - private void InitPage() - { - _pageRect = _pdfTextExtractor.GetRect(); - _pageWidth = (int)Math.Ceiling(_pageRect.XMax - _pageRect.XMin); - _pageHeight = (int)Math.Ceiling(_pageRect.YMax - _pageRect.YMin); - while ((_pageWidth * _scale) > MaxSize) { _scale--; } - while ((_pageHeight * _scale) > MaxSize) { _scale--; } - if (_scale <= 0) { _scale = 1; } - } - - public Bitmap Render() - { - if (_pdfTextExtractor.Elements.Count == 0) - { - // Nothing to render - Bitmap emptyBmp = new Bitmap(100, 200, PixelFormat.Format32bppArgb); - using (Graphics gcEmpty = Graphics.FromImage(emptyBmp)) - gcEmpty.Clear(Color.White); - return emptyBmp; - } - - // Prepare image - Bitmap bmp = new Bitmap(_pageWidth * _scale, _pageHeight * _scale, PixelFormat.Format32bppArgb); - Graphics gc = Graphics.FromImage(bmp); - gc.Clear(Color.White); - - // Draw text elements of the page - using (Pen penTextElem = new Pen(Color.Blue)) - using (Pen penCharElem = new Pen(Color.Navy)) - { - foreach (PdfTextElement textElement in _pdfTextExtractor.Elements) - { - DrawTextElement(textElement, gc, penTextElem, penCharElem, _scale, _pageHeight, _pageRect.XMin, _pageRect.YMin, Brushes.Black); - } - } - - gc.Dispose(); - return bmp; - } - - public Bitmap RenderColumn(PdfTextElementColumn columnData, Bitmap bmp = null) - { - Graphics gc; - if (bmp == null) - { - bmp = new Bitmap(_pageWidth * _scale, _pageHeight * _scale, PixelFormat.Format32bppArgb); - gc = Graphics.FromImage(bmp); - gc.Clear(Color.White); - } - else - { - gc = Graphics.FromImage(bmp); - } - - // Draw text elements of the column header - using (Pen penTextElem = new Pen(Color.Green)) - using (Pen penCharElem = new Pen(Color.DarkGreen)) - { - DrawTextElement(columnData.HeadTextElement, gc, penTextElem, penCharElem, _scale, _pageHeight, _pageRect.XMin, _pageRect.YMin, Brushes.Olive); - } - - // Draw text elements of the column - using (Pen penTextElem = new Pen(Color.Red)) - using (Pen penCharElem = new Pen(Color.DarkRed)) - { - foreach (PdfTextElement textElement in columnData.Elements) - { - DrawTextElement(textElement, gc, penTextElem, penCharElem, _scale, _pageHeight, _pageRect.XMin, _pageRect.YMin, Brushes.OrangeRed); - } - } - - // Draw column extents - using (Pen penColumn = new Pen(Color.Red)) - { - float y = (float)(_pageRect.YMax - columnData.Y); - float x1 = (float)(columnData.X1 - _pageRect.XMin); - float x2 = (float)(columnData.X2 - _pageRect.XMin); - - gc.DrawLine(penColumn, x1 * _scale, y * _scale, x2 * _scale, y * _scale); - gc.DrawLine(penColumn, x1 * _scale, y * _scale, x1 * _scale, _pageHeight * _scale); - gc.DrawLine(penColumn, x2 * _scale, y * _scale, x2 * _scale, _pageHeight * _scale); - } - - gc.Dispose(); - return bmp; - } - - private static void DrawTextElement(PdfTextElement textElement, Graphics gc, Pen penTextElem, Pen penCharElem, int scale, int pageHeight, double pageXMin, double pageYMin, Brush brushText) - { - if (textElement == null) { return; } - double textElementX = textElement.GetX() - pageXMin; - double textElementY = textElement.GetY() - pageYMin; - double textElementWidth = textElement.VisibleWidth; - double textElementHeight = textElement.VisibleHeight; - string textElementText = textElement.VisibleText; - string textElementFontName = (textElement.Font == null ? string.Empty : textElement.Font.Name); - - if (textElementHeight < 0.0001) { return; } - - double textElementPageX = textElementX; - double textElementPageY = pageHeight - textElementY; - - if (penTextElem != null) - { - DrawRoundedRectangle(gc, penTextElem, - (int)(textElementPageX * scale), - (int)(textElementPageY * scale), - (int)(textElementWidth * scale), - (int)(textElementHeight * scale), - 5); - } - - using (Font font = new Font("Arial", (int)(textElementHeight * scale), GraphicsUnit.Pixel)) - { - foreach (PdfCharElement c in textElement.Characters) - { - gc.DrawString(c.Char, - font, - brushText, - (int)((textElementPageX + c.Displacement) * scale), - (int)(textElementPageY * scale)); - if (penCharElem != null) - { - DrawRoundedRectangle(gc, penCharElem, - (int)((textElementPageX + c.Displacement) * scale), - (int)(textElementPageY * scale), - (int)(c.Width * scale), - (int)(textElementHeight * scale), - 5); - } - } - } - } - - public static GraphicsPath RoundedRect(int x, int y, int width, int height, int radius) - { - int diameter = radius * 2; - Size size = new Size(diameter, diameter); - Rectangle arc = new Rectangle(x, y, diameter, diameter); - GraphicsPath path = new GraphicsPath(); - - // top left arc - path.AddArc(arc, 180, 90); - - // top right arc - arc.X = (x + width) - diameter; - path.AddArc(arc, 270, 90); - - // bottom right arc - arc.Y = (y + height) - diameter; - path.AddArc(arc, 0, 90); - - // bottom left arc - arc.X = x; - path.AddArc(arc, 90, 90); - - path.CloseFigure(); - return path; - } - - public static void DrawRoundedRectangle(Graphics graphics, Pen pen, int x, int y, int width, int height, int cornerRadius) - { - if (graphics == null) - throw new ArgumentNullException("graphics"); - if (pen == null) - throw new ArgumentNullException("pen"); - - using (GraphicsPath path = RoundedRect(x, y, width, height, cornerRadius)) - { - graphics.DrawPath(pen, path); - } - } - } -} diff --git a/VAR.PdfTools/PdfParser.cs b/VAR.PdfTools/PdfParser.cs deleted file mode 100644 index 26a84d9..0000000 --- a/VAR.PdfTools/PdfParser.cs +++ /dev/null @@ -1,1183 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.IO; -using System.Linq; -using System.Text; -using VAR.PdfTools.PdfElements; - -namespace VAR.PdfTools -{ - public class PdfParser - { - #region Declarations - - private byte[] _stream = null; - private long _streamPosition = 0; - - private string _decimalSeparator = "."; - - #endregion - - #region Creator - - public PdfParser(byte[] stream) - { - _stream = stream; - } - - #endregion - - #region Utility methods - - private int ByteHexValue(byte character) - { - if (character >= 0x30 && character <= 0x39) - { - return (character - 0x30); - } - if (character >= 0x41 && character <= 0x46) - { - return 10 + (character - 0x41); - } - if (character >= 0x61 && character <= 0x66) - { - return 10 + (character - 0x61); - } - return 0; - } - - private byte[] GetRawData(long start, long size) - { - byte[] newArray = new byte[size]; - Array.Copy(_stream, start, newArray, 0, size); - return newArray; - } - - private byte[] GetRawData(long length) - { - var memStream = new MemoryStream(); - var byteArray = new byte[1]; - - for (long i = 0; i < length; i++) - { - byteArray[0] = PeekChar(); - NextChar(); - memStream.Write(byteArray, 0, 1); - } - - return memStream.ToArray(); - } - - private bool TestMarker(long position, char[] marker) - { - for(int i = 0; i < marker.Length; i++) - { - if ((position + i) >= _stream.Length) { return false; } - if(_stream[position+i] != marker[i]) { return false; } - } - return true; - } - - private long MeasureToMarkers(char[][] markers) - { - long position = _streamPosition; - do - { - foreach(char[] marker in markers) - { - if (TestMarker(position, marker)) - { - return (position - _streamPosition); - } - } - position++; - } while (position < _stream.Length); - return -1; - } - - private byte PeekChar() - { - if (_streamPosition >= _stream.Length) - { - return 0; - } - return _stream[_streamPosition]; - } - - private byte PeekNextChar() - { - return PeekNextChar(1); - } - - private byte PeekNextChar(int offset) - { - if ((_streamPosition + offset) >= _stream.Length) - { - return 0; - } - return _stream[_streamPosition + offset]; - } - - private bool NextChar() - { - _streamPosition++; - if (_streamPosition >= _stream.Length) - { - return false; - } - return true; - } - - private bool IsWhitespace(byte character) - { - if ( - character == 0x00 || // NULL - character == 0x09 || // Horizontal Tab (HT) - character == 0x0A || // Line Feed (LF) - character == 0x0C || // Form Feed (FF) - character == 0x0D || // Carriage Return (CR) - character == 0x20 || // Space (SP) - false) - { - return true; - } - return false; - } - - private bool IsEndOfLine(byte character) - { - byte lineFeed = 0x0A; - byte carriageReturn = 0x0D; - if ( - character == lineFeed || - character == carriageReturn || - false) - { - return true; - } - return false; - } - - private bool IsDelimiter(byte character) - { - if ( - character == '(' || - character == ')' || - character == '<' || - character == '>' || - character == '[' || - character == ']' || - character == '}' || - character == '{' || - character == '%' || - false) - { - return true; - } - return false; - } - - private bool IsDigit(byte character) - { - if (character >= '0' && character <= '9') - { - return true; - } - return false; - } - - private void SkipWhitespace() - { - while (IsWhitespace(PeekChar())) - { - _streamPosition++; - if (_streamPosition >= _stream.Length) - { - // EOS - break; - } - } - } - - private void SkipWhitespaceBack() - { - while (IsWhitespace(PeekChar())) - { - if (_streamPosition == 0) - { - break; - } - _streamPosition--; - } - } - - private void SkipDigitsBack() - { - while (IsDigit(PeekChar())) - { - if (_streamPosition == 0) - { - break; - } - _streamPosition--; - } - } - - private void SkipEndOfLine() - { - byte lineFeed = 0x0A; - byte carriageReturn = 0x0D; - if (PeekChar() == carriageReturn) - { - NextChar(); - if (_streamPosition < _stream.Length) - { - if (_stream[_streamPosition] == lineFeed) - { - _streamPosition++; - } - } - return; - } - if (PeekChar() == lineFeed) - { - NextChar(); - return; - } - } - - private void SkipToEndOfLine() - { - while (IsEndOfLine(PeekChar()) == false) - { - if (NextChar() == false) - { - break; - } - } - } - - private void SkipComment() - { - if (PeekChar() != '%') { return; } - SkipToEndOfLine(); - SkipEndOfLine(); - } - - private string ParseComment() - { - if (PeekChar() != '%') { return string.Empty; } - NextChar(); - StringBuilder sbComment = new StringBuilder(); - while (IsEndOfLine(PeekChar()) == false) - { - sbComment.Append((char)PeekChar()); - if (NextChar() == false) - { - break; - } - } - SkipEndOfLine(); - return sbComment.ToString(); - } - - private string ParseToken() - { - SkipWhitespace(); - StringBuilder sbToken = new StringBuilder(); - do - { - byte character = PeekChar(); - if (IsWhitespace(character) || IsDelimiter(character)) - { - break; - } - sbToken.Append((char)character); - NextChar(); - } while (IsEndOfStream() == false); - return sbToken.ToString(); - } - - private IPdfElement ParseElement() - { - IPdfElement obj = null; - byte character = PeekChar(); - byte nextCharacter = PeekNextChar(); - - if (character == 't' || character == 'f') - { - obj = ParseBoolean(); - } - if (character == 'n') - { - obj = ParseNull(); - } - else if (IsDigit(character) || character == '+' || character == '-' || character == '.') - { - obj = ParseNumberOrReference(); - } - else if (character == '(' || (character == '<' && nextCharacter != '<')) - { - obj = ParseString(); - } - else if (character == '/') - { - obj = ParseName(); - } - else if (character == '[') - { - obj = ParseArray(); - } - else if (character == '<' && nextCharacter == '<') - { - obj = ParseDictionary(); - } - return obj; - } - - private PdfBoolean ParseBoolean() - { - if ( - PeekNextChar(0) == 't' && - PeekNextChar(1) == 'r' && - PeekNextChar(2) == 'u' && - PeekNextChar(3) == 'e' - ) - { - NextChar(); - NextChar(); - NextChar(); - NextChar(); - return new PdfBoolean { Value = true }; - } - - if ( - PeekNextChar(0) == 'f' && - PeekNextChar(1) == 'a' && - PeekNextChar(2) == 'l' && - PeekNextChar(3) == 's' && - PeekNextChar(4) == 'e' - ) - { - NextChar(); - NextChar(); - NextChar(); - NextChar(); - NextChar(); - return new PdfBoolean { Value = false }; - } - - return null; - } - - private PdfNull ParseNull() - { - if ( - PeekNextChar(0) == 'n' && - PeekNextChar(1) == 'u' && - PeekNextChar(2) == 'l' && - PeekNextChar(3) == 'l' - ) - { - NextChar(); - NextChar(); - NextChar(); - NextChar(); - return new PdfNull(); - } - - return null; - } - - private IPdfElement ParseNumber() - { - long startPosition = _streamPosition; - bool valid = false; - int dotCount = 0; - StringBuilder sbNumber = new StringBuilder(); - if (PeekChar() == '-') - { - sbNumber.Append('-'); - NextChar(); - } - else if (PeekChar() == '+') - { - NextChar(); - } - while (IsDigit(PeekChar()) || PeekChar() == '.') - { - if (PeekChar() == '.') - { - sbNumber.Append(_decimalSeparator); - dotCount++; - } - else - { - sbNumber.Append((char)PeekChar()); - } - NextChar(); - valid = true; - } - if (valid && dotCount <= 1) - { - if (dotCount == 0) - { - PdfInteger obj = new PdfInteger(); - obj.Value = Convert.ToInt32(sbNumber.ToString()); - return obj; - } - if (dotCount == 1) - { - PdfReal obj = new PdfReal(); - obj.Value = Convert.ToDouble(sbNumber.ToString(), CultureInfo.InvariantCulture); - return obj; - } - } - throw new Exception(string.Format("Expected number at {0}, found \"{1}\"", startPosition, sbNumber.ToString())); - } - - private IPdfElement ParseNumberOrReference() - { - IPdfElement obj = ParseNumber(); - PdfInteger number = obj as PdfInteger; - if (number == null) - { - return obj; - } - - // Try to get an indirect object reference - long streamPosition = _streamPosition; - SkipWhitespace(); - if (char.IsDigit((char)PeekChar()) == false) - { - _streamPosition = streamPosition; - return obj; - } - IPdfElement objectGeneration = ParseNumber(); - if((objectGeneration is PdfInteger) == false) - { - _streamPosition = streamPosition; - return obj; - } - SkipWhitespace(); - if (PeekChar() != 'R') - { - _streamPosition = streamPosition; - return obj; - } - NextChar(); - PdfObjectReference objRef = new PdfObjectReference(); - objRef.ObjectID = (int)number.Value; - objRef.ObjectGeneration = (int)((PdfInteger)objectGeneration).Value; - return objRef; - } - - private PdfString ParseString() - { - if (PeekChar() == '(') - { - StringBuilder sbString = new StringBuilder(); - int depth = 1; - NextChar(); - do - { - byte character = PeekChar(); - if (character == '(') - { - depth++; - sbString.Append((char)character); - } - else if (character == ')') - { - depth--; - if (depth == 0) - { - NextChar(); - break; - } - else - { - sbString.Append((char)character); - } - } - else if (character == '\\') - { - if (NextChar() == false) - { - throw new Exception("Unexpected end of string and file"); - } - character = PeekChar(); - if (character == 'n') - { - sbString.Append('\n'); - } - else if (character == 'r') - { - sbString.Append('\n'); - } - else if (character == 't') - { - sbString.Append('\t'); - } - else if (character == 'b') - { - sbString.Append('\b'); - } - else if (character == 'f') - { - sbString.Append('\f'); - } - else if (character == '(') - { - sbString.Append('('); - } - else if (character == ')') - { - sbString.Append(')'); - } - else if (character == '\\') - { - sbString.Append('\\'); - } - else if (IsEndOfLine(character)) - { - SkipEndOfLine(); - continue; - } - else if (IsDigit(character)) - { - if (_streamPosition + 2 >= _stream.Length) - { - throw new Exception("Unexpected end of string and file"); - } - StringBuilder sbOctal = new StringBuilder(); - sbOctal.Append((char)character); - NextChar(); - sbOctal.Append((char)PeekChar()); - NextChar(); - sbOctal.Append((char)PeekChar()); - char newCharacter = (char)(Convert.ToInt32(sbOctal.ToString(), 8)); - } - } - else - { - sbString.Append((Char)character); - } - if (NextChar() == false) - { - throw new Exception("Unexpected end of string and file"); - } - } while (IsEndOfStream() == false); - - PdfString obj = new PdfString(); - obj.Value = sbString.ToString(); - return obj; - } - else if (PeekChar() == '<') - { - StringBuilder sbString = new StringBuilder(); - NextChar(); - do - { - byte character = PeekChar(); - if (character == '>') { break; } - NextChar(); - byte nextCharacter = PeekChar(); - NextChar(); - byte realChar = (byte)(ByteHexValue(character) * 16 + ByteHexValue(nextCharacter)); - sbString.Append((Char)realChar); - } while (IsEndOfStream() == false); - NextChar(); - - PdfString obj = new PdfString(); - obj.Value = sbString.ToString(); - return obj; - } - return null; - } - - private PdfName ParseName() - { - if (PeekChar() != '/') - { - return null; - } - NextChar(); - StringBuilder sbName = new StringBuilder(); - do - { - byte character = PeekChar(); - if (IsDelimiter(character) || character == '/') - { - break; - } - else if (character == '#') - { - byte realChar = 0; - NextChar(); - character = PeekChar(); - realChar = (byte)(ByteHexValue(character) * 16); - NextChar(); - character = PeekChar(); - realChar += (byte)ByteHexValue(character); - sbName.Append((char)realChar); - } - else if (character > 0x20 && character < 0x7F) - { - sbName.Append((char)character); - } - else - { - break; - } - if (NextChar() == false) - { - throw new Exception("Unexpected end of name and file"); - } - } while (IsEndOfStream() == false); - - PdfName obj = new PdfName(); - obj.Value = sbName.ToString(); - return obj; - } - - private PdfArray ParseArray() - { - if (PeekChar() != '[') - { - return null; - } - NextChar(); - SkipWhitespace(); - - PdfArray array = new PdfArray(); - do - { - byte character = PeekChar(); - - if (character == ']') - { - NextChar(); - break; - } - else - { - IPdfElement obj = ParseElement(); - if(obj == null) - { - break; - //throw new Exception(string.Format("ParseArray: Error parsing item at: {0}", _streamPosition)); - } - array.Values.Add(obj); - } - SkipWhitespace(); - } while (IsEndOfStream() == false); - return array; - } - - private PdfDictionary ParseDictionary() - { - if (PeekChar() != '<' || PeekNextChar() != '<') - { - return null; - } - NextChar(); - NextChar(); - SkipWhitespace(); - - PdfName previousName = null; - PdfDictionary dict = new PdfDictionary(); - do - { - byte character = PeekChar(); - byte nextCharacter = PeekNextChar(); - - if (character == '>' && nextCharacter == '>') - { - NextChar(); - NextChar(); - break; - } - else if (character == '/') - { - PdfName name = ParseName(); - previousName = name; - SkipWhitespace(); - IPdfElement obj = ParseElement(); - if (obj is PdfNull) - { - dict.Values.Remove(name.Value); - } - else - { - previousName = name; - if (dict.Values.ContainsKey(name.Value)) - { - dict.Values[name.Value] = obj; - } - else - { - dict.Values.Add(name.Value, obj); - } - } - SkipWhitespace(); - } - else - { - throw new Exception(string.Format("Error parsing Dictionary at: {0}", _streamPosition)); - } - - } while (IsEndOfStream() == false); - return dict; - } - - public string ReencodeStringToUTF16BE(string strIn) - { - byte[] byteArray = strIn.Select(c => (byte)c).ToArray(); - if((byteArray.Length % 2) == 1) - { - byte[] newByteArray = new byte[byteArray.Length + 1]; - newByteArray[0] = 0x00; - Array.Copy(byteArray, 0, newByteArray, 1, byteArray.Length); - byteArray = newByteArray; - } - return Encoding.BigEndianUnicode.GetString(byteArray); - } - - public IPdfElement SearchObjectID(List knownObjects, long objectID) - { - foreach (PdfObject obj in knownObjects) - { - if (obj.ObjectID == objectID) - { - return obj.Data; - } - } - return null; - } - - #endregion - - #region Public methods - - public PdfObject ParseObject(List knownObjects) - { - PdfObject obj = null; - long startPosition = _streamPosition; - do - { - SkipWhitespace(); - byte character = PeekChar(); - - if (character == '%') - { - SkipComment(); - } - else if (IsDigit(character)) - { - IPdfElement objectID = ParseNumber(); - SkipWhitespace(); - IPdfElement objectGeneration = ParseNumber(); - SkipWhitespace(); - string token = ParseToken(); - if (token == "obj") - { - SkipWhitespace(); - IPdfElement element = ParseElement(); - string endToken = ParseToken(); - - // Intercept streams - if (endToken == "stream") - { - PdfDictionary streamDict = element as PdfDictionary; - if (streamDict == null) - { - throw new Exception(string.Format("Stream after a not dictionary element at: {0}", _streamPosition)); - } - SkipEndOfLine(); - - // Find the length of the stream - long length = -1; - if (streamDict.Values.ContainsKey("Length") ) - { - length = PdfElementUtils.GetInt(streamDict.Values["Length"], -1); - if (length == -1 && streamDict.Values["Length"] is PdfObjectReference) - { - IPdfElement lenghtObj = SearchObjectID(knownObjects, ((PdfObjectReference) streamDict.Values["Length"]).ObjectID); - length = PdfElementUtils.GetInt(lenghtObj, -1); - } - } - if(length == -1) - { - byte lineFeed = 0x0A; - byte carriageReturn = 0x0D; - length = MeasureToMarkers(new char[][] { - new char[] {(char)carriageReturn, (char)lineFeed, 'e', 'n', 'd', 's', 't', 'r', 'e', 'a', 'm'}, - new char[] {(char)lineFeed, 'e', 'n', 'd', 's', 't', 'r', 'e', 'a', 'm'}, - new char[] {'e', 'n', 'd', 's', 't', 'r', 'e', 'a', 'm', (char)lineFeed}, - new char[] {'e', 'n', 'd', 's', 't', 'r', 'e', 'a', 'm', (char)carriageReturn, (char)lineFeed}, - }); - } - - // Get the stream - byte[] streamBody = GetRawData(length); - SkipEndOfLine(); - endToken = ParseToken(); - if (endToken != "endstream") - { - throw new Exception(string.Format("Expected \"endstream\" token, \"{0}\" found at: {1}", token, _streamPosition)); - } - SkipWhitespace(); - endToken = ParseToken(); - PdfStream stream = new PdfStream(); - stream.Dictionary = streamDict; - stream.Data = streamBody; - element = stream; - } - - if (endToken == "endobj") - { - obj = new PdfObject(); - obj.ObjectID = (int)((PdfInteger)objectID).Value; - obj.ObjectGeneration = (int)((PdfInteger)objectGeneration).Value; - obj.Data = element; - break; - } - } - } - else - { - long streamPosition = _streamPosition; - string token = ParseToken(); - if (token == "startxref") - { - // TODO: PdfParser: Ignoring startxref for now - SkipEndOfLine(); - SkipToEndOfLine(); - SkipEndOfLine(); - SkipToEndOfLine(); - SkipEndOfLine(); - SkipWhitespace(); - continue; - } - if (token == "xref") - { - // TODO: PdfParser: Ignoring xref for now - SkipToEndOfLine(); - SkipEndOfLine(); - do - { - SkipWhitespace(); - IPdfElement objNumber = ParseNumber(); - SkipWhitespace(); - objNumber = ParseNumber(); - SkipEndOfLine(); - PdfInteger refNumber = objNumber as PdfInteger; - for (int i = 0; i < refNumber.Value; i++) - { - SkipToEndOfLine(); - SkipEndOfLine(); - } - long currentPosition = _streamPosition; - IPdfElement testElem = ParseElement(); - _streamPosition = currentPosition; - if((testElem is PdfInteger) == false) - { - break; - } - } while (IsEndOfStream() == false); - continue; - } - if (token == "trailer") - { - // TODO: PdfParser: Ignoring trailer for now - SkipEndOfLine(); - ParseElement(); - SkipWhitespace(); - - SkipToEndOfLine(); - SkipEndOfLine(); - SkipToEndOfLine(); - SkipEndOfLine(); - SkipToEndOfLine(); - SkipEndOfLine(); - SkipWhitespace(); - continue; - } - - // Try to find an object marker - byte lineFeed = 0x0A; - byte carriageReturn = 0x0D; - long distToObject = MeasureToMarkers(new char[][] { - new char[] {' ', 'o', 'b', 'j', (char)lineFeed}, - new char[] {' ', 'o', 'b', 'j', (char)carriageReturn, (char)lineFeed}, - }); - if (distToObject > 0) - { - // Object marker found, backtrack and retry - long originalPosition = _streamPosition; - _streamPosition += distToObject; - long marker = _streamPosition; - SkipWhitespaceBack(); - if (_streamPosition == marker) - { - // Abort backtrack, skip garbage - _streamPosition = originalPosition + distToObject + 4; - continue; - } - marker = _streamPosition; - SkipDigitsBack(); - if (_streamPosition == marker) - { - // Abort backtrack, skip garbage - _streamPosition = originalPosition + distToObject + 4; - continue; - } - marker = _streamPosition; - SkipWhitespaceBack(); - if (_streamPosition == marker) - { - // Abort backtrack, skip garbage - _streamPosition = originalPosition + distToObject + 4; - continue; - } - marker = _streamPosition; - SkipDigitsBack(); - if (_streamPosition == marker) - { - // Abort backtrack, skip garbage - _streamPosition = originalPosition + distToObject + 4; - continue; - } - NextChar(); - } - else - { - // No more obj markers found, abort all. - _streamPosition = _stream.Length; - } - } - } while (IsEndOfStream() == false); - return obj; - } - - public List ParseObjectStream(int number, long first) - { - var streamObjects = new List(); - var objectIds = new List(); - for (int i = 0; i < number; i++) - { - SkipWhitespace(); - IPdfElement objectId = ParseElement(); - if (objectId is PdfInteger) - { - objectIds.Add(((PdfInteger)objectId).Value); - } - else - { - throw new System.Exception(string.Format("Unexpected element parsing ObjectStream at: {0}", _streamPosition)); - } - SkipWhitespace(); - ParseElement(); - } - _streamPosition = (int)first; - for (int i = 0; i < number; i++) - { - SkipWhitespace(); - IPdfElement elem = ParseElement(); - if (elem == null) - { - throw new System.Exception(string.Format("Unexpected error parsing ObjectStream at: {0}", _streamPosition)); - } - - PdfObject objAux = new PdfObject(); - objAux.ObjectGeneration = 0; - objAux.ObjectID = (int)objectIds[i]; - objAux.Data = elem; - streamObjects.Add(objAux); - } - return streamObjects; - } - - public List ParseContent() - { - List actions = new List(); - List elems = new List(); - do - { - SkipWhitespace(); - IPdfElement elem = ParseElement(); - if (elem != null) - { - elems.Add(elem); - } - else - { - string token = ParseToken(); - if (string.IsNullOrEmpty(token)) - { - break; - } - PdfContentAction action = new PdfContentAction(token, elems); - elems = new List(); - actions.Add(action); - if (action.Token == "ID") - { - // Embbed inline image - byte lineFeed = 0x0A; - byte carriageReturn = 0x0D; - long distToObject = MeasureToMarkers(new char[][] { - new char[] {(char)lineFeed, 'E', 'I'}, - new char[] {(char)carriageReturn, (char)lineFeed, 'E', 'I'}, - }); - byte[] imageBody = GetRawData(distToObject); - SkipEndOfLine(); - string endToken = ParseToken(); - action.Parameters.Add(new PdfStream { OriginalData = imageBody, }); - } - } - } while (IsEndOfStream() == false); - return actions; - } - - public Dictionary ParseToUnicode() - { - var toUnicode = new Dictionary(); - long skip = MeasureToMarkers(new char[][] { - new char[] { 'b', 'e', 'g', 'i', 'n', 'c', 'm', 'a', 'p'}, - }); - _streamPosition = skip; - var stack = new List(); - do - { - SkipWhitespace(); - IPdfElement elem = ParseElement(); - if (elem != null) - { - stack.Add(elem); - } - else - { - string token = ParseToken(); - if (token == "begincodespacerange") - { - PdfInteger numCodespaces = stack.Last() as PdfInteger; - if (numCodespaces == null) - { - throw new Exception(string.Format("ParseToUnicode: \"begincodespacerange\" found without preceding count at: {0}", _streamPosition)); - } - for (int i = 0; i < numCodespaces.Value; i++) - { - // Skip CodeSpaceRanges - SkipWhitespace(); - PdfString strStart = ParseString(); - SkipWhitespace(); - PdfString strEnd = ParseString(); - } - SkipWhitespace(); - string endToken = ParseToken(); - if (endToken != "endcodespacerange") - { - throw new Exception(string.Format("ParseToUnicode: Expected \"endcodespacerange\", found \"{0}\", at: {1}", endToken, _streamPosition)); - } - } - else if (token == "beginbfrange") - { - PdfInteger numRanges = stack.Last() as PdfInteger; - if (numRanges == null) - { - throw new Exception(string.Format("ParseToUnicode: \"beginbfrange\" found without preceding count at: {0}", _streamPosition)); - } - for (int i = 0; i < numRanges.Value; i++) - { - SkipWhitespace(); - PdfString pdfStrStart = ParseString(); - SkipWhitespace(); - PdfString pdfStrEnd = ParseString(); - SkipWhitespace(); - IPdfElement pdfElemDest = ParseElement(); - - char chStart = ReencodeStringToUTF16BE(pdfStrStart.Value)[0]; - char chEnd = ReencodeStringToUTF16BE(pdfStrEnd.Value)[0]; - - if(chStart == chEnd && pdfElemDest is PdfString) - { - string strDst = ReencodeStringToUTF16BE(((PdfString)pdfElemDest).Value); - toUnicode.Add(chStart, strDst); - continue; - } - if (chEnd > chStart && pdfElemDest is PdfString) - { - string strDst = ReencodeStringToUTF16BE(((PdfString)pdfElemDest).Value); - char[] chsDest = strDst.ToArray(); - for (char c = chStart; c <= chEnd; c++) - { - toUnicode.Add(c, new string(chsDest)); - chsDest[chsDest.Length - 1]++; - } - continue; - } - if (chEnd > chStart && pdfElemDest is PdfArray) - { - PdfArray array = pdfElemDest as PdfArray; - int length = chEnd - chStart; - for (int j = 0; j <= length; j++) - { - char c = (char)(chStart + j); - string strDst = ReencodeStringToUTF16BE(((PdfString)array.Values[j]).Value); - toUnicode.Add(c, strDst); - } - continue; - } - } - SkipWhitespace(); - string endToken = ParseToken(); - if (endToken != "endbfrange") - { - throw new Exception(string.Format("ParseToUnicode: Expected \"endbfrange\", found \"{0}\", at: {1}", endToken, _streamPosition)); - } - } - else if (token == "beginbfchar") - { - PdfInteger numChars = stack.Last() as PdfInteger; - if (numChars == null) - { - throw new Exception(string.Format("ParseToUnicode: \"beginbfchar\" found without preceding count at: {0}", _streamPosition)); - } - for (int i = 0; i < numChars.Value; i++) - { - SkipWhitespace(); - PdfString pdfStrOrig = ParseString(); - SkipWhitespace(); - PdfString pdfStrDest = ParseString(); - - char chOrig = ReencodeStringToUTF16BE(pdfStrOrig.Value)[0]; - string strDst = ReencodeStringToUTF16BE(((PdfString)pdfStrDest).Value); - toUnicode.Add(chOrig, strDst); - } - SkipWhitespace(); - string endToken = ParseToken(); - if (endToken != "endbfchar") - { - throw new Exception(string.Format("ParseToUnicode: Expected \"endbfchar\", found \"{0}\", at: {1}", endToken, _streamPosition)); - } - } - else - { - // Ignore rest of tokens - } - } - - } while (IsEndOfStream() == false); - return toUnicode; - } - - public bool IsEndOfStream() - { - return _streamPosition >= _stream.Length; - } - - #endregion - } -} diff --git a/VAR.PdfTools/PdfStandar14FontMetrics.cs b/VAR.PdfTools/PdfStandar14FontMetrics.cs deleted file mode 100644 index 37e7c40..0000000 --- a/VAR.PdfTools/PdfStandar14FontMetrics.cs +++ /dev/null @@ -1,2405 +0,0 @@ -using System.Collections.Generic; - -namespace VAR.PdfTools -{ - public class PdfStandar14FontMetrics - { - public class Times_Roman - { - #region Definition - - public static double ApproxHeight = 0.880; - - public static double Ascender = 0.683; - public static double CapHeight = 0.662; - public static double XHeight = 0.450; - public static double Descender = -0.217; - public static Dictionary Widths = new Dictionary() - { - { (char)32, 0.250 }, - { (char)33, 0.333 }, - { (char)34, 0.408 }, - { (char)35, 0.500 }, - { (char)36, 0.500 }, - { (char)37, 0.833 }, - { (char)38, 0.778 }, - { (char)39, 0.333 }, - { (char)40, 0.333 }, - { (char)41, 0.333 }, - { (char)42, 0.500 }, - { (char)43, 0.564 }, - { (char)44, 0.250 }, - { (char)45, 0.333 }, - { (char)46, 0.250 }, - { (char)47, 0.278 }, - { (char)48, 0.500 }, - { (char)49, 0.500 }, - { (char)50, 0.500 }, - { (char)51, 0.500 }, - { (char)52, 0.500 }, - { (char)53, 0.500 }, - { (char)54, 0.500 }, - { (char)55, 0.500 }, - { (char)56, 0.500 }, - { (char)57, 0.500 }, - { (char)58, 0.278 }, - { (char)59, 0.278 }, - { (char)60, 0.564 }, - { (char)61, 0.564 }, - { (char)62, 0.564 }, - { (char)63, 0.444 }, - { (char)64, 0.921 }, - { (char)65, 0.722 }, - { (char)66, 0.667 }, - { (char)67, 0.667 }, - { (char)68, 0.722 }, - { (char)69, 0.611 }, - { (char)70, 0.556 }, - { (char)71, 0.722 }, - { (char)72, 0.722 }, - { (char)73, 0.333 }, - { (char)74, 0.389 }, - { (char)75, 0.722 }, - { (char)76, 0.611 }, - { (char)77, 0.889 }, - { (char)78, 0.722 }, - { (char)79, 0.722 }, - { (char)80, 0.556 }, - { (char)81, 0.722 }, - { (char)82, 0.667 }, - { (char)83, 0.556 }, - { (char)84, 0.611 }, - { (char)85, 0.722 }, - { (char)86, 0.722 }, - { (char)87, 0.944 }, - { (char)88, 0.722 }, - { (char)89, 0.722 }, - { (char)90, 0.611 }, - { (char)91, 0.333 }, - { (char)92, 0.278 }, - { (char)93, 0.333 }, - { (char)94, 0.469 }, - { (char)95, 0.500 }, - { (char)96, 0.333 }, - { (char)97, 0.444 }, - { (char)98, 0.500 }, - { (char)99, 0.444 }, - { (char)100, 0.500 }, - { (char)101, 0.444 }, - { (char)102, 0.333 }, - { (char)103, 0.500 }, - { (char)104, 0.500 }, - { (char)105, 0.278 }, - { (char)106, 0.278 }, - { (char)107, 0.500 }, - { (char)108, 0.278 }, - { (char)109, 0.778 }, - { (char)110, 0.500 }, - { (char)111, 0.500 }, - { (char)112, 0.500 }, - { (char)113, 0.500 }, - { (char)114, 0.333 }, - { (char)115, 0.389 }, - { (char)116, 0.278 }, - { (char)117, 0.500 }, - { (char)118, 0.500 }, - { (char)119, 0.722 }, - { (char)120, 0.500 }, - { (char)121, 0.500 }, - { (char)122, 0.444 }, - { (char)123, 0.480 }, - { (char)124, 0.200 }, - { (char)125, 0.480 }, - { (char)126, 0.541 }, - { (char)161, 0.333 }, - { (char)162, 0.500 }, - { (char)163, 0.500 }, - { (char)164, 0.167 }, - { (char)165, 0.500 }, - { (char)166, 0.500 }, - { (char)167, 0.500 }, - { (char)168, 0.500 }, - { (char)169, 0.180 }, - { (char)170, 0.444 }, - { (char)171, 0.500 }, - { (char)172, 0.333 }, - { (char)173, 0.333 }, - { (char)174, 0.556 }, - { (char)175, 0.556 }, - { (char)177, 0.500 }, - { (char)178, 0.500 }, - { (char)179, 0.500 }, - { (char)180, 0.250 }, - { (char)182, 0.453 }, - { (char)183, 0.350 }, - { (char)184, 0.333 }, - { (char)185, 0.444 }, - { (char)186, 0.444 }, - { (char)187, 0.500 }, - { (char)188, 1.000 }, - { (char)189, 1.000 }, - { (char)191, 0.444 }, - { (char)193, 0.333 }, - { (char)194, 0.333 }, - { (char)195, 0.333 }, - { (char)196, 0.333 }, - { (char)197, 0.333 }, - { (char)198, 0.333 }, - { (char)199, 0.333 }, - { (char)200, 0.333 }, - { (char)202, 0.333 }, - { (char)203, 0.333 }, - { (char)205, 0.333 }, - { (char)206, 0.333 }, - { (char)207, 0.333 }, - { (char)208, 1.000 }, - { (char)225, 0.889 }, - { (char)227, 0.276 }, - { (char)232, 0.611 }, - { (char)233, 0.722 }, - { (char)234, 0.889 }, - { (char)235, 0.310 }, - { (char)241, 0.667 }, - { (char)245, 0.278 }, - { (char)248, 0.278 }, - { (char)249, 0.500 }, - { (char)250, 0.722 }, - { (char)251, 0.500 }, - }; - #endregion - } - - public class Times_Bold - { - #region Definition - - public static double ApproxHeight = 0.880; - - public static double Ascender = 0.683; - public static double CapHeight = 0.676; - public static double XHeight = 0.461; - public static double Descender = -0.217; - public static Dictionary Widths = new Dictionary() - { - { (char)32, 0.250 }, - { (char)33, 0.333 }, - { (char)34, 0.555 }, - { (char)35, 0.500 }, - { (char)36, 0.500 }, - { (char)37, 1.000 }, - { (char)38, 0.833 }, - { (char)39, 0.333 }, - { (char)40, 0.333 }, - { (char)41, 0.333 }, - { (char)42, 0.500 }, - { (char)43, 0.570 }, - { (char)44, 0.250 }, - { (char)45, 0.333 }, - { (char)46, 0.250 }, - { (char)47, 0.278 }, - { (char)48, 0.500 }, - { (char)49, 0.500 }, - { (char)50, 0.500 }, - { (char)51, 0.500 }, - { (char)52, 0.500 }, - { (char)53, 0.500 }, - { (char)54, 0.500 }, - { (char)55, 0.500 }, - { (char)56, 0.500 }, - { (char)57, 0.500 }, - { (char)58, 0.333 }, - { (char)59, 0.333 }, - { (char)60, 0.570 }, - { (char)61, 0.570 }, - { (char)62, 0.570 }, - { (char)63, 0.500 }, - { (char)64, 0.930 }, - { (char)65, 0.722 }, - { (char)66, 0.667 }, - { (char)67, 0.722 }, - { (char)68, 0.722 }, - { (char)69, 0.667 }, - { (char)70, 0.611 }, - { (char)71, 0.778 }, - { (char)72, 0.778 }, - { (char)73, 0.389 }, - { (char)74, 0.500 }, - { (char)75, 0.778 }, - { (char)76, 0.667 }, - { (char)77, 0.944 }, - { (char)78, 0.722 }, - { (char)79, 0.778 }, - { (char)80, 0.611 }, - { (char)81, 0.778 }, - { (char)82, 0.722 }, - { (char)83, 0.556 }, - { (char)84, 0.667 }, - { (char)85, 0.722 }, - { (char)86, 0.722 }, - { (char)87, 1.000 }, - { (char)88, 0.722 }, - { (char)89, 0.722 }, - { (char)90, 0.667 }, - { (char)91, 0.333 }, - { (char)92, 0.278 }, - { (char)93, 0.333 }, - { (char)94, 0.581 }, - { (char)95, 0.500 }, - { (char)96, 0.333 }, - { (char)97, 0.500 }, - { (char)98, 0.556 }, - { (char)99, 0.444 }, - { (char)100, 0.556 }, - { (char)101, 0.444 }, - { (char)102, 0.333 }, - { (char)103, 0.500 }, - { (char)104, 0.556 }, - { (char)105, 0.278 }, - { (char)106, 0.333 }, - { (char)107, 0.556 }, - { (char)108, 0.278 }, - { (char)109, 0.833 }, - { (char)110, 0.556 }, - { (char)111, 0.500 }, - { (char)112, 0.556 }, - { (char)113, 0.556 }, - { (char)114, 0.444 }, - { (char)115, 0.389 }, - { (char)116, 0.333 }, - { (char)117, 0.556 }, - { (char)118, 0.500 }, - { (char)119, 0.722 }, - { (char)120, 0.500 }, - { (char)121, 0.500 }, - { (char)122, 0.444 }, - { (char)123, 0.394 }, - { (char)124, 0.220 }, - { (char)125, 0.394 }, - { (char)126, 0.520 }, - { (char)161, 0.333 }, - { (char)162, 0.500 }, - { (char)163, 0.500 }, - { (char)164, 0.167 }, - { (char)165, 0.500 }, - { (char)166, 0.500 }, - { (char)167, 0.500 }, - { (char)168, 0.500 }, - { (char)169, 0.278 }, - { (char)170, 0.500 }, - { (char)171, 0.500 }, - { (char)172, 0.333 }, - { (char)173, 0.333 }, - { (char)174, 0.556 }, - { (char)175, 0.556 }, - { (char)177, 0.500 }, - { (char)178, 0.500 }, - { (char)179, 0.500 }, - { (char)180, 0.250 }, - { (char)182, 0.540 }, - { (char)183, 0.350 }, - { (char)184, 0.333 }, - { (char)185, 0.500 }, - { (char)186, 0.500 }, - { (char)187, 0.500 }, - { (char)188, 1.000 }, - { (char)189, 1.000 }, - { (char)191, 0.500 }, - { (char)193, 0.333 }, - { (char)194, 0.333 }, - { (char)195, 0.333 }, - { (char)196, 0.333 }, - { (char)197, 0.333 }, - { (char)198, 0.333 }, - { (char)199, 0.333 }, - { (char)200, 0.333 }, - { (char)202, 0.333 }, - { (char)203, 0.333 }, - { (char)205, 0.333 }, - { (char)206, 0.333 }, - { (char)207, 0.333 }, - { (char)208, 1.000 }, - { (char)225, 1.000 }, - { (char)227, 0.300 }, - { (char)232, 0.667 }, - { (char)233, 0.778 }, - { (char)234, 1.000 }, - { (char)235, 0.330 }, - { (char)241, 0.722 }, - { (char)245, 0.278 }, - { (char)248, 0.278 }, - { (char)249, 0.500 }, - { (char)250, 0.722 }, - { (char)251, 0.556 }, - }; - #endregion - } - - public class Times_Italic - { - #region Definition - - public static double ApproxHeight = 0.880; - - public static double Ascender = 0.683; - public static double CapHeight = 0.653; - public static double XHeight = 0.441; - public static double Descender = -0.217; - public static Dictionary Widths = new Dictionary() - { - { (char)32, 0.250 }, - { (char)33, 0.333 }, - { (char)34, 0.420 }, - { (char)35, 0.500 }, - { (char)36, 0.500 }, - { (char)37, 0.833 }, - { (char)38, 0.778 }, - { (char)39, 0.333 }, - { (char)40, 0.333 }, - { (char)41, 0.333 }, - { (char)42, 0.500 }, - { (char)43, 0.675 }, - { (char)44, 0.250 }, - { (char)45, 0.333 }, - { (char)46, 0.250 }, - { (char)47, 0.278 }, - { (char)48, 0.500 }, - { (char)49, 0.500 }, - { (char)50, 0.500 }, - { (char)51, 0.500 }, - { (char)52, 0.500 }, - { (char)53, 0.500 }, - { (char)54, 0.500 }, - { (char)55, 0.500 }, - { (char)56, 0.500 }, - { (char)57, 0.500 }, - { (char)58, 0.333 }, - { (char)59, 0.333 }, - { (char)60, 0.675 }, - { (char)61, 0.675 }, - { (char)62, 0.675 }, - { (char)63, 0.500 }, - { (char)64, 0.920 }, - { (char)65, 0.611 }, - { (char)66, 0.611 }, - { (char)67, 0.667 }, - { (char)68, 0.722 }, - { (char)69, 0.611 }, - { (char)70, 0.611 }, - { (char)71, 0.722 }, - { (char)72, 0.722 }, - { (char)73, 0.333 }, - { (char)74, 0.444 }, - { (char)75, 0.667 }, - { (char)76, 0.556 }, - { (char)77, 0.833 }, - { (char)78, 0.667 }, - { (char)79, 0.722 }, - { (char)80, 0.611 }, - { (char)81, 0.722 }, - { (char)82, 0.611 }, - { (char)83, 0.500 }, - { (char)84, 0.556 }, - { (char)85, 0.722 }, - { (char)86, 0.611 }, - { (char)87, 0.833 }, - { (char)88, 0.611 }, - { (char)89, 0.556 }, - { (char)90, 0.556 }, - { (char)91, 0.389 }, - { (char)92, 0.278 }, - { (char)93, 0.389 }, - { (char)94, 0.422 }, - { (char)95, 0.500 }, - { (char)96, 0.333 }, - { (char)97, 0.500 }, - { (char)98, 0.500 }, - { (char)99, 0.444 }, - { (char)100, 0.500 }, - { (char)101, 0.444 }, - { (char)102, 0.278 }, - { (char)103, 0.500 }, - { (char)104, 0.500 }, - { (char)105, 0.278 }, - { (char)106, 0.278 }, - { (char)107, 0.444 }, - { (char)108, 0.278 }, - { (char)109, 0.722 }, - { (char)110, 0.500 }, - { (char)111, 0.500 }, - { (char)112, 0.500 }, - { (char)113, 0.500 }, - { (char)114, 0.389 }, - { (char)115, 0.389 }, - { (char)116, 0.278 }, - { (char)117, 0.500 }, - { (char)118, 0.444 }, - { (char)119, 0.667 }, - { (char)120, 0.444 }, - { (char)121, 0.444 }, - { (char)122, 0.389 }, - { (char)123, 0.400 }, - { (char)124, 0.275 }, - { (char)125, 0.400 }, - { (char)126, 0.541 }, - { (char)161, 0.389 }, - { (char)162, 0.500 }, - { (char)163, 0.500 }, - { (char)164, 0.167 }, - { (char)165, 0.500 }, - { (char)166, 0.500 }, - { (char)167, 0.500 }, - { (char)168, 0.500 }, - { (char)169, 0.214 }, - { (char)170, 0.556 }, - { (char)171, 0.500 }, - { (char)172, 0.333 }, - { (char)173, 0.333 }, - { (char)174, 0.500 }, - { (char)175, 0.500 }, - { (char)177, 0.500 }, - { (char)178, 0.500 }, - { (char)179, 0.500 }, - { (char)180, 0.250 }, - { (char)182, 0.523 }, - { (char)183, 0.350 }, - { (char)184, 0.333 }, - { (char)185, 0.556 }, - { (char)186, 0.556 }, - { (char)187, 0.500 }, - { (char)188, 0.889 }, - { (char)189, 1.000 }, - { (char)191, 0.500 }, - { (char)193, 0.333 }, - { (char)194, 0.333 }, - { (char)195, 0.333 }, - { (char)196, 0.333 }, - { (char)197, 0.333 }, - { (char)198, 0.333 }, - { (char)199, 0.333 }, - { (char)200, 0.333 }, - { (char)202, 0.333 }, - { (char)203, 0.333 }, - { (char)205, 0.333 }, - { (char)206, 0.333 }, - { (char)207, 0.333 }, - { (char)208, 0.889 }, - { (char)225, 0.889 }, - { (char)227, 0.276 }, - { (char)232, 0.556 }, - { (char)233, 0.722 }, - { (char)234, 0.944 }, - { (char)235, 0.310 }, - { (char)241, 0.667 }, - { (char)245, 0.278 }, - { (char)248, 0.278 }, - { (char)249, 0.500 }, - { (char)250, 0.667 }, - { (char)251, 0.500 }, - - }; - #endregion - } - - public class Times_BoldItalic - { - #region Definition - - public static double ApproxHeight = 0.880; - - public static double Ascender = 0.683; - public static double CapHeight = 0.669; - public static double XHeight = 0.462; - public static double Descender = -0.217; - public static Dictionary Widths = new Dictionary() - { - { (char)32, 0.250 }, - { (char)33, 0.389 }, - { (char)34, 0.555 }, - { (char)35, 0.500 }, - { (char)36, 0.500 }, - { (char)37, 0.833 }, - { (char)38, 0.778 }, - { (char)39, 0.333 }, - { (char)40, 0.333 }, - { (char)41, 0.333 }, - { (char)42, 0.500 }, - { (char)43, 0.570 }, - { (char)44, 0.250 }, - { (char)45, 0.333 }, - { (char)46, 0.250 }, - { (char)47, 0.278 }, - { (char)48, 0.500 }, - { (char)49, 0.500 }, - { (char)50, 0.500 }, - { (char)51, 0.500 }, - { (char)52, 0.500 }, - { (char)53, 0.500 }, - { (char)54, 0.500 }, - { (char)55, 0.500 }, - { (char)56, 0.500 }, - { (char)57, 0.500 }, - { (char)58, 0.333 }, - { (char)59, 0.333 }, - { (char)60, 0.570 }, - { (char)61, 0.570 }, - { (char)62, 0.570 }, - { (char)63, 0.500 }, - { (char)64, 0.832 }, - { (char)65, 0.667 }, - { (char)66, 0.667 }, - { (char)67, 0.667 }, - { (char)68, 0.722 }, - { (char)69, 0.667 }, - { (char)70, 0.667 }, - { (char)71, 0.722 }, - { (char)72, 0.778 }, - { (char)73, 0.389 }, - { (char)74, 0.500 }, - { (char)75, 0.667 }, - { (char)76, 0.611 }, - { (char)77, 0.889 }, - { (char)78, 0.722 }, - { (char)79, 0.722 }, - { (char)80, 0.611 }, - { (char)81, 0.722 }, - { (char)82, 0.667 }, - { (char)83, 0.556 }, - { (char)84, 0.611 }, - { (char)85, 0.722 }, - { (char)86, 0.667 }, - { (char)87, 0.889 }, - { (char)88, 0.667 }, - { (char)89, 0.611 }, - { (char)90, 0.611 }, - { (char)91, 0.333 }, - { (char)92, 0.278 }, - { (char)93, 0.333 }, - { (char)94, 0.570 }, - { (char)95, 0.500 }, - { (char)96, 0.333 }, - { (char)97, 0.500 }, - { (char)98, 0.500 }, - { (char)99, 0.444 }, - { (char)100, 0.500 }, - { (char)101, 0.444 }, - { (char)102, 0.333 }, - { (char)103, 0.500 }, - { (char)104, 0.556 }, - { (char)105, 0.278 }, - { (char)106, 0.278 }, - { (char)107, 0.500 }, - { (char)108, 0.278 }, - { (char)109, 0.778 }, - { (char)110, 0.556 }, - { (char)111, 0.500 }, - { (char)112, 0.500 }, - { (char)113, 0.500 }, - { (char)114, 0.389 }, - { (char)115, 0.389 }, - { (char)116, 0.278 }, - { (char)117, 0.556 }, - { (char)118, 0.444 }, - { (char)119, 0.667 }, - { (char)120, 0.500 }, - { (char)121, 0.444 }, - { (char)122, 0.389 }, - { (char)123, 0.348 }, - { (char)124, 0.220 }, - { (char)125, 0.348 }, - { (char)126, 0.570 }, - { (char)161, 0.389 }, - { (char)162, 0.500 }, - { (char)163, 0.500 }, - { (char)164, 0.167 }, - { (char)165, 0.500 }, - { (char)166, 0.500 }, - { (char)167, 0.500 }, - { (char)168, 0.500 }, - { (char)169, 0.278 }, - { (char)170, 0.500 }, - { (char)171, 0.500 }, - { (char)172, 0.333 }, - { (char)173, 0.333 }, - { (char)174, 0.556 }, - { (char)175, 0.556 }, - { (char)177, 0.500 }, - { (char)178, 0.500 }, - { (char)179, 0.500 }, - { (char)180, 0.250 }, - { (char)182, 0.500 }, - { (char)183, 0.350 }, - { (char)184, 0.333 }, - { (char)185, 0.500 }, - { (char)186, 0.500 }, - { (char)187, 0.500 }, - { (char)188, 1.000 }, - { (char)189, 1.000 }, - { (char)191, 0.500 }, - { (char)193, 0.333 }, - { (char)194, 0.333 }, - { (char)195, 0.333 }, - { (char)196, 0.333 }, - { (char)197, 0.333 }, - { (char)198, 0.333 }, - { (char)199, 0.333 }, - { (char)200, 0.333 }, - { (char)202, 0.333 }, - { (char)203, 0.333 }, - { (char)205, 0.333 }, - { (char)206, 0.333 }, - { (char)207, 0.333 }, - { (char)208, 1.000 }, - { (char)225, 0.944 }, - { (char)227, 0.266 }, - { (char)232, 0.611 }, - { (char)233, 0.722 }, - { (char)234, 0.944 }, - { (char)235, 0.300 }, - { (char)241, 0.722 }, - { (char)245, 0.278 }, - { (char)248, 0.278 }, - { (char)249, 0.500 }, - { (char)250, 0.722 }, - { (char)251, 0.500 }, - - - }; - #endregion - } - - public class Helvetica - { - #region Definition - - public static double ApproxHeight = 0.900; - - public static double Ascender = 0.718; - public static double CapHeight = 0.718; - public static double XHeight = 0.523; - public static double Descender = -0.207; - public static Dictionary Widths = new Dictionary() - { - { (char)32, 0.278 }, - { (char)33, 0.278 }, - { (char)34, 0.355 }, - { (char)35, 0.556 }, - { (char)36, 0.556 }, - { (char)37, 0.889 }, - { (char)38, 0.667 }, - { (char)39, 0.222 }, - { (char)40, 0.333 }, - { (char)41, 0.333 }, - { (char)42, 0.389 }, - { (char)43, 0.584 }, - { (char)44, 0.278 }, - { (char)45, 0.333 }, - { (char)46, 0.278 }, - { (char)47, 0.278 }, - { (char)48, 0.556 }, - { (char)49, 0.556 }, - { (char)50, 0.556 }, - { (char)51, 0.556 }, - { (char)52, 0.556 }, - { (char)53, 0.556 }, - { (char)54, 0.556 }, - { (char)55, 0.556 }, - { (char)56, 0.556 }, - { (char)57, 0.556 }, - { (char)58, 0.278 }, - { (char)59, 0.278 }, - { (char)60, 0.584 }, - { (char)61, 0.584 }, - { (char)62, 0.584 }, - { (char)63, 0.556 }, - { (char)64, 1.015 }, - { (char)65, 0.667 }, - { (char)66, 0.667 }, - { (char)67, 0.722 }, - { (char)68, 0.722 }, - { (char)69, 0.667 }, - { (char)70, 0.611 }, - { (char)71, 0.778 }, - { (char)72, 0.722 }, - { (char)73, 0.278 }, - { (char)74, 0.500 }, - { (char)75, 0.667 }, - { (char)76, 0.556 }, - { (char)77, 0.833 }, - { (char)78, 0.722 }, - { (char)79, 0.778 }, - { (char)80, 0.667 }, - { (char)81, 0.778 }, - { (char)82, 0.722 }, - { (char)83, 0.667 }, - { (char)84, 0.611 }, - { (char)85, 0.722 }, - { (char)86, 0.667 }, - { (char)87, 0.944 }, - { (char)88, 0.667 }, - { (char)89, 0.667 }, - { (char)90, 0.611 }, - { (char)91, 0.278 }, - { (char)92, 0.278 }, - { (char)93, 0.278 }, - { (char)94, 0.469 }, - { (char)95, 0.556 }, - { (char)96, 0.222 }, - { (char)97, 0.556 }, - { (char)98, 0.556 }, - { (char)99, 0.500 }, - { (char)100, 0.556 }, - { (char)101, 0.556 }, - { (char)102, 0.278 }, - { (char)103, 0.556 }, - { (char)104, 0.556 }, - { (char)105, 0.222 }, - { (char)106, 0.222 }, - { (char)107, 0.500 }, - { (char)108, 0.222 }, - { (char)109, 0.833 }, - { (char)110, 0.556 }, - { (char)111, 0.556 }, - { (char)112, 0.556 }, - { (char)113, 0.556 }, - { (char)114, 0.333 }, - { (char)115, 0.500 }, - { (char)116, 0.278 }, - { (char)117, 0.556 }, - { (char)118, 0.500 }, - { (char)119, 0.722 }, - { (char)120, 0.500 }, - { (char)121, 0.500 }, - { (char)122, 0.500 }, - { (char)123, 0.334 }, - { (char)124, 0.260 }, - { (char)125, 0.334 }, - { (char)126, 0.584 }, - { (char)161, 0.333 }, - { (char)162, 0.556 }, - { (char)163, 0.556 }, - { (char)164, 0.167 }, - { (char)165, 0.556 }, - { (char)166, 0.556 }, - { (char)167, 0.556 }, - { (char)168, 0.556 }, - { (char)169, 0.191 }, - { (char)170, 0.333 }, - { (char)171, 0.556 }, - { (char)172, 0.333 }, - { (char)173, 0.333 }, - { (char)174, 0.500 }, - { (char)175, 0.500 }, - { (char)177, 0.556 }, - { (char)178, 0.556 }, - { (char)179, 0.556 }, - { (char)180, 0.278 }, - { (char)182, 0.537 }, - { (char)183, 0.350 }, - { (char)184, 0.222 }, - { (char)185, 0.333 }, - { (char)186, 0.333 }, - { (char)187, 0.556 }, - { (char)188, 1.000 }, - { (char)189, 1.000 }, - { (char)191, 0.611 }, - { (char)193, 0.333 }, - { (char)194, 0.333 }, - { (char)195, 0.333 }, - { (char)196, 0.333 }, - { (char)197, 0.333 }, - { (char)198, 0.333 }, - { (char)199, 0.333 }, - { (char)200, 0.333 }, - { (char)202, 0.333 }, - { (char)203, 0.333 }, - { (char)205, 0.333 }, - { (char)206, 0.333 }, - { (char)207, 0.333 }, - { (char)208, 1.000 }, - { (char)225, 1.000 }, - { (char)227, 0.370 }, - { (char)232, 0.556 }, - { (char)233, 0.778 }, - { (char)234, 1.000 }, - { (char)235, 0.365 }, - { (char)241, 0.889 }, - { (char)245, 0.278 }, - { (char)248, 0.222 }, - { (char)249, 0.611 }, - { (char)250, 0.944 }, - { (char)251, 0.611 }, - }; - #endregion - } - - public class Helvetica_Bold - { - #region Definition - - public static double ApproxHeight = 0.900; - - public static double Ascender = 0.718; - public static double CapHeight = 0.718; - public static double XHeight = 0.532; - public static double Descender = -0.207; - public static Dictionary Widths = new Dictionary() - { - { (char)32, 0.278 }, - { (char)33, 0.333 }, - { (char)34, 0.474 }, - { (char)35, 0.556 }, - { (char)36, 0.556 }, - { (char)37, 0.889 }, - { (char)38, 0.722 }, - { (char)39, 0.278 }, - { (char)40, 0.333 }, - { (char)41, 0.333 }, - { (char)42, 0.389 }, - { (char)43, 0.584 }, - { (char)44, 0.278 }, - { (char)45, 0.333 }, - { (char)46, 0.278 }, - { (char)47, 0.278 }, - { (char)48, 0.556 }, - { (char)49, 0.556 }, - { (char)50, 0.556 }, - { (char)51, 0.556 }, - { (char)52, 0.556 }, - { (char)53, 0.556 }, - { (char)54, 0.556 }, - { (char)55, 0.556 }, - { (char)56, 0.556 }, - { (char)57, 0.556 }, - { (char)58, 0.333 }, - { (char)59, 0.333 }, - { (char)60, 0.584 }, - { (char)61, 0.584 }, - { (char)62, 0.584 }, - { (char)63, 0.611 }, - { (char)64, 0.975 }, - { (char)65, 0.722 }, - { (char)66, 0.722 }, - { (char)67, 0.722 }, - { (char)68, 0.722 }, - { (char)69, 0.667 }, - { (char)70, 0.611 }, - { (char)71, 0.778 }, - { (char)72, 0.722 }, - { (char)73, 0.278 }, - { (char)74, 0.556 }, - { (char)75, 0.722 }, - { (char)76, 0.611 }, - { (char)77, 0.833 }, - { (char)78, 0.722 }, - { (char)79, 0.778 }, - { (char)80, 0.667 }, - { (char)81, 0.778 }, - { (char)82, 0.722 }, - { (char)83, 0.667 }, - { (char)84, 0.611 }, - { (char)85, 0.722 }, - { (char)86, 0.667 }, - { (char)87, 0.944 }, - { (char)88, 0.667 }, - { (char)89, 0.667 }, - { (char)90, 0.611 }, - { (char)91, 0.333 }, - { (char)92, 0.278 }, - { (char)93, 0.333 }, - { (char)94, 0.584 }, - { (char)95, 0.556 }, - { (char)96, 0.278 }, - { (char)97, 0.556 }, - { (char)98, 0.611 }, - { (char)99, 0.556 }, - { (char)100, 0.611 }, - { (char)101, 0.556 }, - { (char)102, 0.333 }, - { (char)103, 0.611 }, - { (char)104, 0.611 }, - { (char)105, 0.278 }, - { (char)106, 0.278 }, - { (char)107, 0.556 }, - { (char)108, 0.278 }, - { (char)109, 0.889 }, - { (char)110, 0.611 }, - { (char)111, 0.611 }, - { (char)112, 0.611 }, - { (char)113, 0.611 }, - { (char)114, 0.389 }, - { (char)115, 0.556 }, - { (char)116, 0.333 }, - { (char)117, 0.611 }, - { (char)118, 0.556 }, - { (char)119, 0.778 }, - { (char)120, 0.556 }, - { (char)121, 0.556 }, - { (char)122, 0.500 }, - { (char)123, 0.389 }, - { (char)124, 0.280 }, - { (char)125, 0.389 }, - { (char)126, 0.584 }, - { (char)161, 0.333 }, - { (char)162, 0.556 }, - { (char)163, 0.556 }, - { (char)164, 0.167 }, - { (char)165, 0.556 }, - { (char)166, 0.556 }, - { (char)167, 0.556 }, - { (char)168, 0.556 }, - { (char)169, 0.238 }, - { (char)170, 0.500 }, - { (char)171, 0.556 }, - { (char)172, 0.333 }, - { (char)173, 0.333 }, - { (char)174, 0.611 }, - { (char)175, 0.611 }, - { (char)177, 0.556 }, - { (char)178, 0.556 }, - { (char)179, 0.556 }, - { (char)180, 0.278 }, - { (char)182, 0.556 }, - { (char)183, 0.350 }, - { (char)184, 0.278 }, - { (char)185, 0.500 }, - { (char)186, 0.500 }, - { (char)187, 0.556 }, - { (char)188, 1.000 }, - { (char)189, 1.000 }, - { (char)191, 0.611 }, - { (char)193, 0.333 }, - { (char)194, 0.333 }, - { (char)195, 0.333 }, - { (char)196, 0.333 }, - { (char)197, 0.333 }, - { (char)198, 0.333 }, - { (char)199, 0.333 }, - { (char)200, 0.333 }, - { (char)202, 0.333 }, - { (char)203, 0.333 }, - { (char)205, 0.333 }, - { (char)206, 0.333 }, - { (char)207, 0.333 }, - { (char)208, 1.000 }, - { (char)225, 1.000 }, - { (char)227, 0.370 }, - { (char)232, 0.611 }, - { (char)233, 0.778 }, - { (char)234, 1.000 }, - { (char)235, 0.365 }, - { (char)241, 0.889 }, - { (char)245, 0.278 }, - { (char)248, 0.278 }, - { (char)249, 0.611 }, - { (char)250, 0.944 }, - { (char)251, 0.611 }, - }; - #endregion - } - - public class Helvetica_Oblique - { - #region Definition - - public static double ApproxHeight = 0.900; - - public static double Ascender = 0.718; - public static double CapHeight = 0.718; - public static double XHeight = 0.523; - public static double Descender = -0.207; - public static Dictionary Widths = new Dictionary() - { - { (char)32, 0.278 }, - { (char)33, 0.278 }, - { (char)34, 0.355 }, - { (char)35, 0.556 }, - { (char)36, 0.556 }, - { (char)37, 0.889 }, - { (char)38, 0.667 }, - { (char)39, 0.222 }, - { (char)40, 0.333 }, - { (char)41, 0.333 }, - { (char)42, 0.389 }, - { (char)43, 0.584 }, - { (char)44, 0.278 }, - { (char)45, 0.333 }, - { (char)46, 0.278 }, - { (char)47, 0.278 }, - { (char)48, 0.556 }, - { (char)49, 0.556 }, - { (char)50, 0.556 }, - { (char)51, 0.556 }, - { (char)52, 0.556 }, - { (char)53, 0.556 }, - { (char)54, 0.556 }, - { (char)55, 0.556 }, - { (char)56, 0.556 }, - { (char)57, 0.556 }, - { (char)58, 0.278 }, - { (char)59, 0.278 }, - { (char)60, 0.584 }, - { (char)61, 0.584 }, - { (char)62, 0.584 }, - { (char)63, 0.556 }, - { (char)64, 1.015 }, - { (char)65, 0.667 }, - { (char)66, 0.667 }, - { (char)67, 0.722 }, - { (char)68, 0.722 }, - { (char)69, 0.667 }, - { (char)70, 0.611 }, - { (char)71, 0.778 }, - { (char)72, 0.722 }, - { (char)73, 0.278 }, - { (char)74, 0.500 }, - { (char)75, 0.667 }, - { (char)76, 0.556 }, - { (char)77, 0.833 }, - { (char)78, 0.722 }, - { (char)79, 0.778 }, - { (char)80, 0.667 }, - { (char)81, 0.778 }, - { (char)82, 0.722 }, - { (char)83, 0.667 }, - { (char)84, 0.611 }, - { (char)85, 0.722 }, - { (char)86, 0.667 }, - { (char)87, 0.944 }, - { (char)88, 0.667 }, - { (char)89, 0.667 }, - { (char)90, 0.611 }, - { (char)91, 0.278 }, - { (char)92, 0.278 }, - { (char)93, 0.278 }, - { (char)94, 0.469 }, - { (char)95, 0.556 }, - { (char)96, 0.222 }, - { (char)97, 0.556 }, - { (char)98, 0.556 }, - { (char)99, 0.500 }, - { (char)100, 0.556 }, - { (char)101, 0.556 }, - { (char)102, 0.278 }, - { (char)103, 0.556 }, - { (char)104, 0.556 }, - { (char)105, 0.222 }, - { (char)106, 0.222 }, - { (char)107, 0.500 }, - { (char)108, 0.222 }, - { (char)109, 0.833 }, - { (char)110, 0.556 }, - { (char)111, 0.556 }, - { (char)112, 0.556 }, - { (char)113, 0.556 }, - { (char)114, 0.333 }, - { (char)115, 0.500 }, - { (char)116, 0.278 }, - { (char)117, 0.556 }, - { (char)118, 0.500 }, - { (char)119, 0.722 }, - { (char)120, 0.500 }, - { (char)121, 0.500 }, - { (char)122, 0.500 }, - { (char)123, 0.334 }, - { (char)124, 0.260 }, - { (char)125, 0.334 }, - { (char)126, 0.584 }, - { (char)161, 0.333 }, - { (char)162, 0.556 }, - { (char)163, 0.556 }, - { (char)164, 0.167 }, - { (char)165, 0.556 }, - { (char)166, 0.556 }, - { (char)167, 0.556 }, - { (char)168, 0.556 }, - { (char)169, 0.191 }, - { (char)170, 0.333 }, - { (char)171, 0.556 }, - { (char)172, 0.333 }, - { (char)173, 0.333 }, - { (char)174, 0.500 }, - { (char)175, 0.500 }, - { (char)177, 0.556 }, - { (char)178, 0.556 }, - { (char)179, 0.556 }, - { (char)180, 0.278 }, - { (char)182, 0.537 }, - { (char)183, 0.350 }, - { (char)184, 0.222 }, - { (char)185, 0.333 }, - { (char)186, 0.333 }, - { (char)187, 0.556 }, - { (char)188, 1.000 }, - { (char)189, 1.000 }, - { (char)191, 0.611 }, - { (char)193, 0.333 }, - { (char)194, 0.333 }, - { (char)195, 0.333 }, - { (char)196, 0.333 }, - { (char)197, 0.333 }, - { (char)198, 0.333 }, - { (char)199, 0.333 }, - { (char)200, 0.333 }, - { (char)202, 0.333 }, - { (char)203, 0.333 }, - { (char)205, 0.333 }, - { (char)206, 0.333 }, - { (char)207, 0.333 }, - { (char)208, 1.000 }, - { (char)225, 1.000 }, - { (char)227, 0.370 }, - { (char)232, 0.556 }, - { (char)233, 0.778 }, - { (char)234, 1.000 }, - { (char)235, 0.365 }, - { (char)241, 0.889 }, - { (char)245, 0.278 }, - { (char)248, 0.222 }, - { (char)249, 0.611 }, - { (char)250, 0.944 }, - { (char)251, 0.611 }, - }; - #endregion - } - - public class Helvetica_BoldOblique - { - #region Definition - - public static double ApproxHeight = 0.900; - - public static double Ascender = 0.718; - public static double CapHeight = 0.718; - public static double XHeight = 0.532; - public static double Descender = -0.207; - public static Dictionary Widths = new Dictionary() - { - { (char)32, 0.278 }, - { (char)33, 0.333 }, - { (char)34, 0.474 }, - { (char)35, 0.556 }, - { (char)36, 0.556 }, - { (char)37, 0.889 }, - { (char)38, 0.722 }, - { (char)39, 0.278 }, - { (char)40, 0.333 }, - { (char)41, 0.333 }, - { (char)42, 0.389 }, - { (char)43, 0.584 }, - { (char)44, 0.278 }, - { (char)45, 0.333 }, - { (char)46, 0.278 }, - { (char)47, 0.278 }, - { (char)48, 0.556 }, - { (char)49, 0.556 }, - { (char)50, 0.556 }, - { (char)51, 0.556 }, - { (char)52, 0.556 }, - { (char)53, 0.556 }, - { (char)54, 0.556 }, - { (char)55, 0.556 }, - { (char)56, 0.556 }, - { (char)57, 0.556 }, - { (char)58, 0.333 }, - { (char)59, 0.333 }, - { (char)60, 0.584 }, - { (char)61, 0.584 }, - { (char)62, 0.584 }, - { (char)63, 0.611 }, - { (char)64, 0.975 }, - { (char)65, 0.722 }, - { (char)66, 0.722 }, - { (char)67, 0.722 }, - { (char)68, 0.722 }, - { (char)69, 0.667 }, - { (char)70, 0.611 }, - { (char)71, 0.778 }, - { (char)72, 0.722 }, - { (char)73, 0.278 }, - { (char)74, 0.556 }, - { (char)75, 0.722 }, - { (char)76, 0.611 }, - { (char)77, 0.833 }, - { (char)78, 0.722 }, - { (char)79, 0.778 }, - { (char)80, 0.667 }, - { (char)81, 0.778 }, - { (char)82, 0.722 }, - { (char)83, 0.667 }, - { (char)84, 0.611 }, - { (char)85, 0.722 }, - { (char)86, 0.667 }, - { (char)87, 0.944 }, - { (char)88, 0.667 }, - { (char)89, 0.667 }, - { (char)90, 0.611 }, - { (char)91, 0.333 }, - { (char)92, 0.278 }, - { (char)93, 0.333 }, - { (char)94, 0.584 }, - { (char)95, 0.556 }, - { (char)96, 0.278 }, - { (char)97, 0.556 }, - { (char)98, 0.611 }, - { (char)99, 0.556 }, - { (char)100, 0.611 }, - { (char)101, 0.556 }, - { (char)102, 0.333 }, - { (char)103, 0.611 }, - { (char)104, 0.611 }, - { (char)105, 0.278 }, - { (char)106, 0.278 }, - { (char)107, 0.556 }, - { (char)108, 0.278 }, - { (char)109, 0.889 }, - { (char)110, 0.611 }, - { (char)111, 0.611 }, - { (char)112, 0.611 }, - { (char)113, 0.611 }, - { (char)114, 0.389 }, - { (char)115, 0.556 }, - { (char)116, 0.333 }, - { (char)117, 0.611 }, - { (char)118, 0.556 }, - { (char)119, 0.778 }, - { (char)120, 0.556 }, - { (char)121, 0.556 }, - { (char)122, 0.500 }, - { (char)123, 0.389 }, - { (char)124, 0.280 }, - { (char)125, 0.389 }, - { (char)126, 0.584 }, - { (char)161, 0.333 }, - { (char)162, 0.556 }, - { (char)163, 0.556 }, - { (char)164, 0.167 }, - { (char)165, 0.556 }, - { (char)166, 0.556 }, - { (char)167, 0.556 }, - { (char)168, 0.556 }, - { (char)169, 0.238 }, - { (char)170, 0.500 }, - { (char)171, 0.556 }, - { (char)172, 0.333 }, - { (char)173, 0.333 }, - { (char)174, 0.611 }, - { (char)175, 0.611 }, - { (char)177, 0.556 }, - { (char)178, 0.556 }, - { (char)179, 0.556 }, - { (char)180, 0.278 }, - { (char)182, 0.556 }, - { (char)183, 0.350 }, - { (char)184, 0.278 }, - { (char)185, 0.500 }, - { (char)186, 0.500 }, - { (char)187, 0.556 }, - { (char)188, 1.000 }, - { (char)189, 1.000 }, - { (char)191, 0.611 }, - { (char)193, 0.333 }, - { (char)194, 0.333 }, - { (char)195, 0.333 }, - { (char)196, 0.333 }, - { (char)197, 0.333 }, - { (char)198, 0.333 }, - { (char)199, 0.333 }, - { (char)200, 0.333 }, - { (char)202, 0.333 }, - { (char)203, 0.333 }, - { (char)205, 0.333 }, - { (char)206, 0.333 }, - { (char)207, 0.333 }, - { (char)208, 1.000 }, - { (char)225, 1.000 }, - { (char)227, 0.370 }, - { (char)232, 0.611 }, - { (char)233, 0.778 }, - { (char)234, 1.000 }, - { (char)235, 0.365 }, - { (char)241, 0.889 }, - { (char)245, 0.278 }, - { (char)248, 0.278 }, - { (char)249, 0.611 }, - { (char)250, 0.944 }, - { (char)251, 0.611 }, - }; - #endregion - } - - public class Courier - { - #region Definition - - public static double ApproxHeight = 0.780; - - public static double Ascender = 0.629; - public static double CapHeight = 0.562; - public static double XHeight = 0.426; - public static double Descender = -0.157; - public static Dictionary Widths = new Dictionary() - { - { (char)32, 0.600 }, - { (char)33, 0.600 }, - { (char)34, 0.600 }, - { (char)35, 0.600 }, - { (char)36, 0.600 }, - { (char)37, 0.600 }, - { (char)38, 0.600 }, - { (char)39, 0.600 }, - { (char)40, 0.600 }, - { (char)41, 0.600 }, - { (char)42, 0.600 }, - { (char)43, 0.600 }, - { (char)44, 0.600 }, - { (char)45, 0.600 }, - { (char)46, 0.600 }, - { (char)47, 0.600 }, - { (char)48, 0.600 }, - { (char)49, 0.600 }, - { (char)50, 0.600 }, - { (char)51, 0.600 }, - { (char)52, 0.600 }, - { (char)53, 0.600 }, - { (char)54, 0.600 }, - { (char)55, 0.600 }, - { (char)56, 0.600 }, - { (char)57, 0.600 }, - { (char)58, 0.600 }, - { (char)59, 0.600 }, - { (char)60, 0.600 }, - { (char)61, 0.600 }, - { (char)62, 0.600 }, - { (char)63, 0.600 }, - { (char)64, 0.600 }, - { (char)65, 0.600 }, - { (char)66, 0.600 }, - { (char)67, 0.600 }, - { (char)68, 0.600 }, - { (char)69, 0.600 }, - { (char)70, 0.600 }, - { (char)71, 0.600 }, - { (char)72, 0.600 }, - { (char)73, 0.600 }, - { (char)74, 0.600 }, - { (char)75, 0.600 }, - { (char)76, 0.600 }, - { (char)77, 0.600 }, - { (char)78, 0.600 }, - { (char)79, 0.600 }, - { (char)80, 0.600 }, - { (char)81, 0.600 }, - { (char)82, 0.600 }, - { (char)83, 0.600 }, - { (char)84, 0.600 }, - { (char)85, 0.600 }, - { (char)86, 0.600 }, - { (char)87, 0.600 }, - { (char)88, 0.600 }, - { (char)89, 0.600 }, - { (char)90, 0.600 }, - { (char)91, 0.600 }, - { (char)92, 0.600 }, - { (char)93, 0.600 }, - { (char)94, 0.600 }, - { (char)95, 0.600 }, - { (char)96, 0.600 }, - { (char)97, 0.600 }, - { (char)98, 0.600 }, - { (char)99, 0.600 }, - { (char)100, 0.600 }, - { (char)101, 0.600 }, - { (char)102, 0.600 }, - { (char)103, 0.600 }, - { (char)104, 0.600 }, - { (char)105, 0.600 }, - { (char)106, 0.600 }, - { (char)107, 0.600 }, - { (char)108, 0.600 }, - { (char)109, 0.600 }, - { (char)110, 0.600 }, - { (char)111, 0.600 }, - { (char)112, 0.600 }, - { (char)113, 0.600 }, - { (char)114, 0.600 }, - { (char)115, 0.600 }, - { (char)116, 0.600 }, - { (char)117, 0.600 }, - { (char)118, 0.600 }, - { (char)119, 0.600 }, - { (char)120, 0.600 }, - { (char)121, 0.600 }, - { (char)122, 0.600 }, - { (char)123, 0.600 }, - { (char)124, 0.600 }, - { (char)125, 0.600 }, - { (char)126, 0.600 }, - { (char)161, 0.600 }, - { (char)162, 0.600 }, - { (char)163, 0.600 }, - { (char)164, 0.600 }, - { (char)165, 0.600 }, - { (char)166, 0.600 }, - { (char)167, 0.600 }, - { (char)168, 0.600 }, - { (char)169, 0.600 }, - { (char)170, 0.600 }, - { (char)171, 0.600 }, - { (char)172, 0.600 }, - { (char)173, 0.600 }, - { (char)174, 0.600 }, - { (char)175, 0.600 }, - { (char)177, 0.600 }, - { (char)178, 0.600 }, - { (char)179, 0.600 }, - { (char)180, 0.600 }, - { (char)182, 0.600 }, - { (char)183, 0.600 }, - { (char)184, 0.600 }, - { (char)185, 0.600 }, - { (char)186, 0.600 }, - { (char)187, 0.600 }, - { (char)188, 0.600 }, - { (char)189, 0.600 }, - { (char)191, 0.600 }, - { (char)193, 0.600 }, - { (char)194, 0.600 }, - { (char)195, 0.600 }, - { (char)196, 0.600 }, - { (char)197, 0.600 }, - { (char)198, 0.600 }, - { (char)199, 0.600 }, - { (char)200, 0.600 }, - { (char)202, 0.600 }, - { (char)203, 0.600 }, - { (char)205, 0.600 }, - { (char)206, 0.600 }, - { (char)207, 0.600 }, - { (char)208, 0.600 }, - { (char)225, 0.600 }, - { (char)227, 0.600 }, - { (char)232, 0.600 }, - { (char)233, 0.600 }, - { (char)234, 0.600 }, - { (char)235, 0.600 }, - { (char)241, 0.600 }, - { (char)245, 0.600 }, - { (char)248, 0.600 }, - { (char)249, 0.600 }, - { (char)250, 0.600 }, - { (char)251, 0.600 }, - }; - #endregion - } - - public class Courier_Bold - { - #region Definition - - public static double ApproxHeight = 0.780; - - public static double Ascender = 0.629; - public static double CapHeight = 0.562; - public static double XHeight = 0.439; - public static double Descender = -0.157; - public static Dictionary Widths = new Dictionary() - { - { (char)32, 0.600 }, - { (char)33, 0.600 }, - { (char)34, 0.600 }, - { (char)35, 0.600 }, - { (char)36, 0.600 }, - { (char)37, 0.600 }, - { (char)38, 0.600 }, - { (char)39, 0.600 }, - { (char)40, 0.600 }, - { (char)41, 0.600 }, - { (char)42, 0.600 }, - { (char)43, 0.600 }, - { (char)44, 0.600 }, - { (char)45, 0.600 }, - { (char)46, 0.600 }, - { (char)47, 0.600 }, - { (char)48, 0.600 }, - { (char)49, 0.600 }, - { (char)50, 0.600 }, - { (char)51, 0.600 }, - { (char)52, 0.600 }, - { (char)53, 0.600 }, - { (char)54, 0.600 }, - { (char)55, 0.600 }, - { (char)56, 0.600 }, - { (char)57, 0.600 }, - { (char)58, 0.600 }, - { (char)59, 0.600 }, - { (char)60, 0.600 }, - { (char)61, 0.600 }, - { (char)62, 0.600 }, - { (char)63, 0.600 }, - { (char)64, 0.600 }, - { (char)65, 0.600 }, - { (char)66, 0.600 }, - { (char)67, 0.600 }, - { (char)68, 0.600 }, - { (char)69, 0.600 }, - { (char)70, 0.600 }, - { (char)71, 0.600 }, - { (char)72, 0.600 }, - { (char)73, 0.600 }, - { (char)74, 0.600 }, - { (char)75, 0.600 }, - { (char)76, 0.600 }, - { (char)77, 0.600 }, - { (char)78, 0.600 }, - { (char)79, 0.600 }, - { (char)80, 0.600 }, - { (char)81, 0.600 }, - { (char)82, 0.600 }, - { (char)83, 0.600 }, - { (char)84, 0.600 }, - { (char)85, 0.600 }, - { (char)86, 0.600 }, - { (char)87, 0.600 }, - { (char)88, 0.600 }, - { (char)89, 0.600 }, - { (char)90, 0.600 }, - { (char)91, 0.600 }, - { (char)92, 0.600 }, - { (char)93, 0.600 }, - { (char)94, 0.600 }, - { (char)95, 0.600 }, - { (char)96, 0.600 }, - { (char)97, 0.600 }, - { (char)98, 0.600 }, - { (char)99, 0.600 }, - { (char)100, 0.600 }, - { (char)101, 0.600 }, - { (char)102, 0.600 }, - { (char)103, 0.600 }, - { (char)104, 0.600 }, - { (char)105, 0.600 }, - { (char)106, 0.600 }, - { (char)107, 0.600 }, - { (char)108, 0.600 }, - { (char)109, 0.600 }, - { (char)110, 0.600 }, - { (char)111, 0.600 }, - { (char)112, 0.600 }, - { (char)113, 0.600 }, - { (char)114, 0.600 }, - { (char)115, 0.600 }, - { (char)116, 0.600 }, - { (char)117, 0.600 }, - { (char)118, 0.600 }, - { (char)119, 0.600 }, - { (char)120, 0.600 }, - { (char)121, 0.600 }, - { (char)122, 0.600 }, - { (char)123, 0.600 }, - { (char)124, 0.600 }, - { (char)125, 0.600 }, - { (char)126, 0.600 }, - { (char)161, 0.600 }, - { (char)162, 0.600 }, - { (char)163, 0.600 }, - { (char)164, 0.600 }, - { (char)165, 0.600 }, - { (char)166, 0.600 }, - { (char)167, 0.600 }, - { (char)168, 0.600 }, - { (char)169, 0.600 }, - { (char)170, 0.600 }, - { (char)171, 0.600 }, - { (char)172, 0.600 }, - { (char)173, 0.600 }, - { (char)174, 0.600 }, - { (char)175, 0.600 }, - { (char)177, 0.600 }, - { (char)178, 0.600 }, - { (char)179, 0.600 }, - { (char)180, 0.600 }, - { (char)182, 0.600 }, - { (char)183, 0.600 }, - { (char)184, 0.600 }, - { (char)185, 0.600 }, - { (char)186, 0.600 }, - { (char)187, 0.600 }, - { (char)188, 0.600 }, - { (char)189, 0.600 }, - { (char)191, 0.600 }, - { (char)193, 0.600 }, - { (char)194, 0.600 }, - { (char)195, 0.600 }, - { (char)196, 0.600 }, - { (char)197, 0.600 }, - { (char)198, 0.600 }, - { (char)199, 0.600 }, - { (char)200, 0.600 }, - { (char)202, 0.600 }, - { (char)203, 0.600 }, - { (char)205, 0.600 }, - { (char)206, 0.600 }, - { (char)207, 0.600 }, - { (char)208, 0.600 }, - { (char)225, 0.600 }, - { (char)227, 0.600 }, - { (char)232, 0.600 }, - { (char)233, 0.600 }, - { (char)234, 0.600 }, - { (char)235, 0.600 }, - { (char)241, 0.600 }, - { (char)245, 0.600 }, - { (char)248, 0.600 }, - { (char)249, 0.600 }, - { (char)250, 0.600 }, - { (char)251, 0.600 }, - }; - #endregion - } - - public class Courier_Oblique - { - #region Definition - - public static double ApproxHeight = 0.780; - - public static double Ascender = 0.629; - public static double CapHeight = 0.562; - public static double XHeight = 0.426; - public static double Descender = -0.157; - public static Dictionary Widths = new Dictionary() - { - { (char)32, 0.600 }, - { (char)33, 0.600 }, - { (char)34, 0.600 }, - { (char)35, 0.600 }, - { (char)36, 0.600 }, - { (char)37, 0.600 }, - { (char)38, 0.600 }, - { (char)39, 0.600 }, - { (char)40, 0.600 }, - { (char)41, 0.600 }, - { (char)42, 0.600 }, - { (char)43, 0.600 }, - { (char)44, 0.600 }, - { (char)45, 0.600 }, - { (char)46, 0.600 }, - { (char)47, 0.600 }, - { (char)48, 0.600 }, - { (char)49, 0.600 }, - { (char)50, 0.600 }, - { (char)51, 0.600 }, - { (char)52, 0.600 }, - { (char)53, 0.600 }, - { (char)54, 0.600 }, - { (char)55, 0.600 }, - { (char)56, 0.600 }, - { (char)57, 0.600 }, - { (char)58, 0.600 }, - { (char)59, 0.600 }, - { (char)60, 0.600 }, - { (char)61, 0.600 }, - { (char)62, 0.600 }, - { (char)63, 0.600 }, - { (char)64, 0.600 }, - { (char)65, 0.600 }, - { (char)66, 0.600 }, - { (char)67, 0.600 }, - { (char)68, 0.600 }, - { (char)69, 0.600 }, - { (char)70, 0.600 }, - { (char)71, 0.600 }, - { (char)72, 0.600 }, - { (char)73, 0.600 }, - { (char)74, 0.600 }, - { (char)75, 0.600 }, - { (char)76, 0.600 }, - { (char)77, 0.600 }, - { (char)78, 0.600 }, - { (char)79, 0.600 }, - { (char)80, 0.600 }, - { (char)81, 0.600 }, - { (char)82, 0.600 }, - { (char)83, 0.600 }, - { (char)84, 0.600 }, - { (char)85, 0.600 }, - { (char)86, 0.600 }, - { (char)87, 0.600 }, - { (char)88, 0.600 }, - { (char)89, 0.600 }, - { (char)90, 0.600 }, - { (char)91, 0.600 }, - { (char)92, 0.600 }, - { (char)93, 0.600 }, - { (char)94, 0.600 }, - { (char)95, 0.600 }, - { (char)96, 0.600 }, - { (char)97, 0.600 }, - { (char)98, 0.600 }, - { (char)99, 0.600 }, - { (char)100, 0.600 }, - { (char)101, 0.600 }, - { (char)102, 0.600 }, - { (char)103, 0.600 }, - { (char)104, 0.600 }, - { (char)105, 0.600 }, - { (char)106, 0.600 }, - { (char)107, 0.600 }, - { (char)108, 0.600 }, - { (char)109, 0.600 }, - { (char)110, 0.600 }, - { (char)111, 0.600 }, - { (char)112, 0.600 }, - { (char)113, 0.600 }, - { (char)114, 0.600 }, - { (char)115, 0.600 }, - { (char)116, 0.600 }, - { (char)117, 0.600 }, - { (char)118, 0.600 }, - { (char)119, 0.600 }, - { (char)120, 0.600 }, - { (char)121, 0.600 }, - { (char)122, 0.600 }, - { (char)123, 0.600 }, - { (char)124, 0.600 }, - { (char)125, 0.600 }, - { (char)126, 0.600 }, - { (char)161, 0.600 }, - { (char)162, 0.600 }, - { (char)163, 0.600 }, - { (char)164, 0.600 }, - { (char)165, 0.600 }, - { (char)166, 0.600 }, - { (char)167, 0.600 }, - { (char)168, 0.600 }, - { (char)169, 0.600 }, - { (char)170, 0.600 }, - { (char)171, 0.600 }, - { (char)172, 0.600 }, - { (char)173, 0.600 }, - { (char)174, 0.600 }, - { (char)175, 0.600 }, - { (char)177, 0.600 }, - { (char)178, 0.600 }, - { (char)179, 0.600 }, - { (char)180, 0.600 }, - { (char)182, 0.600 }, - { (char)183, 0.600 }, - { (char)184, 0.600 }, - { (char)185, 0.600 }, - { (char)186, 0.600 }, - { (char)187, 0.600 }, - { (char)188, 0.600 }, - { (char)189, 0.600 }, - { (char)191, 0.600 }, - { (char)193, 0.600 }, - { (char)194, 0.600 }, - { (char)195, 0.600 }, - { (char)196, 0.600 }, - { (char)197, 0.600 }, - { (char)198, 0.600 }, - { (char)199, 0.600 }, - { (char)200, 0.600 }, - { (char)202, 0.600 }, - { (char)203, 0.600 }, - { (char)205, 0.600 }, - { (char)206, 0.600 }, - { (char)207, 0.600 }, - { (char)208, 0.600 }, - { (char)225, 0.600 }, - { (char)227, 0.600 }, - { (char)232, 0.600 }, - { (char)233, 0.600 }, - { (char)234, 0.600 }, - { (char)235, 0.600 }, - { (char)241, 0.600 }, - { (char)245, 0.600 }, - { (char)248, 0.600 }, - { (char)249, 0.600 }, - { (char)250, 0.600 }, - { (char)251, 0.600 }, - }; - #endregion - } - - public class Courier_BoldOblique - { - #region Definition - - public static double ApproxHeight = 0.780; - - public static double Ascender = 0.629; - public static double CapHeight = 0.562; - public static double XHeight = 0.439; - public static double Descender = -0.157; - public static Dictionary Widths = new Dictionary() - { - { (char)32, 0.600 }, - { (char)33, 0.600 }, - { (char)34, 0.600 }, - { (char)35, 0.600 }, - { (char)36, 0.600 }, - { (char)37, 0.600 }, - { (char)38, 0.600 }, - { (char)39, 0.600 }, - { (char)40, 0.600 }, - { (char)41, 0.600 }, - { (char)42, 0.600 }, - { (char)43, 0.600 }, - { (char)44, 0.600 }, - { (char)45, 0.600 }, - { (char)46, 0.600 }, - { (char)47, 0.600 }, - { (char)48, 0.600 }, - { (char)49, 0.600 }, - { (char)50, 0.600 }, - { (char)51, 0.600 }, - { (char)52, 0.600 }, - { (char)53, 0.600 }, - { (char)54, 0.600 }, - { (char)55, 0.600 }, - { (char)56, 0.600 }, - { (char)57, 0.600 }, - { (char)58, 0.600 }, - { (char)59, 0.600 }, - { (char)60, 0.600 }, - { (char)61, 0.600 }, - { (char)62, 0.600 }, - { (char)63, 0.600 }, - { (char)64, 0.600 }, - { (char)65, 0.600 }, - { (char)66, 0.600 }, - { (char)67, 0.600 }, - { (char)68, 0.600 }, - { (char)69, 0.600 }, - { (char)70, 0.600 }, - { (char)71, 0.600 }, - { (char)72, 0.600 }, - { (char)73, 0.600 }, - { (char)74, 0.600 }, - { (char)75, 0.600 }, - { (char)76, 0.600 }, - { (char)77, 0.600 }, - { (char)78, 0.600 }, - { (char)79, 0.600 }, - { (char)80, 0.600 }, - { (char)81, 0.600 }, - { (char)82, 0.600 }, - { (char)83, 0.600 }, - { (char)84, 0.600 }, - { (char)85, 0.600 }, - { (char)86, 0.600 }, - { (char)87, 0.600 }, - { (char)88, 0.600 }, - { (char)89, 0.600 }, - { (char)90, 0.600 }, - { (char)91, 0.600 }, - { (char)92, 0.600 }, - { (char)93, 0.600 }, - { (char)94, 0.600 }, - { (char)95, 0.600 }, - { (char)96, 0.600 }, - { (char)97, 0.600 }, - { (char)98, 0.600 }, - { (char)99, 0.600 }, - { (char)100, 0.600 }, - { (char)101, 0.600 }, - { (char)102, 0.600 }, - { (char)103, 0.600 }, - { (char)104, 0.600 }, - { (char)105, 0.600 }, - { (char)106, 0.600 }, - { (char)107, 0.600 }, - { (char)108, 0.600 }, - { (char)109, 0.600 }, - { (char)110, 0.600 }, - { (char)111, 0.600 }, - { (char)112, 0.600 }, - { (char)113, 0.600 }, - { (char)114, 0.600 }, - { (char)115, 0.600 }, - { (char)116, 0.600 }, - { (char)117, 0.600 }, - { (char)118, 0.600 }, - { (char)119, 0.600 }, - { (char)120, 0.600 }, - { (char)121, 0.600 }, - { (char)122, 0.600 }, - { (char)123, 0.600 }, - { (char)124, 0.600 }, - { (char)125, 0.600 }, - { (char)126, 0.600 }, - { (char)161, 0.600 }, - { (char)162, 0.600 }, - { (char)163, 0.600 }, - { (char)164, 0.600 }, - { (char)165, 0.600 }, - { (char)166, 0.600 }, - { (char)167, 0.600 }, - { (char)168, 0.600 }, - { (char)169, 0.600 }, - { (char)170, 0.600 }, - { (char)171, 0.600 }, - { (char)172, 0.600 }, - { (char)173, 0.600 }, - { (char)174, 0.600 }, - { (char)175, 0.600 }, - { (char)177, 0.600 }, - { (char)178, 0.600 }, - { (char)179, 0.600 }, - { (char)180, 0.600 }, - { (char)182, 0.600 }, - { (char)183, 0.600 }, - { (char)184, 0.600 }, - { (char)185, 0.600 }, - { (char)186, 0.600 }, - { (char)187, 0.600 }, - { (char)188, 0.600 }, - { (char)189, 0.600 }, - { (char)191, 0.600 }, - { (char)193, 0.600 }, - { (char)194, 0.600 }, - { (char)195, 0.600 }, - { (char)196, 0.600 }, - { (char)197, 0.600 }, - { (char)198, 0.600 }, - { (char)199, 0.600 }, - { (char)200, 0.600 }, - { (char)202, 0.600 }, - { (char)203, 0.600 }, - { (char)205, 0.600 }, - { (char)206, 0.600 }, - { (char)207, 0.600 }, - { (char)208, 0.600 }, - { (char)225, 0.600 }, - { (char)227, 0.600 }, - { (char)232, 0.600 }, - { (char)233, 0.600 }, - { (char)234, 0.600 }, - { (char)235, 0.600 }, - { (char)241, 0.600 }, - { (char)245, 0.600 }, - { (char)248, 0.600 }, - { (char)249, 0.600 }, - { (char)250, 0.600 }, - { (char)251, 0.600 }, - }; - #endregion - } - - public class Symbol - { - #region Definition - - public static double ApproxHeight = 1.000; - - public static Dictionary Widths = new Dictionary() - { - { (char)32, 0.250 }, - { (char)33, 0.333 }, - { (char)34, 0.713 }, - { (char)35, 0.500 }, - { (char)36, 0.549 }, - { (char)37, 0.833 }, - { (char)38, 0.778 }, - { (char)39, 0.439 }, - { (char)40, 0.333 }, - { (char)41, 0.333 }, - { (char)42, 0.500 }, - { (char)43, 0.549 }, - { (char)44, 0.250 }, - { (char)45, 0.549 }, - { (char)46, 0.250 }, - { (char)47, 0.278 }, - { (char)48, 0.500 }, - { (char)49, 0.500 }, - { (char)50, 0.500 }, - { (char)51, 0.500 }, - { (char)52, 0.500 }, - { (char)53, 0.500 }, - { (char)54, 0.500 }, - { (char)55, 0.500 }, - { (char)56, 0.500 }, - { (char)57, 0.500 }, - { (char)58, 0.278 }, - { (char)59, 0.278 }, - { (char)60, 0.549 }, - { (char)61, 0.549 }, - { (char)62, 0.549 }, - { (char)63, 0.444 }, - { (char)64, 0.549 }, - { (char)65, 0.722 }, - { (char)66, 0.667 }, - { (char)67, 0.722 }, - { (char)68, 0.612 }, - { (char)69, 0.611 }, - { (char)70, 0.763 }, - { (char)71, 0.603 }, - { (char)72, 0.722 }, - { (char)73, 0.333 }, - { (char)74, 0.631 }, - { (char)75, 0.722 }, - { (char)76, 0.686 }, - { (char)77, 0.889 }, - { (char)78, 0.722 }, - { (char)79, 0.722 }, - { (char)80, 0.768 }, - { (char)81, 0.741 }, - { (char)82, 0.556 }, - { (char)83, 0.592 }, - { (char)84, 0.611 }, - { (char)85, 0.690 }, - { (char)86, 0.439 }, - { (char)87, 0.768 }, - { (char)88, 0.645 }, - { (char)89, 0.795 }, - { (char)90, 0.611 }, - { (char)91, 0.333 }, - { (char)92, 0.863 }, - { (char)93, 0.333 }, - { (char)94, 0.658 }, - { (char)95, 0.500 }, - { (char)96, 0.500 }, - { (char)97, 0.631 }, - { (char)98, 0.549 }, - { (char)99, 0.549 }, - { (char)100, 0.494 }, - { (char)101, 0.439 }, - { (char)102, 0.521 }, - { (char)103, 0.411 }, - { (char)104, 0.603 }, - { (char)105, 0.329 }, - { (char)106, 0.603 }, - { (char)107, 0.549 }, - { (char)108, 0.549 }, - { (char)109, 0.576 }, - { (char)110, 0.521 }, - { (char)111, 0.549 }, - { (char)112, 0.549 }, - { (char)113, 0.521 }, - { (char)114, 0.549 }, - { (char)115, 0.603 }, - { (char)116, 0.439 }, - { (char)117, 0.576 }, - { (char)118, 0.713 }, - { (char)119, 0.686 }, - { (char)120, 0.493 }, - { (char)121, 0.686 }, - { (char)122, 0.494 }, - { (char)123, 0.480 }, - { (char)124, 0.200 }, - { (char)125, 0.480 }, - { (char)126, 0.549 }, - { (char)160, 0.750 }, - { (char)161, 0.620 }, - { (char)162, 0.247 }, - { (char)163, 0.549 }, - { (char)164, 0.167 }, - { (char)165, 0.713 }, - { (char)166, 0.500 }, - { (char)167, 0.753 }, - { (char)168, 0.753 }, - { (char)169, 0.753 }, - { (char)170, 0.753 }, - { (char)171, 1.042 }, - { (char)172, 0.987 }, - { (char)173, 0.603 }, - { (char)174, 0.987 }, - { (char)175, 0.603 }, - { (char)176, 0.400 }, - { (char)177, 0.549 }, - { (char)178, 0.411 }, - { (char)179, 0.549 }, - { (char)180, 0.549 }, - { (char)181, 0.713 }, - { (char)182, 0.494 }, - { (char)183, 0.460 }, - { (char)184, 0.549 }, - { (char)185, 0.549 }, - { (char)186, 0.549 }, - { (char)187, 0.549 }, - { (char)188, 1.000 }, - { (char)189, 0.603 }, - { (char)190, 1.000 }, - { (char)191, 0.658 }, - { (char)192, 0.823 }, - { (char)193, 0.686 }, - { (char)194, 0.795 }, - { (char)195, 0.987 }, - { (char)196, 0.768 }, - { (char)197, 0.768 }, - { (char)198, 0.823 }, - { (char)199, 0.768 }, - { (char)200, 0.768 }, - { (char)201, 0.713 }, - { (char)202, 0.713 }, - { (char)203, 0.713 }, - { (char)204, 0.713 }, - { (char)205, 0.713 }, - { (char)206, 0.713 }, - { (char)207, 0.713 }, - { (char)208, 0.768 }, - { (char)209, 0.713 }, - { (char)210, 0.790 }, - { (char)211, 0.790 }, - { (char)212, 0.890 }, - { (char)213, 0.823 }, - { (char)214, 0.549 }, - { (char)215, 0.250 }, - { (char)216, 0.713 }, - { (char)217, 0.603 }, - { (char)218, 0.603 }, - { (char)219, 1.042 }, - { (char)220, 0.987 }, - { (char)221, 0.603 }, - { (char)222, 0.987 }, - { (char)223, 0.603 }, - { (char)224, 0.494 }, - { (char)225, 0.329 }, - { (char)226, 0.790 }, - { (char)227, 0.790 }, - { (char)228, 0.786 }, - { (char)229, 0.713 }, - { (char)230, 0.384 }, - { (char)231, 0.384 }, - { (char)232, 0.384 }, - { (char)233, 0.384 }, - { (char)234, 0.384 }, - { (char)235, 0.384 }, - { (char)236, 0.494 }, - { (char)237, 0.494 }, - { (char)238, 0.494 }, - { (char)239, 0.494 }, - { (char)241, 0.329 }, - { (char)242, 0.274 }, - { (char)243, 0.686 }, - { (char)244, 0.686 }, - { (char)245, 0.686 }, - { (char)246, 0.384 }, - { (char)247, 0.384 }, - { (char)248, 0.384 }, - { (char)249, 0.384 }, - { (char)250, 0.384 }, - { (char)251, 0.384 }, - { (char)252, 0.494 }, - { (char)253, 0.494 }, - { (char)254, 0.494 }, - }; - #endregion - } - - public class ZapfDingbats - { - #region Definition - - public static double ApproxHeight = 1.000; - - public static Dictionary Widths = new Dictionary() - { - { (char)32, 0.278 }, - { (char)33, 0.974 }, - { (char)34, 0.961 }, - { (char)35, 0.974 }, - { (char)36, 0.980 }, - { (char)37, 0.719 }, - { (char)38, 0.789 }, - { (char)39, 0.790 }, - { (char)40, 0.791 }, - { (char)41, 0.690 }, - { (char)42, 0.960 }, - { (char)43, 0.939 }, - { (char)44, 0.549 }, - { (char)45, 0.855 }, - { (char)46, 0.911 }, - { (char)47, 0.933 }, - { (char)48, 0.911 }, - { (char)49, 0.945 }, - { (char)50, 0.974 }, - { (char)51, 0.755 }, - { (char)52, 0.846 }, - { (char)53, 0.762 }, - { (char)54, 0.761 }, - { (char)55, 0.571 }, - { (char)56, 0.677 }, - { (char)57, 0.763 }, - { (char)58, 0.760 }, - { (char)59, 0.759 }, - { (char)60, 0.754 }, - { (char)61, 0.494 }, - { (char)62, 0.552 }, - { (char)63, 0.537 }, - { (char)64, 0.577 }, - { (char)65, 0.692 }, - { (char)66, 0.786 }, - { (char)67, 0.788 }, - { (char)68, 0.788 }, - { (char)69, 0.790 }, - { (char)70, 0.793 }, - { (char)71, 0.794 }, - { (char)72, 0.816 }, - { (char)73, 0.823 }, - { (char)74, 0.789 }, - { (char)75, 0.841 }, - { (char)76, 0.823 }, - { (char)77, 0.833 }, - { (char)78, 0.816 }, - { (char)79, 0.831 }, - { (char)80, 0.923 }, - { (char)81, 0.744 }, - { (char)82, 0.723 }, - { (char)83, 0.749 }, - { (char)84, 0.790 }, - { (char)85, 0.792 }, - { (char)86, 0.695 }, - { (char)87, 0.776 }, - { (char)88, 0.768 }, - { (char)89, 0.792 }, - { (char)90, 0.759 }, - { (char)91, 0.707 }, - { (char)92, 0.708 }, - { (char)93, 0.682 }, - { (char)94, 0.701 }, - { (char)95, 0.826 }, - { (char)96, 0.815 }, - { (char)97, 0.789 }, - { (char)98, 0.789 }, - { (char)99, 0.707 }, - { (char)100, 0.687 }, - { (char)101, 0.696 }, - { (char)102, 0.689 }, - { (char)103, 0.786 }, - { (char)104, 0.787 }, - { (char)105, 0.713 }, - { (char)106, 0.791 }, - { (char)107, 0.785 }, - { (char)108, 0.791 }, - { (char)109, 0.873 }, - { (char)110, 0.761 }, - { (char)111, 0.762 }, - { (char)112, 0.762 }, - { (char)113, 0.759 }, - { (char)114, 0.759 }, - { (char)115, 0.892 }, - { (char)116, 0.892 }, - { (char)117, 0.788 }, - { (char)118, 0.784 }, - { (char)119, 0.438 }, - { (char)120, 0.138 }, - { (char)121, 0.277 }, - { (char)122, 0.415 }, - { (char)123, 0.392 }, - { (char)124, 0.392 }, - { (char)125, 0.668 }, - { (char)126, 0.668 }, - { (char)128, 0.390 }, - { (char)129, 0.390 }, - { (char)130, 0.317 }, - { (char)131, 0.317 }, - { (char)132, 0.276 }, - { (char)133, 0.276 }, - { (char)134, 0.509 }, - { (char)135, 0.509 }, - { (char)136, 0.410 }, - { (char)137, 0.410 }, - { (char)138, 0.234 }, - { (char)139, 0.234 }, - { (char)140, 0.334 }, - { (char)141, 0.334 }, - { (char)161, 0.732 }, - { (char)162, 0.544 }, - { (char)163, 0.544 }, - { (char)164, 0.910 }, - { (char)165, 0.667 }, - { (char)166, 0.760 }, - { (char)167, 0.760 }, - { (char)168, 0.776 }, - { (char)169, 0.595 }, - { (char)170, 0.694 }, - { (char)171, 0.626 }, - { (char)172, 0.788 }, - { (char)173, 0.788 }, - { (char)174, 0.788 }, - { (char)175, 0.788 }, - { (char)176, 0.788 }, - { (char)177, 0.788 }, - { (char)178, 0.788 }, - { (char)179, 0.788 }, - { (char)180, 0.788 }, - { (char)181, 0.788 }, - { (char)182, 0.788 }, - { (char)183, 0.788 }, - { (char)184, 0.788 }, - { (char)185, 0.788 }, - { (char)186, 0.788 }, - { (char)187, 0.788 }, - { (char)188, 0.788 }, - { (char)189, 0.788 }, - { (char)190, 0.788 }, - { (char)191, 0.788 }, - { (char)192, 0.788 }, - { (char)193, 0.788 }, - { (char)194, 0.788 }, - { (char)195, 0.788 }, - { (char)196, 0.788 }, - { (char)197, 0.788 }, - { (char)198, 0.788 }, - { (char)199, 0.788 }, - { (char)200, 0.788 }, - { (char)201, 0.788 }, - { (char)202, 0.788 }, - { (char)203, 0.788 }, - { (char)204, 0.788 }, - { (char)205, 0.788 }, - { (char)206, 0.788 }, - { (char)207, 0.788 }, - { (char)208, 0.788 }, - { (char)209, 0.788 }, - { (char)210, 0.788 }, - { (char)211, 0.788 }, - { (char)212, 0.894 }, - { (char)213, 0.838 }, - { (char)214, 1.016 }, - { (char)215, 0.458 }, - { (char)216, 0.748 }, - { (char)217, 0.924 }, - { (char)218, 0.748 }, - { (char)219, 0.918 }, - { (char)220, 0.927 }, - { (char)221, 0.928 }, - { (char)222, 0.928 }, - { (char)223, 0.834 }, - { (char)224, 0.873 }, - { (char)225, 0.828 }, - { (char)226, 0.924 }, - { (char)227, 0.924 }, - { (char)228, 0.917 }, - { (char)229, 0.930 }, - { (char)230, 0.931 }, - { (char)231, 0.463 }, - { (char)232, 0.883 }, - { (char)233, 0.836 }, - { (char)234, 0.836 }, - { (char)235, 0.867 }, - { (char)236, 0.867 }, - { (char)237, 0.696 }, - { (char)238, 0.696 }, - { (char)239, 0.874 }, - { (char)241, 0.874 }, - { (char)242, 0.760 }, - { (char)243, 0.946 }, - { (char)244, 0.771 }, - { (char)245, 0.865 }, - { (char)246, 0.771 }, - { (char)247, 0.888 }, - { (char)248, 0.967 }, - { (char)249, 0.888 }, - { (char)250, 0.831 }, - { (char)251, 0.873 }, - { (char)252, 0.927 }, - { (char)253, 0.970 }, - { (char)254, 0.918 }, - }; - #endregion - } - } -} diff --git a/VAR.PdfTools/PdfTextElement.cs b/VAR.PdfTools/PdfTextElement.cs deleted file mode 100644 index 629b5aa..0000000 --- a/VAR.PdfTools/PdfTextElement.cs +++ /dev/null @@ -1,149 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using VAR.PdfTools.Maths; - -namespace VAR.PdfTools -{ - public struct PdfCharElement - { - public string Char; - public double Displacement; - public double Width; - } - - public class PdfTextElement - { - #region Properties - - public PdfFont Font { get; set; } - - public double FontSize { get; set; } - - public Matrix3x3 Matrix { get; set; } - - public string RawText { get; set; } - - public string VisibleText { get; set; } - - public double VisibleWidth { get; set; } - - public double VisibleHeight { get; set; } - - public List Characters { get; set; } - - public List Childs { get; set; } - - #endregion - - #region Public methods - - public double GetX() - { - return Matrix.Matrix[0, 2]; - } - - public double GetY() - { - return Matrix.Matrix[1, 2]; - } - - public PdfTextElement SubPart(int startIndex, int endIndex) - { - PdfTextElement blockElem = new PdfTextElement - { - Font = null, - FontSize = FontSize, - Matrix = Matrix.Copy(), - RawText = RawText.Substring(startIndex, endIndex - startIndex), - VisibleText = VisibleText.Substring(startIndex, endIndex - startIndex), - VisibleWidth = 0, - VisibleHeight = VisibleHeight, - Characters = new List(), - Childs = new List(), - }; - double displacement = Characters[startIndex].Displacement; - blockElem.Matrix.Matrix[0, 2] += displacement; - for (int j = startIndex; j < endIndex; j++) - { - blockElem.Characters.Add(new PdfCharElement - { - Char = Characters[j].Char, - Displacement = Characters[j].Displacement - displacement, - Width = Characters[j].Width, - }); - } - PdfCharElement lastChar = blockElem.Characters[blockElem.Characters.Count - 1]; - blockElem.VisibleWidth = lastChar.Displacement + lastChar.Width; - foreach (PdfTextElement elem in Childs) - { - blockElem.Childs.Add(elem); - } - - return blockElem; - } - - public double MaxWidth() - { - return Characters.Average(c => c.Width); - } - - public Rect GetRect() - { - double x = GetX(); - double y = GetY(); - return new Rect - { - XMin = x, - YMax = y, - XMax = x + VisibleWidth, - YMin = y - VisibleHeight, - }; - } - - public double GetCharacterPreviousSpacing(int index) - { - if (index <= 0) { return 0; } - double previousEnd = Characters[index - 1].Displacement + Characters[index - 1].Width; - double spacing = Characters[index].Displacement - previousEnd; - return spacing; - } - - public double GetCharacterPrecedingSpacing(int index) - { - if (index >= (Characters.Count - 1)) { return 0; } - double currentEnd = Characters[index].Displacement + Characters[index].Width; - double spacing = Characters[index + 1].Displacement - currentEnd; - return spacing; - } - - #endregion - } - - public class PdfTextElementColumn - { - public PdfTextElement HeadTextElement { get; private set; } - - public IEnumerable Elements { get; private set; } - - public double Y { get; private set; } - - public double X1 { get; private set; } - public double X2 { get; private set; } - - public static PdfTextElementColumn Empty { get; } = new PdfTextElementColumn(); - - private PdfTextElementColumn() - { - Elements = new List(); - } - - public PdfTextElementColumn(PdfTextElement head, IEnumerable elements, double y, double x1, double x2) - { - HeadTextElement = head; - Elements = elements; - Y = y; - X1 = x1; - X2 = x2; - } - } -} diff --git a/VAR.PdfTools/PdfTextExtractor.cs b/VAR.PdfTools/PdfTextExtractor.cs deleted file mode 100644 index 2b64e75..0000000 --- a/VAR.PdfTools/PdfTextExtractor.cs +++ /dev/null @@ -1,856 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using VAR.PdfTools.Maths; -using VAR.PdfTools.PdfElements; - -namespace VAR.PdfTools -{ - public class PdfTextExtractor - { - #region Declarations - - private PdfDocumentPage _page = null; - - private List _textElements = new List(); - - // Graphics state - private List _graphicsMatrixStack = new List(); - private Matrix3x3 _graphicsMatrix = new Matrix3x3(); - - // Text state - private PdfFont _font = null; - private double _fontSize = 1; - private double _charSpacing = 0; - private double _wordSpacing = 0; - private double _textLeading = 0; - - // Text object state - private bool inText = false; - private Matrix3x3 _textMatrix = new Matrix3x3(); - private Matrix3x3 _textMatrixCurrent = new Matrix3x3(); - private StringBuilder _sbText = new StringBuilder(); - private double _textWidth = 0; - private List _listCharacters = new List(); - - #endregion - - #region Properties - - public PdfDocumentPage Page { get { return _page; } } - - public List Elements { get { return _textElements; } } - - #endregion - - #region lifecycle - - public PdfTextExtractor(PdfDocumentPage page) - { - _page = page; - ProcessPageContent(); - JoinTextElements(); - SplitTextElements(); - } - - #endregion - - #region Utility methods - - private string PdfString_ToUnicode(string text, PdfFont font) - { - if (font == null) - { - return text; - } - - StringBuilder sbText = new StringBuilder(); - foreach (char c in text) - { - sbText.Append(font.ToUnicode(c).Replace("\0", "")); - } - return sbText.ToString(); - } - - private PdfTextElement BuildTextElement() - { - PdfTextElement textElem = new PdfTextElement(); - textElem.Font = _font; - textElem.FontSize = _fontSize; - textElem.Matrix = _textMatrixCurrent.Multiply(_graphicsMatrix); - textElem.RawText = _sbText.ToString(); - textElem.VisibleText = PdfString_ToUnicode(textElem.RawText, _font); - PdfCharElement lastChar = _listCharacters[_listCharacters.Count - 1]; - textElem.VisibleWidth = (lastChar.Displacement + lastChar.Width) * textElem.Matrix.Matrix[0, 0]; - textElem.VisibleHeight = (_font.Height * _fontSize) * textElem.Matrix.Matrix[1, 1]; - textElem.Characters = new List(); - foreach (PdfCharElement c in _listCharacters) - { - textElem.Characters.Add(new PdfCharElement - { - Char = c.Char, - Displacement = (c.Displacement * textElem.Matrix.Matrix[0, 0]), - Width = (c.Width * textElem.Matrix.Matrix[0, 0]), - }); - } - textElem.Childs = new List(); - return textElem; - } - - private void AddTextElement(PdfTextElement textElement) - { - if (string.IsNullOrEmpty(textElement.VisibleText.Trim())) - { - return; - } - _textElements.Add(textElement); - } - - private void FlushTextElement() - { - if (_sbText.Length == 0) - { - _textWidth = 0; - return; - } - PdfTextElement textElem = BuildTextElement(); - AddTextElement(textElem); - - _textMatrixCurrent.Matrix[0, 2] += _textWidth; - - _sbText = new StringBuilder(); - _listCharacters.Clear(); - _textWidth = 0; - } - - private string SimplifyText(string text) - { - StringBuilder sbResult = new StringBuilder(); - foreach (char c in text) - { - if (c == '.' || c == ',' || - c == ':' || c == ';' || - c == '-' || c == '_' || - c == ' ' || c == '\t') - { - continue; - } - sbResult.Append(char.ToUpper(c)); - } - return sbResult.ToString(); - } - - private PdfTextElement FindElementByText(string text, bool fuzzy) - { - string matchingText = fuzzy ? SimplifyText(text) : text; - foreach (PdfTextElement elem in _textElements) - { - string elemText = fuzzy ? SimplifyText(elem.VisibleText) : elem.VisibleText; - if (elemText == matchingText) - { - return elem; - } - } - return null; - } - - private List FindElementsContainingText(string text, bool fuzzy) - { - List list = new List(); - string matchingText = fuzzy ? SimplifyText(text) : text; - foreach (PdfTextElement elem in _textElements) - { - string elemText = fuzzy ? SimplifyText(elem.VisibleText) : elem.VisibleText; - if (elemText.Contains(matchingText)) - { - list.Add(elem); - } - } - return list; - } - - private bool TextElementVerticalIntersection(PdfTextElement elem1, double elem2X1, double elem2X2) - { - double elem1X1 = elem1.GetX(); - double elem1X2 = elem1.GetX() + elem1.VisibleWidth; - - return elem1X2 >= elem2X1 && elem2X2 >= elem1X1; - } - - private bool TextElementVerticalIntersection(PdfTextElement elem1, PdfTextElement elem2) - { - double elem1X1 = elem1.GetX(); - double elem1X2 = elem1.GetX() + elem1.VisibleWidth; - double elem2X1 = elem2.GetX(); - double elem2X2 = elem2.GetX() + elem2.VisibleWidth; - - return elem1X2 >= elem2X1 && elem2X2 >= elem1X1; - } - - private bool TextElementHorizontalIntersection(PdfTextElement elem1, PdfTextElement elem2) - { - double elem1Y1 = elem1.GetY(); - double elem1Y2 = elem1.GetY() + elem1.VisibleHeight; - double elem2Y1 = elem2.GetY(); - double elem2Y2 = elem2.GetY() + elem2.VisibleHeight; - - return elem1Y2 >= elem2Y1 && elem2Y2 >= elem1Y1; - } - - #endregion - - #region Operations - - private void OpPushGraphState() - { - _graphicsMatrixStack.Add(_graphicsMatrix.Copy()); - } - - private void OpSetGraphMatrix(double a, double b, double c, double d, double e, double f) - { - _graphicsMatrix.Set(a, b, c, d, e, f); - } - - private void OpPopGraphState() - { - _graphicsMatrix = _graphicsMatrixStack[_graphicsMatrixStack.Count - 1]; - _graphicsMatrixStack.RemoveAt(_graphicsMatrixStack.Count - 1); - } - - private void OpBeginText() - { - _textMatrix.Idenity(); - _textMatrixCurrent.Idenity(); - inText = true; - } - - private void OpEndText() - { - FlushTextElement(); - inText = false; - } - - private void OpTextFont(string fontName, double size) - { - FlushTextElement(); - _font = _page.Fonts[fontName]; - _fontSize = size; - } - - private void OpTextCharSpacing(double charSpacing) - { - _charSpacing = charSpacing; - } - - private void OpTextWordSpacing(double wordSpacing) - { - _wordSpacing = wordSpacing; - } - - private void OpTextLeading(double textLeading) - { - _textLeading = textLeading; - } - - private void OpTextDisplace(double x, double y) - { - FlushTextElement(); - var newMatrix = new Matrix3x3(); - newMatrix.Matrix[0, 2] = x; - newMatrix.Matrix[1, 2] = y; - _textMatrix = newMatrix.Multiply(_textMatrix); - _textMatrixCurrent = _textMatrix.Copy(); - } - - private void OpTextLineFeed() - { - OpTextDisplace(0, -_textLeading); - } - - private void OpSetTextMatrix(double a, double b, double c, double d, double e, double f) - { - Matrix3x3 newMatrix = new Matrix3x3(a, b, c, d, e, f); - FlushTextElement(); - _textMatrix = newMatrix; - _textMatrixCurrent = _textMatrix.Copy(); - } - - private void OpTextPut(string text) - { - if (inText == false) { return; } - _sbText.Append(text); - if (_font != null) - { - foreach (char c in text) - { - string realChar = _font.ToUnicode(c); - if (realChar == "\0") { continue; } - double charWidth = _font.GetCharWidth(c) * _fontSize; - _listCharacters.Add(new PdfCharElement { Char = _font.ToUnicode(c), Displacement = _textWidth, Width = charWidth }); - _textWidth += charWidth; - _textWidth += ((c == 0x20) ? _wordSpacing : _charSpacing); - } - } - } - - private void OpTextPutMultiple(PdfArray array) - { - if (inText == false) { return; } - foreach (IPdfElement elem in array.Values) - { - if (elem is PdfString) - { - OpTextPut(((PdfString)elem).Value); - } - else if (elem is PdfInteger || elem is PdfReal) - { - double spacing = PdfElementUtils.GetReal(elem, 0); - _textWidth -= (spacing / 1000) * _fontSize; - } - else if (elem is PdfArray) - { - OpTextPutMultiple(((PdfArray)elem)); - } - } - } - - #endregion - - #region Private methods - - private void ProcessPageContent() - { - int unknowCount = 0; - int lineCount = 0; - int strokeCount = 0; - int pathCount = 0; - for (int i = 0; i < _page.ContentActions.Count; i++) - { - PdfContentAction action = _page.ContentActions[i]; - - // Special graphics state - if (action.Token == "q") - { - OpPushGraphState(); - } - else if (action.Token == "Q") - { - OpPopGraphState(); - } - else if (action.Token == "cm") - { - double a = PdfElementUtils.GetReal(action.Parameters[0], 0); - double b = PdfElementUtils.GetReal(action.Parameters[1], 0); - double c = PdfElementUtils.GetReal(action.Parameters[2], 0); - double d = PdfElementUtils.GetReal(action.Parameters[3], 0); - double e = PdfElementUtils.GetReal(action.Parameters[4], 0); - double f = PdfElementUtils.GetReal(action.Parameters[5], 0); - OpSetGraphMatrix(a, b, c, d, e, f); - } - - // Text Operations - else if (action.Token == "BT") - { - OpBeginText(); - } - else if (action.Token == "ET") - { - OpEndText(); - } - else if (action.Token == "Tc") - { - double charSpacing = PdfElementUtils.GetReal(action.Parameters[0], 0); - OpTextCharSpacing(charSpacing); - } - else if (action.Token == "Tw") - { - double wordSpacing = PdfElementUtils.GetReal(action.Parameters[0], 0); - OpTextWordSpacing(wordSpacing); - } - else if (action.Token == "Tz") - { - // TODO: PdfTextExtractor: Horizontal Scale - } - else if (action.Token == "Tf") - { - string fontName = PdfElementUtils.GetString(action.Parameters[0], string.Empty); - double fontSize = PdfElementUtils.GetReal(action.Parameters[1], 0); - OpTextFont(fontName, fontSize); - } - else if (action.Token == "TL") - { - double leading = PdfElementUtils.GetReal(action.Parameters[0], 0); - OpTextLeading(leading); - } - else if (action.Token == "Tr") - { - // TODO: PdfTextExtractor: Rendering mode - } - else if (action.Token == "Ts") - { - // TODO: PdfTextExtractor: Text rise - } - else if (action.Token == "Td") - { - double x = PdfElementUtils.GetReal(action.Parameters[0], 0); - double y = PdfElementUtils.GetReal(action.Parameters[1], 0); - OpTextDisplace(x, y); - } - else if (action.Token == "TD") - { - double x = PdfElementUtils.GetReal(action.Parameters[0], 0); - double y = PdfElementUtils.GetReal(action.Parameters[1], 0); - OpTextLeading(-y); - OpTextDisplace(x, y); - } - else if (action.Token == "Tm") - { - double a = PdfElementUtils.GetReal(action.Parameters[0], 0); - double b = PdfElementUtils.GetReal(action.Parameters[1], 0); - double c = PdfElementUtils.GetReal(action.Parameters[2], 0); - double d = PdfElementUtils.GetReal(action.Parameters[3], 0); - double e = PdfElementUtils.GetReal(action.Parameters[4], 0); - double f = PdfElementUtils.GetReal(action.Parameters[5], 0); - OpSetTextMatrix(a, b, c, d, e, f); - } - else if (action.Token == "T*") - { - OpTextLineFeed(); - } - else if (action.Token == "Tj") - { - string text = PdfElementUtils.GetString(action.Parameters[0], string.Empty); - OpTextPut(text); - } - else if (action.Token == "'") - { - string text = PdfElementUtils.GetString(action.Parameters[0], string.Empty); - OpTextLineFeed(); - OpTextPut(text); - } - else if (action.Token == "\"") - { - double wordSpacing = PdfElementUtils.GetReal(action.Parameters[0], 0); - double charSpacing = PdfElementUtils.GetReal(action.Parameters[1], 0); - string text = PdfElementUtils.GetString(action.Parameters[0], string.Empty); - OpTextCharSpacing(charSpacing); - OpTextWordSpacing(wordSpacing); - OpTextPut(text); - } - else if (action.Token == "TJ") - { - OpTextPutMultiple(((PdfArray)action.Parameters[0])); - } - else if (action.Token == "re") - { - // TODO: PdfTextExtractor: Interpret this - } - else if (action.Token == "f") - { - // TODO: PdfTextExtractor: Interpret this - } - else if (action.Token == "g") - { - // TODO: PdfTextExtractor: Interpret this - } - else if (action.Token == "rg") - { - // TODO: PdfTextExtractor: Interpret this - } - else if (action.Token == "BI") - { - // TODO: PdfTextExtractor: Interpret this - } - else if (action.Token == "ID") - { - // TODO: PdfTextExtractor: Interpret this - } - else if (action.Token == "EI") - { - // TODO: PdfTextExtractor: Interpret this - } - else if (action.Token == "W") - { - // TODO: PdfTextExtractor: Interpret this - } - else if (action.Token == "n") - { - // TODO: PdfTextExtractor: Interpret this - } - else if (action.Token == "Do") - { - // TODO: PdfTextExtractor: Interpret this - } - else if (action.Token == "m") - { - // TODO: PdfTextExtractor: Interpret this "moveto: Begin new subpath" - } - else if (action.Token == "l") - { - // TODO: PdfTextExtractor: Interpret this "lineto: Append straight line segment to path" - lineCount++; - } - else if (action.Token == "h") - { - // TODO: PdfTextExtractor: Interpret this "closepath: Close subpath" - pathCount++; - } - else if (action.Token == "W") - { - // TODO: PdfTextExtractor: Interpret this "clip: Set clipping path using nonzero winding number rule" - } - else if (action.Token == "W*") - { - // TODO: PdfTextExtractor: Interpret this "eoclip: Set clipping path using even-odd rule" - } - else if (action.Token == "w") - { - // TODO: PdfTextExtractor: Interpret this "setlinewidth: Set line width" - } - else if (action.Token == "G") - { - // TODO: PdfTextExtractor: Interpret this "setgray: Set gray level for stroking operations" - } - else if (action.Token == "S") - { - // TODO: PdfTextExtractor: Interpret this "stroke: Stroke path" - strokeCount++; - } - else if (action.Token == "M") - { - // TODO: PdfTextExtractor: Interpret this "setmiterlimit: Set miter limit" - } - else - { - unknowCount++; - } - } - FlushTextElement(); - } - - private void JoinTextElements() - { - var textElementsCondensed = new List(); - while (_textElements.Count > 0) - { - PdfTextElement elem = _textElements[0]; - _textElements.Remove(elem); - double blockY = elem.GetY(); - double blockXMin = elem.GetX(); - double blockXMax = blockXMin + elem.VisibleWidth; - - // Prepare first neighbour - var textElementNeighbours = new List(); - textElementNeighbours.Add(elem); - - // Search Neighbours - int i = 0; - while (i < _textElements.Count) - { - PdfTextElement neighbour = _textElements[i]; - - if (neighbour.Font != elem.Font || neighbour.FontSize != elem.FontSize) - { - i++; - continue; - } - - double neighbourY = neighbour.GetY(); - if (Math.Abs(neighbourY - blockY) > 0.001) { i++; continue; } - - double maxWidth = neighbour.MaxWidth(); - - double neighbourXMin = neighbour.GetX(); - double neighbourXMax = neighbourXMin + neighbour.VisibleWidth; - double auxBlockXMin = blockXMin - maxWidth; - double auxBlockXMax = blockXMax + maxWidth; - if (auxBlockXMax >= neighbourXMin && neighbourXMax >= auxBlockXMin) - { - _textElements.Remove(neighbour); - textElementNeighbours.Add(neighbour); - if (blockXMax < neighbourXMax) { blockXMax = neighbourXMax; } - if (blockXMin > neighbourXMin) { blockXMin = neighbourXMin; } - i = 0; - continue; - } - i++; - } - - if (textElementNeighbours.Count == 1) - { - textElementsCondensed.Add(elem); - continue; - } - - // Join neighbours - var chars = new List(); - foreach (PdfTextElement neighbour in textElementNeighbours) - { - double neighbourXMin = neighbour.GetX(); - foreach (PdfCharElement c in neighbour.Characters) - { - chars.Add(new PdfCharElement - { - Char = c.Char, - Displacement = (c.Displacement + neighbourXMin) - blockXMin, - Width = c.Width, - }); - } - } - chars = chars.OrderBy(c => c.Displacement).ToList(); - var sbText = new StringBuilder(); - foreach (PdfCharElement c in chars) - { - sbText.Append(c.Char); - } - PdfTextElement blockElem = new PdfTextElement - { - Font = null, - FontSize = elem.FontSize, - Matrix = elem.Matrix.Copy(), - RawText = sbText.ToString(), - VisibleText = sbText.ToString(), - VisibleWidth = blockXMax - blockXMin, - VisibleHeight = elem.VisibleHeight, - Characters = chars, - Childs = textElementNeighbours, - }; - blockElem.Matrix.Matrix[0, 2] = blockXMin; - textElementsCondensed.Add(blockElem); - } - _textElements = textElementsCondensed; - } - - private void SplitTextElements() - { - var textElementsSplitted = new List(); - while (_textElements.Count > 0) - { - PdfTextElement elem = _textElements[0]; - _textElements.Remove(elem); - - double maxWidth = elem.MaxWidth(); - - int prevBreak = 0; - for (int i = 1; i < elem.Characters.Count; i++) - { - double prevCharEnd = elem.Characters[i - 1].Displacement + elem.Characters[i - 1].Width; - double charSeparation = elem.Characters[i].Displacement - prevCharEnd; - if (charSeparation > maxWidth) - { - PdfTextElement partElem = elem.SubPart(prevBreak, i); - textElementsSplitted.Add(partElem); - prevBreak = i; - } - } - - if (prevBreak == 0) - { - textElementsSplitted.Add(elem); - continue; - } - PdfTextElement lastElem = elem.SubPart(prevBreak, elem.Characters.Count); - textElementsSplitted.Add(lastElem); - } - _textElements = textElementsSplitted; - } - - #endregion - - #region Public methods - - public Rect GetRect() - { - Rect rect = null; - foreach (PdfTextElement textElement in _textElements) - { - Rect elementRect = textElement.GetRect(); - if (rect == null) { rect = elementRect; } - rect.Add(elementRect); - } - return rect; - } - - public PdfTextElementColumn GetColumn(string column, bool fuzzy = true) - { - PdfTextElement columnHead = FindElementByText(column, fuzzy); - if (columnHead == null) - { - return PdfTextElementColumn.Empty; - } - double headY = columnHead.GetY() - columnHead.VisibleHeight; - double headX1 = columnHead.GetX(); - double headX2 = headX1 + columnHead.VisibleWidth; - - // Determine horizontal extent - double extentX1 = double.MinValue; - double extentX2 = double.MaxValue; - foreach (PdfTextElement elem in _textElements) - { - if (elem == columnHead) { continue; } - if (TextElementHorizontalIntersection(columnHead, elem) == false) { continue; } - double elemX1 = elem.GetX(); - double elemX2 = elemX1 + elem.VisibleWidth; - - if (elemX2 < headX1) - { - if (elemX2 > extentX1) - { - extentX1 = elemX2; - } - } - if (elemX1 > headX2) - { - if (elemX1 < extentX2) - { - extentX2 = elemX1; - } - } - } - - PdfTextElementColumn columnData = GetColumn(columnHead, headY, headX1, headX2, extentX1, extentX2); - - return columnData; - } - - public PdfTextElementColumn GetColumn(PdfTextElement columnHead, double headY, double headX1, double headX2, double extentX1, double extentX2) - { - // Get all the elements that intersects vertically, are down and sort results - var columnDataRaw = new List(); - foreach (PdfTextElement elem in _textElements) - { - if (TextElementVerticalIntersection(elem, headX1, headX2) == false) { continue; } - - // Only intems down the column - double elemY = elem.GetY(); - if (elemY >= headY) { continue; } - - columnDataRaw.Add(elem); - } - columnDataRaw = columnDataRaw.OrderByDescending(elem => elem.GetY()).ToList(); - - // Only items completelly inside extents, try spliting big elements and break on big elements that can't be splitted - var columnElements = new List(); - foreach (PdfTextElement elem in columnDataRaw) - { - double elemX1 = elem.GetX(); - double elemX2 = elemX1 + elem.VisibleWidth; - - // Add elements completely inside - if (elemX1 > extentX1 && elemX2 < extentX2) - { - columnElements.Add(elem); - continue; - } - - // Try to split elements intersecting extents of the column - double maxSpacing = elem.Characters.Average(c => c.Width) / 10; - int indexStart = 0; - int indexEnd = elem.Characters.Count - 1; - bool indexStartValid = true; - bool indexEndValid = true; - if (elemX1 < extentX1) - { - // Search best start - int index = 0; - double characterPosition = elemX1 + elem.Characters[index].Displacement; - while (characterPosition < extentX1 && index < (elem.Characters.Count - 1)) - { - index++; - characterPosition = elemX1 + elem.Characters[index].Displacement; - } - double spacing = elem.GetCharacterPreviousSpacing(index); - while (spacing < maxSpacing && index < (elem.Characters.Count - 1)) - { - index++; - spacing = elem.GetCharacterPreviousSpacing(index); - } - if (spacing < maxSpacing) { indexStartValid = false; } - indexStart = index; - } - - if (elemX2 > extentX2) - { - // Search best end - int index = elem.Characters.Count - 1; - double characterPosition = elemX1 + elem.Characters[index].Displacement + elem.Characters[index].Width; - while (characterPosition > extentX2 && index > 0) - { - index--; - characterPosition = elemX1 + elem.Characters[index].Displacement + elem.Characters[index].Width; - } - double spacing = elem.GetCharacterPrecedingSpacing(index); - while (spacing < maxSpacing && index > 0) - { - index--; - spacing = elem.GetCharacterPrecedingSpacing(index); - } - if (spacing < maxSpacing) { indexEndValid = false; } - indexEnd = index; - } - - // Break when there is no good split, spaning all extent - if (indexStartValid == false && indexEndValid == false) { break; } - - // Continue when only one of the sides is invalid. (outside elements intersecting extents of the column) - if (indexStartValid == false || indexEndValid == false) { continue; } - - // Add splitted element - columnElements.Add(elem.SubPart(indexStart, indexEnd + 1)); - } - - var columnData = new PdfTextElementColumn(columnHead, columnElements, headY, extentX1, extentX2); - return columnData; - } - - public List GetColumnAsStrings(string column, bool fuzzy = true) - { - PdfTextElementColumn columnData = GetColumn(column, fuzzy); - - // Emit result - var result = new List(); - foreach (PdfTextElement elem in columnData.Elements) - { - result.Add(elem.VisibleText); - } - return result; - } - - public string GetFieldAsString(string field, bool fuzzy = true) - { - PdfTextElement fieldTitle = FindElementByText(field, fuzzy); - if (fieldTitle == null) - { - return null; - } - double titleX = fieldTitle.GetX(); - var fieldData = new List(); - - - foreach (PdfTextElement elem in _textElements) - { - if (TextElementHorizontalIntersection(fieldTitle, elem) == false) { continue; } - double elemX = elem.GetX(); - if (elemX <= titleX) { continue; } - - fieldData.Add(elem); - } - - if (fieldData.Count == 0) - { - return null; - } - - return fieldData.OrderBy(elem => elem.GetX()).FirstOrDefault().VisibleText; - } - - public bool HasText(string text, bool fuzzy = true) - { - List list = FindElementsContainingText(text, fuzzy); - return (list.Count > 0); - } - - #endregion - } -} diff --git a/VAR.PdfTools/VAR.PdfTools.csproj b/VAR.PdfTools/VAR.PdfTools.csproj deleted file mode 100644 index a6174fe..0000000 --- a/VAR.PdfTools/VAR.PdfTools.csproj +++ /dev/null @@ -1,30 +0,0 @@ - - - netstandard2.0 - Library - true - true - - - VAR.PdfTools - VAR.PdfTools - 1.6.1 - PdfTools Library - VAR - VAR - Copyright © VAR 2016-2019 - false - LICENSE.txt - https://github.com/Kableado/VAR.PdfTools - PDF;PDF Library - - - - - - - - - - - \ No newline at end of file diff --git a/VAR.PdfTools/NuGet/keep.txt b/issues/.keep similarity index 100% rename from VAR.PdfTools/NuGet/keep.txt rename to issues/.keep