protected virtual void AddColor(PdfTextResult text, StringBuilder sb) { if (!text.StrokeColore.HasValue) { return; } sb.Append("color:"); PdfHtmlWriter.AppendColor(text.StrokeColore.Value, sb); sb.Append(";"); }
protected void AddFontClass(PdfTextResult text, Dictionary <PdfFontDetails, int> fontRef, StringBuilder sb) { sb.Append($@" font").Append(fontRef[text.Font] + 1); if (text.Font.Bold) { sb.Append($@" bold"); } sb.Append(" font-size-") .Append((Math.Round(text.FontSize * 2) / 2).ToString(formatNumInClassName)); }
private IList <PdfTextResult> MergeTextInLine() { var result = new LinkedList <PdfTextResult> { }; LinkedListNode <PdfTextResult> firstNode = null; PdfTextBlock lastBlock = null; PdfTextResult text = null; PdfLinkResult link = null; for (var index = 0; index < blocks.Count; index++) { var current = blocks[index]; bool currentRTL = RightToLeftManager.Instance.AssignNeutral(pageContext.PageRTL, current, blocks, index); bool opositeDirection = pageContext.PageRTL != currentRTL; // bool digitLtr = current.IsDigit && last?.IsDigit==true; if (lastBlock != null && Equals(lastBlock.StrokeColore, current.StrokeColore) && lastBlock.FontSize == current.FontSize && lastBlock.Font == current.Font && lastBlock.Link == current.Link && lastBlock.IsRightToLeft == current.IsRightToLeft) { if (opositeDirection) //&&!digitLtr) { text.Value = current.Value + text.Value; } else { text.Value += current.Value; } } else { // var stateRtl = // RightToLeftManager.Instance.PageElemtRtl(pageRTL, currentRightToLeft); // && !digitLtr); SeperateRtlLtr(opositeDirection, pageContext.PageRTL, current, lastBlock, text); text = new PdfTextResult { FontSize = current.FontSize, Font = current.Font, StrokeColore = current.StrokeColore, Value = current.Value, }; pageContext.LinkManager.AssignLink(current, text, ref link); AddNewText(opositeDirection, result, text, ref firstNode); } lastBlock = current; } return(result.ToArray()); }
protected virtual void AddText(PdfTextResult text, Dictionary <PdfFontDetails, int> fontRef, StringBuilder sb) { sb.Append($@"<span class=""baseline"); AddFontClass(text, fontRef, sb); var b = text.StrokeColore?.GetBrightness(); if (b > 0.9) { sb.Append($@" darken"); } sb.Append("\" style=\""); AddColor(text, sb); sb.Append(@""">"); AddText(text.Value, sb); sb.Append(@"</span>"); }
public void AssignLink(PdfTextBlock current, PdfTextResult text, ref PdfLinkResult link) { if (current.Link != null) { if (!string.Equals(link?.Link, current.Link)) { if (link != null && Log.DebugSupported) { Log.Debug("link:" + link); } link = new PdfLinkResult { Link = current.Link }; } link.Children.Add(text); text.LinkParent = link; } }
private void SeperateRtlLtr(bool opositeDirection, bool pageRtl, PdfTextBlock current, PdfTextBlock lastBlock, PdfTextResult lastText) { if (opositeDirection) { if (lastBlock?.IsRightToLeft == pageRtl && //!lastBlock.IsDigit && !RightToLeftManager.Instance.IsNeutral(lastBlock.Value[lastBlock.Value.Length - 1])) { lastText.Value = lastText.Value + " "; Log.Debug("seperated:" + lastBlock.Value + "-" + current.Value); } } else { if (lastBlock?.IsRightToLeft == !pageRtl && // !lastBlock.IsDigit && !RightToLeftManager.Instance.IsNeutral(current.Value[0])) { current.Value = " " + current.Value; Log.Debug("seperated:" + lastText.Value + "-" + current.Value); } } }
private static void AddNewText(bool opositeDirection, LinkedList <PdfTextResult> result, PdfTextResult text, ref LinkedListNode <PdfTextResult> firstNode) { if (opositeDirection) { if (firstNode == null) { result.AddFirst(text); } else { result.AddAfter(firstNode, text); } } else { firstNode = result.AddLast(text); } }