public Rectangle GetRect(int i, int n) { TextChar start = GetChar(i); TextChar end = GetChar(i + n - 1); return(start == null || end == null ? null : new Rectangle(start.x1, start.y1, end.x2 - start.x1 + 1, end.y2 - start.y1 + 1)); }
public bool AddChar(TextChar c) { float cy = (c.y1 + c.y2) / 2; if (chars.Count == 0) { this.y1 = c.y1; this.y2 = c.y2; chars.Add(c); return(true); } if (this.y1 <= cy && cy <= this.y2) { if (c.y1 < this.y1) { this.y1 = c.y1; } if (c.y2 > this.y2) { this.y2 = c.y2; } chars.Add(c); return(true); } return(false); }
public void Finish() { chars = chars.OrderBy((TextChar a) => a.x1).ToList(); var nchars = new List <TextChar> (); words = new List <TextWord> (); TextWord word = null; foreach (TextChar c in chars) { if (word == null || word.AddChar(c) == false) { if (word != null) { TextChar c2 = new TextChar(); c2.x1 = c.x1; c2.y1 = c.y1; c2.x2 = c.x2; c2.y2 = c.y2; c2.fontFamily = c.fontFamily; c2.fontSize = c.fontSize; nchars.Add(c2); } word = new TextWord(); words.Add(word); word.AddChar(c); } nchars.Add(c); } chars = nchars; this.x1 = words[0].x1; this.x2 = words[words.Count - 1].x2; this.text = null; foreach (TextWord w in words) { text = text == null ? w.text : (text + " " + w.text); w.Finish(this); } if (this.text.Length != this.chars.Count) { throw new Exception("Error while creating lines from PDF."); } }
public override void EventOccurred(IEventData data, EventType type) { if (!type.Equals(EventType.RENDER_TEXT)) { return; } TextRenderInfo renderInfo = (TextRenderInfo)data; string curFont = renderInfo.GetFont().GetFontProgram().ToString(); float curFontSize = renderInfo.GetFontSize(); IList <TextRenderInfo> text = renderInfo.GetCharacterRenderInfos(); foreach (TextRenderInfo t in text) { string letter = t.GetText(); Vector letterStart = t.GetDescentLine().GetStartPoint(); Vector letterEnd = t.GetAscentLine().GetEndPoint(); if (letter != " " && !letter.Contains(" ")) { TextChar c = new TextChar(); chars.Add(c); c.text = letter; c.x1 = letterStart.Get(0); c.x2 = letterEnd.Get(0); c.y1 = letterStart.Get(1); c.y2 = letterEnd.Get(1); if (c.y1 > c.y2) { c.y1 = letterEnd.Get(1); c.y2 = letterStart.Get(1); } c.fontFamily = curFont; c.fontSize = curFontSize; } } }
public bool AddChar(TextChar c) { if (chars.Count == 0) { this.x1 = c.x1; this.x2 = c.x2; this.text = c.text; chars.Add(c); return(true); } if (c.x1 - chars[chars.Count - 1].x2 < 2) { this.text += c.text; this.x2 = c.x2; chars.Add(c); return(true); } return(false); }