List <TextLine> ProcessLine(IBlockSet <IBlock> bset, TextPageInfo pageInfo) { var items = bset; float minx = bset.GetX(); float maxx = bset.GetX() + bset.GetWidth(); float last_y = float.NaN; TextLine last_tl = null; var lines = new List <TextLine>(); foreach (var it in items) { var bl = (BlockLine)it; var tl = new TextLine { FontName = bl.FontName, FontSize = bl.FontSize, FontStyle = bl.FontStyle, Text = bl.Text, MarginLeft = bl.GetX() - minx, MarginRight = maxx - (bl.GetX() + bl.GetWidth()), BeforeSpace = (last_tl != null) ? (float?)(last_y - bl.GetH() - bl.FontSize) : null, AfterSpace = null, HasLargeSpace = bl.HasLargeSpace, Block = bl, HasBackColor = bl.HasBackColor, PageInfo = pageInfo }; tl.CenteredAt = 0.5f * (tl.MarginLeft - tl.MarginRight); lines.Add(tl); if (last_tl != null) { if (float.IsNaN(last_y)) { PdfReaderException.AlwaysThrow("float.IsNaN(last_y)"); } float a = bl.GetHeight(); float b = bl.FontSize; float diff = last_y - bl.GetH(); last_tl.AfterSpace = (last_y - bl.GetH() - bl.FontSize); if (diff < 1f) { PdfReaderException.Warning("BlockLines in different lines - result in wrong text aligment"); } } last_tl = tl; last_y = bl.GetH(); } return(lines.ToList()); }
IBlockSet <IBlock> ResizeBlockSet(IBlockSet <IBlock> bset, float minX, float maxX) { float maxWidth = maxX - minX; float width = bset.GetWidth(); bool shouldResize = Math.Abs(maxWidth - width) > WIDTH_DIFFERENCE; float x1 = Math.Min(minX, bset.GetX()); float x2 = Math.Max(maxX, bset.GetX() + bset.GetWidth()); float h1 = bset.GetH(); float h2 = bset.GetH() + bset.GetHeight(); if (shouldResize) { return(new BlockSet2 <IBlock>(bset, x1, h1, x2, h2)); } return(bset); }
IBlockSet <IBlock> Merge(IBlockSet <IBlock> b1, IBlockSet <IBlock> b2) { bool first = b1.GetX() < b2.GetX(); float x1 = Math.Min(b1.GetX(), b2.GetX()); float x2 = Math.Max(b1.GetX() + b1.GetWidth(), b2.GetX() + b2.GetWidth()); float h1 = Math.Min(b1.GetH(), b2.GetH()); float h2 = Math.Max(b1.GetH() + b1.GetHeight(), b2.GetH() + b2.GetHeight()); var blocks = (first) ? b1.Concat(b2) : b2.Concat(b1); var newblock = new BlockSet2 <IBlock>(blocks, x1, h1, x2, h2); return(newblock); }