コード例 #1
0
 protected virtual void AddColor(PdfTextResult text, StringBuilder sb)
 {
     if (!text.StrokeColore.HasValue)
     {
         return;
     }
     sb.Append("color:");
     PdfHtmlWriter.AppendColor(text.StrokeColore.Value, sb);
     sb.Append(";");
 }
コード例 #2
0
 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));
 }
コード例 #3
0
        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());
        }
コード例 #4
0
        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>");
        }
コード例 #5
0
 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;
     }
 }
コード例 #6
0
 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);
         }
     }
 }
コード例 #7
0
 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);
     }
 }