/// 获取当前选中元素 /// </summary> /// <returns></returns> public override StructElement GetCurrentElement() { if (this.m_textEditor == null || this.m_textEditor.IsDisposed) { return(null); } try { string expression = this.m_textEditor.GetFieldElemXmlPath(0); if (string.IsNullOrEmpty(expression)) { return(null); } string[] names = expression.Split(new char[] { '.' } , StringSplitOptions.RemoveEmptyEntries); if (names == null || names.Length <= 0) { return(null); } StructElement structElement = new StructElement(); structElement.ElementName = names[names.Length - 1]; return(structElement); } catch (Exception ex) { LogManager.Instance.WriteLog("HerenPad3Editor.GetCurrentElement", ex); return(null); } }
private Color[,] closing(Bitmap InputImage, StructElement structElement) { if (OutputImage != null) { OutputImage.Dispose(); // Reset output image } OutputImage = new Bitmap(InputImage.Size.Width, InputImage.Size.Height); // Create new output image Color[,] Image = new Color[InputImage.Size.Width, InputImage.Size.Height]; // Create array to speed-up operations (Bitmap functions are very slow) Color[,] output = new Color[InputImage.Size.Width, InputImage.Size.Height]; // Create array to speed-up operations (Bitmap functions are very slow) convertImageToString(Image); setupProgressBar(); if (isBinary(Image, InputImage.Size.Width, InputImage.Size.Height)) { output = dilatationBinary(Image, structElement); output = erosionBinary(output, structElement); } else { output = dilatationGray(Image, structElement); output = erosionGray(output, structElement); } return(output); }
GenerateChildrenSample() { var list = new List <IDiscriminatedElement>(); var ns = new NameSpaceElement(new PhysicalStorage(PathA)); AttachName(ns, NameSpaceA); var sample = new InterfaceElement(ns, ScopeCategories.Public, false, false); list.Add(AttachName(sample, "ISample")); IDiscriminatedElement tmp = new InterfaceElement(sample, ScopeCategories.Public, false, false); AttachName(tmp, "IInner"); list.Add(tmp); tmp = new StructElement(sample, ScopeCategories.Public, false, false); AttachName(tmp, "StructInner"); list.Add(tmp); tmp = new ClassElement(sample, ScopeCategories.Public, false, false, false, false, false); AttachName(tmp, "ReferenceInner"); list.Add(tmp); yield return(sample, list); }
public void InitChildElements(StructElement element) { foreach (var def in elementDefs) { var e = def.NewElement(element); e.Initialize(); } }
public override Element ReadElement( Container container, PluginFileSource source, UInt32?dataSize = null ) { var e = new StructElement(container, this); ReadChildElements(e, source, dataSize); return(e); }
private Color[,] dilatationGray(Color[,] Image, StructElement structElement) { if (OutputImage != null) { OutputImage.Dispose(); // Reset output image } OutputImage = new Bitmap(InputImage.Size.Width, InputImage.Size.Height); // Create new output image //Color[,] Image = new Color[InputImage.Size.Width, InputImage.Size.Height]; // Create array to speed-up operations (Bitmap functions are very slow) Color[,] output = new Color[InputImage.Size.Width, InputImage.Size.Height]; int[,] structMatrix = structElement.getMatrix(); for (int i = 0; i < InputImage.Size.Width; i++) { for (int j = 0; j < InputImage.Size.Height; j++) { output[i, j] = Color.FromArgb(255, 255, 255); } } int offset = (structElement.getSize() - 1) / 2; //convertImageToString(Image); setupProgressBar(); int value = 0; for (int u = offset; u < InputImage.Size.Width - offset; u++) { for (int v = offset; v < InputImage.Size.Height - offset; v++) { value = 0; for (int i = -offset; i < offset; i++) { for (int j = -offset; j < offset; j++) { if (structMatrix[i + offset, j + offset] != -256) //cell off { if (Image[u + i, v + j].R + structMatrix[i + offset, j + offset] > 255) { value = Math.Max(value, 255); } else { value = Math.Max(value, (Image[u + i, v + j].R) + (structMatrix[i + offset, j + offset])); } } } } output[u, v] = Color.FromArgb(value, value, value); progressBar.PerformStep(); } } return(output); }
private void TempletEditor_SelectionChanged(object sender, EventArgs e) { this.lblSelectedElement.Text = "请单击需要检索的元素"; StructElement selectedElement = this.TempletEditor.GetCurrentElement(); if (selectedElement != null) { this.lblSelectedElement.Text = "当前选择的元素:" + selectedElement.ElementName; this.SelectedElement = selectedElement; } }
private Color[,] erosionGray(Color[,] Image, StructElement structElement) { if (OutputImage != null) { OutputImage.Dispose(); // Reset output image } OutputImage = new Bitmap(InputImage.Size.Width, InputImage.Size.Height); // Create new output image Color[,] output = myColorInversion(Image); setupProgressBar(); return(myColorInversion(dilatationGray(output, structElement))); }
public override List <Field> GetFieldsForLucene() { List <Field> fields = new List <Field>(); StructElement structElement = (StructElement)programElement; fields.Add(new Field(SandoField.Namespace.ToString(), structElement.Namespace.ToSandoSearchable(), Field.Store.YES, Field.Index.ANALYZED)); AddBodyField(fields, new Field(SandoField.Body.ToString(), structElement.Body.ToSandoSearchable(), Field.Store.NO, Field.Index.ANALYZED)); fields.Add(new Field(SandoField.AccessLevel.ToString(), structElement.AccessLevel.ToString().ToLower(), Field.Store.YES, Field.Index.NOT_ANALYZED)); fields.Add(new Field(SandoField.ExtendedClasses.ToString(), structElement.ExtendedStructs.ToSandoSearchable(), Field.Store.YES, Field.Index.ANALYZED)); fields.Add(new Field(SandoField.Modifiers.ToString(), structElement.Modifiers, Field.Store.YES, Field.Index.ANALYZED)); return(fields); }
/// <summary> /// 获取当前选中元素 /// </summary> /// <returns></returns> public override StructElement GetCurrentElement() { TextField field = this.m_textEditor.GetCurrentField(); if (field != null) { StructElement element = new StructElement(); element.ElementID = field.ID; element.ElementName = field.Name; return(element); } return(null); }
StructType(Program program, StructElement element) : base(p) { super(program, new UserElementMixin(element)); this.structType = element.type(); ImmutableList.Builder <Field> fieldsBuilder = ImmutableList.builder(); for (FieldElement fieldElement : element.fields()) { fieldsBuilder.add(new Field(fieldElement)); } this.fields = fieldsBuilder.build(); }
public void TextTagBegin(GcPdfGraphics graphics, TextLayout textLayout, object tag) { int paragraphIndex; if (tag is int) { paragraphIndex = (int)tag; } else { paragraphIndex = -1; } StructElement paragraphElement; if (_currentParagraphIndex == paragraphIndex) { paragraphElement = _currentparagraphElement; } else { if (paragraphIndex >= 0) { paragraphElement = new StructElement("P"); ParentElement.Children.Add(paragraphElement); _currentparagraphElement = paragraphElement; _currentParagraphIndex = paragraphIndex; } else { paragraphElement = null; _currentparagraphElement = paragraphElement; _currentParagraphIndex = paragraphIndex; } } // if (paragraphElement != null) { graphics.BeginMarkedContent(new TagMcid("P", _tagIndex)); McrContentItemLink mcil = new McrContentItemLink(); mcil.MCID = _tagIndex; mcil.Page = Page; paragraphElement.ContentItems.Add(mcil); _tagIndex++; } }
private Color[,] geodesicDilatationGray(Color[,] Image, StructElement structElement, Bitmap controlImage) { if (OutputImage != null) { OutputImage.Dispose(); // Reset output image } OutputImage = new Bitmap(InputImage.Size.Width, InputImage.Size.Height); // Create new output image Color[,] controlImagee = new Color[InputImage2.Size.Width, InputImage2.Size.Height]; int[,] structMatrix = structElement.getMatrix(); Color[,] output = new Color[InputImage.Size.Width, InputImage.Size.Height]; convertImageToString2(controlImagee); output = dilatationGray(Image, structElement); output = myApplyMin(output, controlImagee); return(output); }
private Color[,] dilatationBinary(Color[,] Image, StructElement structElement) { if (OutputImage != null) { OutputImage.Dispose(); // Reset output image } OutputImage = new Bitmap(InputImage.Size.Width, InputImage.Size.Height); // Create new output image Color[,] output = new Color[InputImage.Size.Width, InputImage.Size.Height]; setupProgressBar(); int[,] H = structElement.getMatrix(); int Hsize = structElement.getSize(); for (int i = 0; i < InputImage.Size.Width; i++) { for (int j = 0; j < InputImage.Size.Height; j++) { output[i, j] = Color.FromArgb(255, 255, 255); } } for (int i = 0; i < Hsize; i++) { for (int j = 0; j < Hsize; j++) { if (H[i, j] == 1) { for (int u = 0; u < InputImage.Size.Width - Hsize; u++) { for (int v = 0; v < InputImage.Size.Height - Hsize; v++) { if (Image[u, v].R == 0) { output[u + i, v + j] = Color.FromArgb(0, 0, 0); } } } } } } return(output); }
public void CSharpStructParserTest() { SrcMLCSharpParser parser = new SrcMLCSharpParser(generator); var elements = parser.Parse("TestFiles\\Struct1.cs.txt"); bool hasStruct = false; foreach (var programElement in elements) { if (programElement as StructElement != null) { StructElement structElem = (StructElement)programElement; Assert.AreEqual(structElem.Name, "SimpleStruct"); Assert.AreEqual(structElem.DefinitionLineNumber, 6); Assert.AreEqual(structElem.Namespace, "SimpleNamespace"); Assert.AreEqual(structElem.AccessLevel, AccessLevel.Internal); Assert.True(structElem.FullFilePath.EndsWith("TestFiles\\Struct1.cs.txt")); hasStruct = true; } } Assert.IsTrue(hasStruct); }
private Color[,] erosion(Bitmap InputImage, StructElement structElement, Bitmap controlImage) // To adjust { if (OutputImage != null) { OutputImage.Dispose(); // Reset output image } OutputImage = new Bitmap(InputImage.Size.Width, InputImage.Size.Height); // Create new output image Color[,] Image = new Color[InputImage.Size.Width, InputImage.Size.Height]; // Create array to speed-up operations (Bitmap functions are very slow) Color[,] output = new Color[InputImage.Size.Width, InputImage.Size.Height]; int[,] structMatrix = structElement.getMatrix(); convertImageToString(Image); setupProgressBar(); if (isBinary(Image, InputImage.Size.Width, InputImage.Size.Height)) { MessageBox.Show("Binary!"); if (controlImage == null) { output = erosionBinary(Image, structElement); MessageBox.Show("Binary Erosion!"); } else { output = geodesicErosionBinary(Image, structElement, controlImage); } } else { if (controlImage == null) { output = erosionGray(Image, structElement); } else { output = geodesicErosionGray(Image, structElement, controlImage); } } return(output); }
GenerateDescendantsSample() { var list = new List <IDiscriminatedElement>(); var ns = new NameSpaceElement(new PhysicalStorage(PathA)); AttachName(ns, NameSpaceA); var sample = new InterfaceElement(ns, ScopeCategories.Public, false, false); var q = new QualifiedElement(sample); list.Add(q); list.Add(new IdentityElement(q, "ISample")); IDiscriminatedElement child = new ClassElement(sample, ScopeCategories.Public, false, false, false, false, false); q = new QualifiedElement(child); list.Add(child); list.Add(q); list.Add(new IdentityElement(q, "InnerClass")); child = new StructElement(sample, ScopeCategories.Public, false, false); q = new QualifiedElement(child); list.Add(child); list.Add(q); list.Add(new IdentityElement(q, "InnerStruct")); yield return(sample, list); child = new StructElement(child, ScopeCategories.Public, false, false); q = new QualifiedElement(child); list.Add(child); list.Add(q); list.Add(new IdentityElement(q, "InnerInner")); yield return(sample, list); }
public void WeirdStructTest() { //Note: may not want to create this in mydocuments.... //create a test file String WeirdStruct = "struct LangMenuItem { LangType _langType; int _cmdID; generic_string _langName; " + "LangMenuItem(LangType lt, int cmdID = 0, generic_string langName = TEXT(\"\")): " + "_langType(lt), _cmdID(cmdID), _langName(langName){};};"; String WeirdStructFile = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\HelloWorld1.cs"; System.IO.File.WriteAllText(WeirdStructFile, WeirdStruct); bool hasStruct = false; Guid structId = Guid.Empty; var parser = new SrcMLCppParser(generator); var elements = parser.Parse(WeirdStructFile); Assert.IsTrue(elements.Count == 2); foreach (ProgramElement pe in elements) { if (pe is StructElement) { StructElement structElement = (StructElement)pe; Assert.IsNotNull(structElement); Assert.AreEqual(structElement.Name, "LangMenuItem"); structId = structElement.Id; hasStruct = true; } else if (pe is MethodElement) { MethodElement methodElement = (MethodElement)pe; Assert.AreEqual(methodElement.ClassId, structId); } } Assert.IsTrue(hasStruct); //delete file System.IO.File.Delete(WeirdStructFile); }
// TODO: rewrite this better or make it unnecessary? public void ReadChildElements( StructElement element, PluginFileSource source, UInt32?dataSize ) { var startPos = source.stream.Position; var lastDefIndex = elementDefs.Count - 1; for (int i = 0; i <= lastDefIndex; i++) { var def = elementDefs[i]; if (source.stream.Position - startPos >= dataSize) { def.NewElement(element); } else { UInt32?remainingSize = (i == lastDefIndex) ? GetRemainingSize(source, startPos, dataSize) : null; def.ReadElement(element, source, remainingSize); } } }
public StructElement ToStructElement( MainRecord rec, PluginFileSource source ) { var headerDef = rec.mrDef.headerDef; var structElement = new StructElement(rec, headerDef); var defs = headerDef.elementDefs; int i = 0; ValueElement.Init(structElement, defs[i++], signature.ToString()); ValueElement.Init(structElement, defs[i++], dataSize); ValueElement.Init(structElement, defs[i++], flags); var targetFile = rec.file.OrdinalToFile((byte)(formId >> 24), false); var fid = new FormId(targetFile, formId & 0xFFFFFF); ValueElement.Init(structElement, defs[i++], fid); source.stream.Position += 16; for (; i < defs.Count; i++) { defs[i].ReadElement(structElement, source); } return(structElement); }
public virtual MethodElement ParseCppFunction(XElement function, List <ProgramElement> programElements, string fileName, string[] includedFiles, Type resolvedType, Type unresolvedType, bool isConstructor = false) { try { MethodElement methodElement = null; string source = String.Empty; int definitionLineNumber = 0; int definitionColumnNumber = 0; string returnType = String.Empty; XElement type = function.Element(SRC.Type); if (type != null) { XElement typeName = type.Element(SRC.Name); returnType = typeName.Value; } XElement paramlist = function.Element(SRC.ParameterList); IEnumerable <XElement> argumentElements = from el in paramlist.Descendants(SRC.Name) select el; string arguments = String.Empty; foreach (XElement elem in argumentElements) { arguments += elem.Value + " "; } arguments = arguments.TrimEnd(); string body = SrcMLParsingUtils.ParseBody(function); string fullFilePath = System.IO.Path.GetFullPath(fileName); XElement nameElement = function.Element(SRC.Name); string wholeName = nameElement.Value; if (wholeName.Contains("::")) { //class function string[] twonames = wholeName.Split("::".ToCharArray()); string funcName = twonames[2]; string className = twonames[0]; definitionLineNumber = Int32.Parse(nameElement.Element(SRC.Name).Attribute(POS.Line).Value); definitionColumnNumber = Int32.Parse(nameElement.Element(SRC.Name).Attribute(POS.Column).Value); source = SrcMLParsingUtils.RetrieveSource(function); return(Activator.CreateInstance(unresolvedType, funcName, definitionLineNumber, definitionColumnNumber, fullFilePath, source, arguments, returnType, body, className, isConstructor, includedFiles) as MethodElement); } else { //regular C-type function, or an inlined class function string funcName = wholeName; definitionLineNumber = Int32.Parse(nameElement.Attribute(POS.Line).Value); definitionColumnNumber = Int32.Parse(nameElement.Attribute(POS.Column).Value); source = SrcMLParsingUtils.RetrieveSource(function); AccessLevel accessLevel = RetrieveCppAccessLevel(function); Guid classId = Guid.Empty; string className = String.Empty; ClassElement classElement = SrcMLParsingUtils.RetrieveClassElement(function, programElements); StructElement structElement = RetrieveStructElement(function, programElements); if (classElement != null) { classId = classElement.Id; className = classElement.Name; } else if (structElement != null) { classId = structElement.Id; className = structElement.Name; } methodElement = Activator.CreateInstance(resolvedType, funcName, definitionLineNumber, definitionColumnNumber, fullFilePath, source, accessLevel, arguments, returnType, body, classId, className, String.Empty, isConstructor) as MethodElement; } return(methodElement); } catch (Exception error) { FileLogger.DefaultLogger.Info("Exception in SrcMLCppParser " + error.Message + "\n" + error.StackTrace); return(null); } }
public void CreatePDF(Stream stream) { var doc = new GcPdfDocument(); var date = new DateTime(1961, 4, 12, 6, 7, 0, DateTimeKind.Utc); // Mark the document as PDF/A-3u conformant: doc.ConformanceLevel = PdfAConformanceLevel.PdfA3u; var fnt = Font.FromFile(Path.Combine("Resources", "Fonts", "arial.ttf")); var gap = 36; // PDF/A-3a requires all content to be tagged so create and populate StructElement when rendering: StructElement sePart = new StructElement("Part"); doc.StructTreeRoot.Children.Add(sePart); TextLayout tl = null; // Add 3 pages with sample content tagged according to PDF/A rules: for (int pageNo = 1; pageNo <= 3; ++pageNo) { var page = doc.Pages.Add(); var g = page.Graphics; float y = 72; if (doc.Pages.Count == 1) { // Create paragraph element: var seParagraph = new StructElement("P") { DefaultPage = page }; // Add it to Part element: sePart.Children.Add(seParagraph); tl = g.CreateTextLayout(); tl.MarginAll = 72; tl.MaxWidth = page.Size.Width; tl.DefaultFormat.Font = fnt; tl.DefaultFormat.FontBold = true; tl.DefaultFormat.FontSize = 20; tl.Append("PDF/A-3A Document"); // PerformLayout is done automatically in a new TextLayout or after a Clear(): //tl.PerformLayout(true); // Draw TextLayout within tagged content: g.BeginMarkedContent(new TagMcid("P", 0)); g.DrawTextLayout(tl, PointF.Empty); g.EndMarkedContent(); y = tl.ContentRectangle.Bottom + gap; seParagraph.ContentItems.Add(new McidContentItemLink(0)); } // Add some sample paragraphs tagged according to PDF/A rules: for (int i = 1; i <= 3; ++i) { // Create paragraph element: var seParagraph = new StructElement("P") { DefaultPage = page }; // Add it to Part element: sePart.Children.Add(seParagraph); var sb = new StringBuilder(); sb.Append(string.Format("Paragraph {0} on page {1}: ", i, pageNo)); sb.Append(Common.Util.LoremIpsum(1, 2, 4, 5, 10)); var para = sb.ToString(); tl.Clear(); tl.DefaultFormat.FontSize = 14; tl.DefaultFormat.FontBold = false; tl.MarginTop = y; tl.Append(para); // Draw TextLayout within tagged content: g.BeginMarkedContent(new TagMcid("P", i)); g.DrawTextLayout(tl, PointF.Empty); g.EndMarkedContent(); y += tl.ContentHeight + gap; // Add content item to paragraph StructElement: seParagraph.ContentItems.Add(new McidContentItemLink(i)); // PDF/A-3 allows to embed files into document, but they should be associated with some document element // add embedded file associated with seParagraph: var ef1 = EmbeddedFileStream.FromBytes(doc, Encoding.UTF8.GetBytes(para)); // ModificationDate and MimeType should be specified in case of PDF/A: ef1.ModificationDate = date; ef1.MimeType = "text/plain"; var fn = string.Format("Page{0}_Paragraph{1}.txt", pageNo, i); var fs1 = FileSpecification.FromEmbeddedStream(fn, ef1); // Relationship should be specified in case of PDF/A: fs1.Relationship = AFRelationship.Unspecified; doc.EmbeddedFiles.Add(fn, fs1); seParagraph.AssociatedFiles.Add(fs1); } } // PDF/A-3 allows transparency drawing in PDF file, add some: var gpage = doc.Pages[0].Graphics; gpage.FillRectangle(new RectangleF(20, 20, 200, 200), Color.FromArgb(40, Color.Red)); // PDF/A-3 allows to use FormXObjects, add one with transparency: var r = new RectangleF(0, 0, 144, 72); var fxo = new FormXObject(doc, r); var gfxo = fxo.Graphics; gfxo.FillRectangle(r, Color.FromArgb(40, Color.Violet)); TextFormat tf = new TextFormat() { Font = fnt, FontSize = 16, ForeColor = Color.FromArgb(100, Color.Black), }; gfxo.DrawString("FormXObject", tf, r, TextAlignment.Center, ParagraphAlignment.Center); gfxo.DrawRectangle(r, Color.Blue, 3); gpage.DrawForm(fxo, new RectangleF(300, 250, r.Width, r.Height), null, ImageAlign.ScaleImage); // PDF/A-3 allows to use embedded files, but each embedded file must be associated with a document's element: EmbeddedFileStream ef = EmbeddedFileStream.FromFile(doc, Path.Combine("Resources", "WordDocs", "ProcurementLetter.docx")); // ModificationDate and MimeType should be specified for EmbeddedFile in PDF/A: ef.ModificationDate = date; ef.MimeType = "application/msword"; var fs = FileSpecification.FromEmbeddedFile(ef); fs.Relationship = AFRelationship.Unspecified; doc.EmbeddedFiles.Add("ProcurementLetter.docx", fs); // Associate embedded file with the document: doc.AssociatedFiles.Add(fs); // Add an attachment associated with an annotation: var sa = new StampAnnotation() { UserName = "******", Font = fnt, Rect = new RectangleF(300, 36, 220, 72), }; sa.Flags |= AnnotationFlags.Print; // Use a FormXObject to represent the stamp annotation: var stampFxo = new FormXObject(doc, new RectangleF(PointF.Empty, sa.Rect.Size)); var gstampFxo = stampFxo.Graphics; gstampFxo.FillRectangle(stampFxo.Bounds, Color.FromArgb(40, Color.Green)); gstampFxo.DrawString("Stamp Annotation\nassociated with minerva.jpg", tf, stampFxo.Bounds, TextAlignment.Center, ParagraphAlignment.Center); gstampFxo.DrawRectangle(stampFxo.Bounds, Color.Green, 3); // sa.AppearanceStreams.Normal.Default = stampFxo; doc.Pages[0].Annotations.Add(sa); ef = EmbeddedFileStream.FromFile(doc, Path.Combine("Resources", "Images", "minerva.jpg")); ef.ModificationDate = date; ef.MimeType = "image/jpeg"; fs = FileSpecification.FromEmbeddedFile(ef); fs.Relationship = AFRelationship.Unspecified; doc.EmbeddedFiles.Add("minerva.jpg", fs); sa.AssociatedFiles.Add(fs); // Mark the document as conforming to Tagged PDF conventions (required for PDF/A): doc.MarkInfo.Marked = true; // Metadata.CreatorTool and DocumentInfo.Creator should be the same for a PDF/A document: doc.Metadata.CreatorTool = doc.DocumentInfo.Creator; // A title should be specified for PDF/A document: doc.Metadata.Title = "GcPdf Document"; doc.ViewerPreferences.DisplayDocTitle = true; // Done: doc.Save(stream); }
public int CreatePDF(Stream stream) { var doc = new GcPdfDocument(); var rnd = Common.Util.NewRandom(); int pageCount = rnd.Next(3, 7); // Create Part element, it will contain P (paragraph) elements StructElement sePart = new StructElement("Part"); doc.StructTreeRoot.Children.Add(sePart); // Add some pages, on each page add some paragraphs and tag them: for (int pageIndex = 0; pageIndex < pageCount; ++pageIndex) { // Add page: var page = doc.Pages.Add(); var g = page.Graphics; const float margin = 36; const float dy = 18; // Add some paragraphs: int paraCount = rnd.Next(1, 5); float y = margin; for (int i = 0; i < paraCount; ++i) { // Create paragraph element: StructElement seParagraph = new StructElement("P") { DefaultPage = page }; // Add it to Part element: sePart.Children.Add(seParagraph); // Create paragraph: var tl = g.CreateTextLayout(); tl.DefaultFormat.Font = StandardFonts.Helvetica; tl.DefaultFormat.FontSize = 12; tl.Append(Common.Util.LoremIpsum(1, 1, 5, 5, 10)); tl.MaxWidth = page.Size.Width; tl.MarginLeft = tl.MarginRight = margin; tl.PerformLayout(true); // Draw TextLayout within tagged content: g.BeginMarkedContent(new TagMcid("P", i)); g.DrawTextLayout(tl, new PointF(0, y)); g.EndMarkedContent(); y += tl.ContentHeight + dy; // Add content item to paragraph StructElement: seParagraph.ContentItems.Add(new McidContentItemLink(i)); } } // Mark document as tagged: doc.MarkInfo.Marked = true; // Done: doc.Save(stream); return(doc.Pages.Count); }
public void CreatePDF(Stream stream) { var doc = new GcPdfDocument(); // Create a Part element, it will contain P (paragraph) elements: StructElement sePart = new StructElement("Part"); doc.StructTreeRoot.Children.Add(sePart); // Create and set up a TextLayout to render paragraphs: var tl = new TextLayout(72); tl.DefaultFormat.Font = StandardFonts.Times; tl.DefaultFormat.FontSize = 12; tl.FirstLineIndent = 72 / 2; tl.MaxWidth = doc.PageSize.Width; tl.MaxHeight = doc.PageSize.Height; tl.MarginAll = tl.Resolution; // // Append the text (20 paragraphs so they would not fit on a single page) // (note that TextLayout interprets "\r\n" as paragraph delimiter): // // Get the text (20 paragraphs): var text = Common.Util.LoremIpsum(20); // In order to tag the individual paragraphs, we need to split the text into paragraphs, // and use each paragraph format's Tag property (which is not related to PDF tags, // it is just an arbitrary data that can be associated with a TextFormat) to add the // paragraph's index to the paragraph: var pars = text.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < pars.Length; ++i) { var tf = new TextFormat(tl.DefaultFormat) { Tag = i }; tl.AppendLine(pars[i], tf); } // Layout the text: tl.PerformLayout(true); // Use split options to provide widow/orphan control: TextSplitOptions to = new TextSplitOptions(tl) { MinLinesInFirstParagraph = 2, MinLinesInLastParagraph = 2, }; // TextLayoutHandler implements ITextLayoutHandler, which // allows to tag the text as it is rendered: TextLayoutHandler tlh = new TextLayoutHandler() { ParentElement = sePart }; // In a loop, split and render the text: while (true) { // 'rest' will accept the text that did not fit: var splitResult = tl.Split(to, out TextLayout rest); var page = doc.Pages.Add(); var g = page.Graphics; // Tell the TextLayoutHandler which page we're on: tlh.Page = page; // ..and associate it with the graphics: g.TextLayoutHandler = tlh; // Draw the text that fits on the current page, and advance to next page unless we're done: g.DrawTextLayout(tl, PointF.Empty); if (splitResult != SplitResult.Split) { break; } tl = rest; } // Mark document as tagged: doc.MarkInfo.Marked = true; // Done: doc.Save(stream); }
public StructDocument(StructElement element) : base(element) { }
private static IEnumerable <string> ExtractStructWords(StructElement element) { return(GetDefaultLetterWords(element.Name + " " + element.Namespace)); }
public UserElementMixin(StructElement s) : this(s.Name, s.Location, s.Documentation, s.Annotations) { }