public override void Scan( ContentScanner.GraphicsState state ) { state.FillColorSpace = DeviceGrayColorSpace.Default; base.Scan(state); }
/** * <summary>Gets whether the specified content stream part is blank.</summary> * <param name="level">Content stream part to evaluate.</param> * <param name="contentBox">Area to evaluate within the page.</param> */ private static bool IsBlank(ContentScanner level, SKRect contentBox) { if (level == null) { return(true); } while (level.MoveNext()) { ContentObject content = level.Current; if (content is ContainerObject) { // Scan the inner level! if (!IsBlank(level.ChildLevel, contentBox)) { return(false); } } else { var contentWrapper = level.CurrentWrapper; if (contentWrapper == null) { continue; } if (contentWrapper.Box.Value.IntersectsWith(contentBox)) { return(false); } } } return(true); }
/** * <summary>Scans a content level looking for text.</summary> */ private void Extract( ContentScanner level, IList <ContentScanner.TextStringWrapper> extractedTextStrings ) { while (level.MoveNext()) { ContentObject content = level.Current; if (content is Text) { // Collect the text strings! foreach (ContentScanner.TextStringWrapper textString in ((ContentScanner.TextWrapper)level.CurrentWrapper).TextStrings) { extractedTextStrings.Add(textString); } } else if (content is ContainerObject) { // Scan the inner level! Extract( level.ChildLevel, extractedTextStrings ); } } }
public BlockComposer( PrimitiveComposer baseComposer ) { this.baseComposer = baseComposer; this.scanner = baseComposer.Scanner; }
/// <summary> /// Extraccción del texto de la página pasada por parámetro /// con sus respectivas propiedades /// (font, font size, text color, text rendering mode, text bounding box, etc.). /// </summary> /// <param name="page">Página de donde extraer el texto</param> public void TextInfoExtraction(Page page) { _PdfTextStrings = new List <PdfClownTextString>(); ContentScanner level = new ContentScanner(page); Extract(level); }
public override void Scan( ContentScanner.GraphicsState state ) { state.StrokeColorSpace = DeviceCMYKColorSpace.Default; base.Scan(state); }
private void Extract(ContentScanner level) { if (level == null) { return; } while (level.MoveNext()) { var content = level.Current; switch (content) { case ShowText text: { var font = level.State.Font; _contentList.Add(font.Decode(text.Text)); break; } case Text _: case ContainerObject _: Extract(level.ChildLevel); break; } } }
internal static GraphicsObjectWrapper Get(ContentScanner scanner) { var obj = scanner.Current; if (obj.Wrapper is GraphicsObjectWrapper exist) { return(exist); } if (obj is ShowText) { return(new TextStringWrapper(scanner)); } else if (obj is Text) { return(new TextWrapper(scanner)); } else if (obj is XObject) { return(new XObjectWrapper(scanner)); } else if (obj is InlineImage) { return(new InlineImageWrapper(scanner)); } else { return(null); } }
/** * <summary>Scans a content level looking for text.</summary> */ /* * NOTE: Page contents are represented by a sequence of content objects, * possibly nested into multiple levels. */ private void Extract( ContentScanner level ) { if (level == null) { return; } while (level.MoveNext()) { ContentObject content = level.Current; if (content is ShowText) { Font font = level.State.Font; // Extract the current text chunk, decoding it! Console.WriteLine(font.Decode(((ShowText)content).Text)); } else if (content is Text || content is ContainerObject) { // Scan the inner level! Extract(level.ChildLevel); } } }
public override void Scan( ContentScanner.GraphicsState state ) { ContentScanner scanner = state.Scanner; GraphicsPath pathObject = scanner.RenderObject; if (pathObject != null) { Graphics context = scanner.RenderContext; if (closed) { pathObject.CloseFigure(); } if (filled) { pathObject.FillMode = fillMode.ToGdi(); context.FillPath(state.FillColorSpace.GetPaint(state.FillColor), pathObject); } if (stroked) { context.DrawPath(GetStroke(state), pathObject); } } }
internal TextStringWrapper(ContentScanner scanner, bool scan = true) : base((ShowText)scanner.Current) { Context = scanner.ContentContext; Context.Strings.Add(this); textChars = new List <TextChar>(); { GraphicsState state = scanner.State; style = new TextStyle( state.Font, state.FontSize * state.TextState.Tm.ScaleY, state.RenderMode, state.StrokeColor, state.StrokeColorSpace, state.FillColor, state.FillColorSpace, state.Scale * state.TextState.Tm.ScaleX, state.TextState.Tm.ScaleY ); if (scan) { BaseDataObject.Scan( state, new ShowTextScanner(this) ); } } }
public override void Scan( ContentScanner.GraphicsState state ) { state.Tlm.Translate(0, (float)state.Lead); state.Tm = state.Tlm.Clone(); }
private void Convert(string path) { ConverterOptions options = GetConverterOptions(); if (path != null) { if (File.Exists(path)) { MarkdownPath = path; _htmlPath = null; Markdown = File.ReadAllText(path).Replace("\t", " "); ConvertMarkdownAndFillTextFields(Markdown, path); if (_useContentScanner) { print(ContentScanner.ParseScanrResults(ContentScanner.ScanMarkdown(Markdown))); } if (_saveOutputToHtml) { _htmlPath = DragonUtil.GetFullPathWithoutExtension(path) + ".html"; Converter.ConvertMarkdownFileToHtmlFile(path, _htmlPath, options); } UIManager.Instance.HideLoadingScreen(); UIManager.Instance.SetStatusText("Converted markdown! Copy HTML on right side or start Image Linker (experimental)."); } } else { UIManager.Instance.HideLoadingScreen(); UIManager.Instance.SetStatusText("No valid markdown chosen!"); } }
/** * <summary>Scans a content level looking for text.</summary> */ /* * NOTE: Page contents are represented by a sequence of content objects, * possibly nested into multiple levels. */ private void Extract( ContentScanner level, PrimitiveComposer composer ) { if (level == null) { return; } while (level.MoveNext()) { ContentObject content = level.Current; if (content is Text) { ContentScanner.TextWrapper text = (ContentScanner.TextWrapper)level.CurrentWrapper; int colorIndex = 0; foreach (ContentScanner.TextStringWrapper textString in text.TextStrings) { RectangleF textStringBox = textString.Box.Value; Console.WriteLine( "Text [" + "x:" + Math.Round(textStringBox.X) + "," + "y:" + Math.Round(textStringBox.Y) + "," + "w:" + Math.Round(textStringBox.Width) + "," + "h:" + Math.Round(textStringBox.Height) + "] [font size:" + Math.Round(textString.Style.FontSize) + "]: " + textString.Text ); // Drawing text character bounding boxes... colorIndex = (colorIndex + 1) % textCharBoxColors.Length; composer.SetStrokeColor(textCharBoxColors[colorIndex]); foreach (TextChar textChar in textString.TextChars) { /* * NOTE: You can get further text information * (font, font size, text color, text rendering mode) * through textChar.style. */ composer.DrawRectangle(textChar.Box); composer.Stroke(); } // Drawing text string bounding box... composer.BeginLocalState(); composer.SetLineDash(new LineDash(new double[] { 5, 5 })); composer.SetStrokeColor(textStringBoxColor); composer.DrawRectangle(textString.Box.Value); composer.Stroke(); composer.End(); } } else if (content is ContainerObject) { // Scan the inner level! Extract(level.ChildLevel, composer); } } }
/** * <summary>Gets the scanner for the contents of the painted external object.</summary> * <param name="context">Scanning context.</param> */ public ContentScanner GetScanner(ContentScanner context) { xObjects::XObject xObject = GetXObject(context.ContentContext); return(xObject is xObjects::FormXObject ? new ContentScanner((xObjects::FormXObject)xObject, context) : null); }
public override void Scan( ContentScanner.GraphicsState state ) { GraphicsPath pathObject = state.Scanner.RenderObject; if(pathObject != null) {pathObject.CloseFigure();} }
/** <summary>Scans a content level looking for text.</summary> */ /* NOTE: Page contents are represented by a sequence of content objects, possibly nested into multiple levels. */ private void Extract( ContentScanner level, PrimitiveComposer composer ) { if(level == null) return; while(level.MoveNext()) { ContentObject content = level.Current; if(content is Text) { ContentScanner.TextWrapper text = (ContentScanner.TextWrapper)level.CurrentWrapper; int colorIndex = 0; foreach(ContentScanner.TextStringWrapper textString in text.TextStrings) { RectangleF textStringBox = textString.Box.Value; Console.WriteLine( "Text [" + "x:" + Math.Round(textStringBox.X) + "," + "y:" + Math.Round(textStringBox.Y) + "," + "w:" + Math.Round(textStringBox.Width) + "," + "h:" + Math.Round(textStringBox.Height) + "] [font size:" + Math.Round(textString.Style.FontSize) + "]: " + textString.Text ); // Drawing text character bounding boxes... colorIndex = (colorIndex + 1) % textCharBoxColors.Length; composer.SetStrokeColor(textCharBoxColors[colorIndex]); foreach(TextChar textChar in textString.TextChars) { /* NOTE: You can get further text information (font, font size, text color, text rendering mode) through textChar.style. */ composer.DrawRectangle(textChar.Box); composer.Stroke(); } // Drawing text string bounding box... composer.BeginLocalState(); composer.SetLineDash(new LineDash(new double[]{5,5})); composer.SetStrokeColor(textStringBoxColor); composer.DrawRectangle(textString.Box.Value); composer.Stroke(); composer.End(); } } else if(content is ContainerObject) { // Scan the inner level! Extract(level.ChildLevel, composer); } } }
public void Render( drawing::Graphics context, drawing::SizeF size ) { ContentScanner scanner = new ContentScanner(Contents); scanner.Render(context, size); }
/// <summary> /// Extraccción del texto de la página pasada por parámetro /// con sus respectivas propiedades /// (font, font size, text color, text rendering mode, text bounding box, etc.). /// Este escaneo se realiza por niveles, ya que las páginas están representadas /// por una secuencia de Content Objects, posiblemente anidados en múltiples niveles. /// </summary> /// <param name="level">Nivel que estamos iterando</param> private void Extract(ContentScanner level) { if (level == null) { return; } while (level.MoveNext()) { ContentObject content = level.Current; if (content is Text) { //Guardamos los TextStrings con sus distintas propiedades ContentScanner.TextWrapper text = (ContentScanner.TextWrapper)level.CurrentWrapper; foreach (ContentScanner.TextStringWrapper textString in text.TextStrings) { _PdfTextStrings.Add(new PdfClownTextString( textString.Text, textString.Style.FillColor, textString.Style.StrokeColor, textString.Style.Font, textString.Style.FontSize) { Rectangle = textString.Box }); } } else if (content is XObject) { //Scanning the external level try { Extract(((XObject)content).GetScanner(level)); } catch (Exception e) { Console.WriteLine(e.StackTrace); Console.WriteLine("Soy la excepción de XObject"); } } else if (content is ContainerObject) { //Scanning the inner level try { Extract(level.ChildLevel); } catch (Exception e) { Console.WriteLine(e.StackTrace); Console.WriteLine("Soy la excepción de ContainerObject"); } } } }
public void Render(SKCanvas context, SKSize size, bool clearContext = true) { var scanner = new ContentScanner(Contents) { ClearContext = clearContext }; scanner.Render(context, size); }
internal InlineImageWrapper(ContentScanner scanner) : base((InlineImage)scanner.Current) { SKMatrix ctm = scanner.State.Ctm; this.box = SKRect.Create( ctm.TransX, scanner.ContextSize.Height - ctm.TransY, ctm.ScaleX, Math.Abs(ctm.ScaleY) ); }
private void RemoveLayerContents( ContentScanner level, ICollection <PdfName> layerEntityNames, ICollection <PdfName> layerXObjectNames, bool preserveContent ) { if (level == null) { return; } while (level.MoveNext()) { ContentObject content = level.Current; if (content is MarkedContent) { var markedContent = (MarkedContent)content; var marker = (ContentMarker)markedContent.Header; if (PdfName.OC.Equals(marker.Tag) && // NOTE: /OC tag identifies layer (aka optional content) markers. layerEntityNames.Contains(marker.Name)) { if (preserveContent) { level.Current = new ContentPlaceholder(markedContent.Objects); // Replaces the layer marked content block with an anonymous container, preserving its contents. } else { level.Remove(); // Removes the layer marked content block along with its contents. continue; } } } else if (!preserveContent && content is XObject) { var xObject = (XObject)content; if (layerXObjectNames.Contains(xObject.Name)) { level.Remove(); continue; } } if (content is ContainerObject) { // Scan the inner level! RemoveLayerContents( level.ChildLevel, layerEntityNames, layerXObjectNames, preserveContent ); } } }
public override void Scan( ContentScanner.GraphicsState state ) { ContentScanner childLevel = state.Scanner.ChildLevel; if(!Render(state)) {childLevel.MoveEnd();} // Forces the current object to its final graphics state. childLevel.State.CopyTo(state); // Copies the current object's final graphics state to the current level's. }
private void CreateReport(string markdownPath) { Console.WriteLine("Creating report..."); string text = DragonUtil.QuickReadFile(markdownPath); string report = ContentScanner.ParseScanrResults(ContentScanner.ScanMarkdown(text, markdownPath)); string savePath = Path.GetDirectoryName(markdownPath) + Path.GetFileNameWithoutExtension(markdownPath) + "_REPORT.txt"; DragonUtil.QuickWriteFile(savePath, report); Console.WriteLine("Saved report to " + savePath); }
internal XObjectWrapper(ContentScanner scanner) : base((XObject)scanner.Current) { SKMatrix ctm = scanner.State.Ctm; this.box = SKRect.Create( ctm.TransX, scanner.ContextSize.Height - ctm.TransY, ctm.ScaleX, Math.Abs(ctm.ScaleY) ); this.name = BaseDataObject.Name; this.xObject = BaseDataObject.GetResource(scanner.ContentContext); }
public override void Scan( ContentScanner.GraphicsState state ) { ContentScanner scanner = state.Scanner; GraphicsPath pathObject = scanner.RenderObject; if (pathObject != null) { pathObject.FillMode = clipMode.ToGdi(); scanner.RenderContext.SetClip(pathObject, CombineMode.Intersect); } }
/** <summary>Renders this container.</summary> <param name="state">Graphics state.</param> <returns>Whether the rendering has been executed.</returns> */ protected bool Render( ContentScanner.GraphicsState state ) { ContentScanner scanner = state.Scanner; Graphics context = scanner.RenderContext; if(context == null) return false; // Render the inner elements! scanner.ChildLevel.Render( context, scanner.CanvasSize, CreateRenderObject() ); return true; }
/** * <summary>Scans a content level looking for text.</summary> */ private void Extract( ContentScanner level, IList <ContentScanner.TextStringWrapper> extractedTextStrings ) { if (level == null) { return; } while (level.MoveNext()) { ContentObject content = level.Current; if (content is Text) { // Collect the text strings! foreach (ContentScanner.TextStringWrapper textString in ((ContentScanner.TextWrapper)level.CurrentWrapper).TextStrings) { if (textString.TextChars.Count > 0) { extractedTextStrings.Add(textString); } } } else if (content is XObject) { // Scan the external level! Extract( ((XObject)content).GetScanner(level), extractedTextStrings ); } else if (content is ContainerObject) { // Scan the inner level! Extract( level.ChildLevel, extractedTextStrings ); } } }
public override void Scan( ContentScanner.GraphicsState state ) { Graphics context = state.Scanner.RenderContext; if(context != null) { /* NOTE: Local graphics state is purposely isolated from surrounding graphics state, so no inner operation can alter its subsequent scanning. */ // Save outer graphics state! GraphicsState contextState = context.Save(); Render(state); // Restore outer graphics state! context.Restore(contextState); } }
private void Extract(ContentScanner level) { if (level == null) { return; } level.MoveStart(); while (level.MoveNext()) { ContentObject content = level.Current; if (content is ShowText) { textStrings.Add((TextStringWrapper)level.CurrentWrapper); } else if (content is ContainerObject) { Extract(level.ChildLevel); } } }
/** <summary>Scans a content level looking for text.</summary> */ /* NOTE: Page contents are represented by a sequence of content objects, possibly nested into multiple levels. */ private void Extract( ContentScanner level ) { if(level == null) return; while(level.MoveNext()) { ContentObject content = level.Current; if(content is ShowText) { Font font = level.State.Font; // Extract the current text chunk, decoding it! Console.WriteLine(font.Decode(((ShowText)content).Text)); } else if(content is Text || content is ContainerObject) { // Scan the inner level! Extract(level.ChildLevel); } } }
/** * <summary>Gets the scanner for this object's contents.</summary> * <param name="context">Scanning context.</param> */ public ContentScanner GetScanner( ContentScanner context ) { return(Operation.GetScanner(context)); }
/** * <summary>Scans a content level looking for images.</summary> */ /* * NOTE: Page contents are represented by a sequence of content objects, * possibly nested into multiple levels. */ private void Scan( ContentScanner level, Page page ) { if (level == null) { return; } while (level.MoveNext()) { ContentObject current = level.Current; if (current is ContainerObject) { // Scan the inner level! Scan( level.ChildLevel, page ); } else { ContentScanner.GraphicsObjectWrapper objectWrapper = level.CurrentWrapper; if (objectWrapper == null) { continue; } /* * NOTE: Images can be represented on a page either as * external objects (XObject) or inline objects. */ SizeF?imageSize = null; // Image native size. if (objectWrapper is ContentScanner.XObjectWrapper) { ContentScanner.XObjectWrapper xObjectWrapper = (ContentScanner.XObjectWrapper)objectWrapper; xObjects::XObject xObject = xObjectWrapper.XObject; // Is the external object an image? if (xObject is xObjects::ImageXObject) { Console.Write( "External Image '" + xObjectWrapper.Name + "' (" + xObject.BaseObject + ")" // Image key and indirect reference. ); imageSize = xObject.Size; // Image native size. } } else if (objectWrapper is ContentScanner.InlineImageWrapper) { Console.Write("Inline Image"); InlineImage inlineImage = ((ContentScanner.InlineImageWrapper)objectWrapper).InlineImage; imageSize = inlineImage.Size; // Image native size. } if (imageSize.HasValue) { RectangleF box = objectWrapper.Box.Value; // Image position (location and size) on the page. Console.WriteLine( " on page " + page.Number + " (" + page.BaseObject + ")" // Page index and indirect reference. ); Console.WriteLine(" Coordinates:"); Console.WriteLine(" x: " + Math.Round(box.X)); Console.WriteLine(" y: " + Math.Round(box.Y)); Console.WriteLine(" width: " + Math.Round(box.Width) + " (native: " + Math.Round(imageSize.Value.Width) + ")"); Console.WriteLine(" height: " + Math.Round(box.Height) + " (native: " + Math.Round(imageSize.Value.Height) + ")"); } } } }
public override void Scan( ContentScanner.GraphicsState state ) { state.MiterLimit = Value; }
public override void Scan( ContentScanner.GraphicsState state ) { ContentScanner scanner = state.Scanner; GraphicsPath pathObject = scanner.RenderObject; if(pathObject != null) { Graphics context = scanner.RenderContext; if(closed) { pathObject.CloseFigure(); } if(filled) { pathObject.FillMode = fillMode.ToGdi(); context.FillPath(state.FillColorSpace.GetPaint(state.FillColor), pathObject); } if(stroked) { context.DrawPath(GetStroke(state), pathObject); } } }
public void Render(SKCanvas context, SKSize size) { var scanner = new ContentScanner(Contents); scanner.Render(context, size); }
public override void Scan( ContentScanner.GraphicsState state ) { state.FillColor = state.FillColorSpace.GetColor( operands, state.Scanner.ContentContext ); }
public override void Scan( ContentScanner.GraphicsState state ) { state.Tlm.Translate((float)OffsetX, (float)OffsetY); state.Tm = state.Tlm.Clone(); if(LeadSet) {state.Lead = OffsetY;} }
public override void Scan( ContentScanner.GraphicsState state ) { state.Tlm = Value; state.Tm = state.Tlm.Clone(); }
/** <summary>Scans a content level looking for images.</summary> */ /* NOTE: Page contents are represented by a sequence of content objects, possibly nested into multiple levels. */ private void Scan( ContentScanner level, Page page ) { if(level == null) return; while(level.MoveNext()) { ContentObject current = level.Current; if(current is ContainerObject) { // Scan the inner level! Scan( level.ChildLevel, page ); } else { ContentScanner.GraphicsObjectWrapper objectWrapper = level.CurrentWrapper; if(objectWrapper == null) continue; /* NOTE: Images can be represented on a page either as external objects (XObject) or inline objects. */ SizeF? imageSize = null; // Image native size. if(objectWrapper is ContentScanner.XObjectWrapper) { ContentScanner.XObjectWrapper xObjectWrapper = (ContentScanner.XObjectWrapper)objectWrapper; xObjects::XObject xObject = xObjectWrapper.XObject; // Is the external object an image? if(xObject is xObjects::ImageXObject) { Console.Write( "External Image '" + xObjectWrapper.Name + "' (" + xObject.BaseObject + ")" // Image key and indirect reference. ); imageSize = xObject.Size; // Image native size. } } else if(objectWrapper is ContentScanner.InlineImageWrapper) { Console.Write("Inline Image"); InlineImage inlineImage = ((ContentScanner.InlineImageWrapper)objectWrapper).InlineImage; imageSize = inlineImage.Size; // Image native size. } if(imageSize.HasValue) { RectangleF box = objectWrapper.Box.Value; // Image position (location and size) on the page. Console.WriteLine( " on page " + (page.Index + 1) + " (" + page.BaseObject + ")" // Page index and indirect reference. ); Console.WriteLine(" Coordinates:"); Console.WriteLine(" x: " + Math.Round(box.X)); Console.WriteLine(" y: " + Math.Round(box.Y)); Console.WriteLine(" width: " + Math.Round(box.Width) + " (native: " + Math.Round(imageSize.Value.Width) + ")"); Console.WriteLine(" height: " + Math.Round(box.Height) + " (native: " + Math.Round(imageSize.Value.Height) + ")"); } } } }
private void Extract(ContentScanner level, List <Entry> entries) { if (level != null) { while (level.MoveNext()) { var content = level.Current; if (content is Text textContent) { var i = 0; var text = (ContentScanner.TextWrapper)level.CurrentWrapper; if (text.TextStrings.Count > 5) { if (text.TextStrings[0].Style.FontSize == 12 && (text.TextStrings[2].Text.StartsWith("(") || text.TextStrings[1].Text.StartsWith(" (") || text.TextStrings[i + 1].Text.StartsWith("("))) { if (currentSkill != "") { entries.Add(new Entry { Name = currentSkill, Description = currentDescription }); } currentSkill = text.TextStrings[0].Text; currentDescription = ""; for (; i < text.TextStrings.Count; i++) { if (text.TextStrings[i].Style.Font.Name.EndsWith("Italic")) { i++; break; } } } } if (!string.IsNullOrEmpty(currentSkill)) { for (; i < text.TextStrings.Count; i++) { if (text.TextStrings.Count > i + 5) { if (text.TextStrings[i].Style.FontSize == 12 && (text.TextStrings[i + 2].Text.StartsWith("(") || text.TextStrings[i + 1].Text.StartsWith(" (") || text.TextStrings[i + 1].Text.StartsWith("("))) { if (currentSkill != "") { entries.Add(new Entry { Name = currentSkill, Description = currentDescription }); } currentSkill = text.TextStrings[i].Text; currentDescription = ""; for (; i < text.TextStrings.Count; i++) { if (text.TextStrings[i].Style.Font.Name.EndsWith("Italic")) { i++; break; } } } } var textString = text.TextStrings[i]; if (textString.Text == "-" || Math.Abs(textString.Style.FontSize - 9) > 0.1) { continue; } if (textString.Style.Font.Name.EndsWith("Italic")) { currentDescription += "<i>" + textString.Text + "</i>"; } else if (textString.Style.Font.Name.EndsWith("Bold")) { currentDescription += "<b>" + textString.Text + "</b>"; } else if (textString.BaseDataObject.Operator.Equals("TJ") && i > 0 && text.TextStrings[i - 1].Text.EndsWith(".")) { currentDescription += "<br/>" + textString.Text; } else { currentDescription += textString.Text; } } } } else if (content is XObject) { Extract(((XObject)content).GetScanner(level), entries); } else if (content is ContainerObject) { Extract(level.ChildLevel, entries); } else { var contentType = content.GetType(); var wrapper = level.CurrentWrapper; if (wrapper != null) { var wrapperType = wrapper.GetType(); } } } } }
public override void Scan( ContentScanner.GraphicsState state ) { Scan(state, null); }
/** <summary>Executes scanning on this operation.</summary> <param name="state">Graphics state context.</param> <param name="textScanner">Scanner to be notified about text contents. In case it's null, the operation is applied to the graphics state context.</param> */ public void Scan( ContentScanner.GraphicsState state, IScanner textScanner ) { /* TODO: I really dislike this solution -- it's a temporary hack until the event-driven parsing mechanism is implemented... */ /* TODO: support to vertical writing mode. */ IContentContext context = state.Scanner.ContentContext; double contextHeight = context.Box.Height; Font font = state.Font; double fontSize = state.FontSize; double scale = state.Scale / 100; double scaledFactor = Font.GetScalingFactor(fontSize) * scale; double wordSpace = state.WordSpace * scale; double charSpace = state.CharSpace * scale; Matrix ctm = state.Ctm.Clone(); Matrix tm = state.Tm; if(this is ShowTextToNextLine) { ShowTextToNextLine showTextToNextLine = (ShowTextToNextLine)this; double? newWordSpace = showTextToNextLine.WordSpace; if(newWordSpace != null) { if(textScanner == null) {state.WordSpace = newWordSpace.Value;} wordSpace = newWordSpace.Value * scale; } double? newCharSpace = showTextToNextLine.CharSpace; if(newCharSpace != null) { if(textScanner == null) {state.CharSpace = newCharSpace.Value;} charSpace = newCharSpace.Value * scale; } tm = state.Tlm.Clone(); tm.Translate(0, (float)state.Lead); } else {tm = state.Tm.Clone();} foreach(object textElement in Value) { if(textElement is byte[]) // Text string. { string textString = font.Decode((byte[])textElement); foreach(char textChar in textString) { double charWidth = font.GetWidth(textChar) * scaledFactor; if(textScanner != null) { /* NOTE: The text rendering matrix is recomputed before each glyph is painted during a text-showing operation. */ Matrix trm = ctm.Clone(); trm.Multiply(tm); double charHeight = font.GetHeight(textChar,fontSize); drawing::RectangleF charBox = new drawing::RectangleF( trm.Elements[4], (float)(contextHeight - trm.Elements[5] - font.GetAscent(fontSize) * trm.Elements[3]), (float)charWidth * trm.Elements[0], (float)charHeight * trm.Elements[3] ); textScanner.ScanChar(textChar,charBox); } /* NOTE: After the glyph is painted, the text matrix is updated according to the glyph displacement and any applicable spacing parameter. */ tm.Translate((float)(charWidth + charSpace + (textChar == ' ' ? wordSpace : 0)), 0); } } else // Text position adjustment. {tm.Translate((float)(-Convert.ToSingle(textElement) * scaledFactor), 0);} } if(textScanner == null) { state.Tm = tm; if(this is ShowTextToNextLine) {state.Tlm = tm.Clone();} } }
public override void Scan( ContentScanner.GraphicsState state ) { GraphicsPath pathObject = state.Scanner.RenderObject; if(pathObject != null) { double x = X, y = Y, width = Width, height = Height; pathObject.AddRectangle( new RectangleF((float)x, (float)y, (float)width, (float)height) ); pathObject.CloseFigure(); } }
public override void Scan( ContentScanner.GraphicsState state ) { GraphicsPath pathObject = state.Scanner.RenderObject; if(pathObject != null) { PointF point = Point; pathObject.AddLine(pathObject.GetLastPoint(), point); } }
public override void Scan( ContentScanner.GraphicsState state ) { state.Lead = Value; }
private void ShowText( BlockComposer composer, PdfName fontName, double fontSize ) { PrimitiveComposer baseComposer = composer.BaseComposer; ContentScanner scanner = baseComposer.Scanner; RectangleF textBox = scanner.ContentContext.Box; if (scanner.State.Font == null) { /* * NOTE: A zero value for size means that the font is to be auto-sized: its size is computed as * a function of the height of the annotation rectangle. */ if (fontSize == 0) { fontSize = textBox.Height * 0.65; } baseComposer.SetFont(fontName, fontSize); } string text = (string)Value; FlagsEnum flags = Flags; if ((flags & FlagsEnum.Comb) == FlagsEnum.Comb && (flags & FlagsEnum.FileSelect) == 0 && (flags & FlagsEnum.Multiline) == 0 && (flags & FlagsEnum.Password) == 0) { int maxLength = MaxLength; if (maxLength > 0) { textBox.Width /= maxLength; for (int index = 0, length = text.Length; index < length; index++) { composer.Begin( textBox, XAlignmentEnum.Center, YAlignmentEnum.Middle ); composer.ShowText(text[index].ToString()); composer.End(); textBox.X += textBox.Width; } return; } } textBox.X += 2; textBox.Width -= 4; YAlignmentEnum yAlignment; if ((flags & FlagsEnum.Multiline) == FlagsEnum.Multiline) { yAlignment = YAlignmentEnum.Top; textBox.Y += (float)(fontSize * .35); textBox.Height -= (float)(fontSize * .7); } else { yAlignment = YAlignmentEnum.Middle; } composer.Begin( textBox, Justification.ToXAlignment(), yAlignment ); composer.ShowText(text); composer.End(); }
public override void Scan( ContentScanner.GraphicsState state ) { state.Ctm.Multiply(Value); Graphics context = state.Scanner.RenderContext; if(context != null) {context.Transform = state.Ctm;} }
private void RemoveLayerContents( Page page, ICollection <Layer> removedLayers, ICollection <LayerEntity> layerEntities, ICollection <xobjects::XObject> layerXObjects, bool preserveContent ) { var pageResources = page.Resources; // Collect the page's layer entities containing the layers! HashSet <PdfName> layerEntityNames = new HashSet <PdfName>(); var pagePropertyLists = pageResources.PropertyLists; foreach (var propertyListEntry in pagePropertyLists) { if (!(propertyListEntry.Value is LayerEntity)) { continue; } var layerEntity = (LayerEntity)propertyListEntry.Value; if (layerEntities.Contains(layerEntity)) { layerEntityNames.Add(propertyListEntry.Key); } else { var members = layerEntity.VisibilityMembers; foreach (var removedLayer in removedLayers) { if (members.Contains(removedLayer)) { layerEntityNames.Add(propertyListEntry.Key); layerEntities.Add(layerEntity); break; } } } } // Collect the page's xobjects associated to the layers! HashSet <PdfName> layerXObjectNames = new HashSet <PdfName>(); var pageXObjects = pageResources.XObjects; foreach (var xObjectEntry in pageXObjects) { if (layerXObjects.Contains(xObjectEntry.Value)) { layerXObjectNames.Add(xObjectEntry.Key); } else { if (layerEntities.Contains(xObjectEntry.Value.Layer)) { layerXObjectNames.Add(xObjectEntry.Key); layerXObjects.Add(xObjectEntry.Value); break; } } } // 1.1. Remove the layered contents from the page! if (layerEntityNames.Count > 0 || (!preserveContent && layerXObjectNames.Count > 0)) { var scanner = new ContentScanner(page); RemoveLayerContents(scanner, layerEntityNames, layerXObjectNames, preserveContent); scanner.Contents.Flush(); } // 1.2. Clean the page's layer entities from the purged references! foreach (var layerEntityName in layerEntityNames) { pagePropertyLists.Remove(layerEntityName); } // 1.3. Clean the page's xobjects from the purged references! if (!preserveContent) { foreach (var layerXObjectName in layerXObjectNames) { pageXObjects.Remove(layerXObjectName); } } // 1.4. Clean the page's annotations! { var pageAnnotations = page.Annotations; for (int index = pageAnnotations.Count - 1; index >= 0; index--) { var annotation = pageAnnotations[index]; if (layerEntities.Contains(annotation.Layer)) { if (preserveContent) { annotation.Layer = null; } else { annotation.Delete(); } } } } }
private static Pen GetStroke( ContentScanner.GraphicsState state ) { Pen stroke = new Pen( state.StrokeColorSpace.GetPaint(state.StrokeColor), (float)state.LineWidth ); { LineCap lineCap = state.LineCap.ToGdi(); stroke.SetLineCap(lineCap, lineCap, lineCap.ToDashCap()); stroke.LineJoin = state.LineJoin.ToGdi(); stroke.MiterLimit = (float)state.MiterLimit; LineDash lineDash = state.LineDash; double[] dashArray = lineDash.DashArray; if(dashArray != null && dashArray.Length > 0) { stroke.DashPattern = ConvertUtils.ToFloatArray(dashArray); stroke.DashOffset = (float)lineDash.DashPhase; } } return stroke; }
public override void Scan( ContentScanner.GraphicsState state ) { state.CharSpace = Value; }
public static ModifyCTM GetResetCTM( ContentScanner.GraphicsState state ) { Matrix inverseCtm = state.Ctm.Clone(); inverseCtm.Invert(); return new ModifyCTM( inverseCtm // TODO: inverseCtm is a simplification which assumes an identity initial ctm! // SquareMatrix.get(state.Ctm).solve( // SquareMatrix.get(state.GetInitialCtm()) // ).toTransform() ); }
public override void Scan( ContentScanner.GraphicsState state ) { state.RenderMode = Value; }
/** <summary>Applies this object to the specified graphics context, updating the specified graphics state.</summary> <param name="state">Graphics state.</param> */ public virtual void Scan( ContentScanner.GraphicsState state ) { /* Do nothing by default. */ }
public override void Scan( ContentScanner.GraphicsState state ) { ContentScanner scanner = state.Scanner; GraphicsPath pathObject = scanner.RenderObject; if(pathObject != null) { pathObject.FillMode = clipMode.ToGdi(); scanner.RenderContext.SetClip(pathObject, CombineMode.Intersect); } }
public override void Scan( ContentScanner.GraphicsState state ) { GraphicsPath pathObject = state.Scanner.RenderObject; if(pathObject != null) { PointF controlPoint1 = (Control1.HasValue ? Control1.Value : pathObject.GetLastPoint()); PointF finalPoint = Point; PointF controlPoint2 = (Control2.HasValue ? Control2.Value : finalPoint); pathObject.AddBezier( pathObject.GetLastPoint(), controlPoint1, controlPoint2, finalPoint ); } }