Exemplo n.º 1
0
        private static void AddWildcard(IFlxGraphics Canvas, TFontCache FontCache, real Zoom100,
                                        Font AFont, real MaxTextWidth, TXRichStringList TextLines, ref SizeF TextExtent)
        {
            TXRichString LineWithWildcard = null;

            foreach (TXRichString line in TextLines)
            {
                if (line.s == null || line.s.RTFRunCount > 0)
                {
                    return;                                           //wildcards only apply to non formatted lines.
                }
                if (line.AdaptFormat != null && line.AdaptFormat.WildcardPos >= 0)
                {
                    LineWithWildcard = line;
                    break;
                }
            }

            if (LineWithWildcard == null)
            {
                return;
            }
            AddWilcardtoLine(Canvas, FontCache, Zoom100, AFont, MaxTextWidth, ref TextExtent, LineWithWildcard);
        }
Exemplo n.º 2
0
        internal static void DrawRichText(ExcelFile Workbook, IFlxGraphics Canvas, TFontCache FontCache, real Zoom100, bool ReverseRightToLeftStrings,
                                          ref RectangleF CellRect, ref RectangleF PaintClipRect, ref RectangleF TextRect, ref RectangleF ContainingRect,
                                          real Clp, THFlxAlignment HJustify, TVFlxAlignment VJustify, real Alpha,
                                          Color DrawFontColor, TSubscriptData SubData, TRichString OutText, SizeF TextExtent,
                                          TXRichStringList TextLines,
                                          Font AFont, TFloatList MaxDescent, real[] X, real[] Y)
        {
            RectangleF FinalRect = CellRect;

            if (ContainingRect.Right > PaintClipRect.Left &&
                ContainingRect.Left < PaintClipRect.Right &&
                Intersect(TextRect, PaintClipRect, out FinalRect))
            {
                real dy             = 0;
                int  TextLinesCount = TextLines.Count;

                if (VJustify == TVFlxAlignment.justify || VJustify == TVFlxAlignment.distributed)
                {
                    if (TextLinesCount > 1)
                    {
                        dy = (CellRect.Height - TextExtent.Height - 2 * Clp) / (TextLinesCount - 1);
                    }
                }

                float eps = 0.0001F; //Tolerance for the comparison, these are floats, not doubles, and we get rounding errors soon.
                if (TextRect.Left - eps <= ContainingRect.Left && TextRect.Right + eps >= ContainingRect.Right && TextRect.Top - eps <= ContainingRect.Top && TextRect.Bottom + eps >= ContainingRect.Bottom)
                {
                    Canvas.SetClipReplace(PaintClipRect);                      //This will improve pdf export a lot, since we can now join all the BT/ET tags inside one, and then we can also join fonts inside the ET/BT tags.
                }
                else
                {
                    if (Alpha == 0 || Alpha == 90)
                    {
                        Canvas.SetClipReplace(FinalRect);
                    }
                    else
                    {
                        Canvas.SetClipReplace(RectangleF.FromLTRB(PaintClipRect.Left, FinalRect.Top, PaintClipRect.Right, FinalRect.Bottom));                         //rotated text can move to other used cells horizontally.
                    }
                }

                real AcumDy = 0;
                for (int i = 0; i < TextLinesCount; i++)
                {
                    TXRichString TextLine = TextLines[i];
                    if ((Alpha == 0) &&
                        (HJustify == THFlxAlignment.justify && TextLine.Split) ||
                        (HJustify == THFlxAlignment.distributed)
                        )
                    {
                        Canvas.SetClipReplace(FinalRect);
                        WriteJustText(Workbook, Canvas, FontCache, Zoom100, ReverseRightToLeftStrings,
                                      AFont, DrawFontColor, Y[i] + AcumDy, SubData.Offset(Canvas, AFont), CellRect, Clp, TextLine.s,
                                      TextLine.XExtent, MaxDescent[i], HJustify == THFlxAlignment.distributed, TextLine.AdaptFormat);
                    }
                    else
                    {
                        WriteText(Workbook, Canvas, FontCache, Zoom100, AFont, DrawFontColor, X[i],
                                  Y[i] + AcumDy, SubData.Offset(Canvas, AFont), GetVisualString(TextLine.s, ReverseRightToLeftStrings),
                                  Alpha, MaxDescent[i], TextLine.AdaptFormat);
                    }
                    AcumDy += dy;
                }
            }
        }
Exemplo n.º 3
0
        internal static void AddWilcardtoLine(IFlxGraphics Canvas, TFontCache FontCache, real Zoom100, Font AFont, real MaxTextWidth, ref SizeF TextExtent, TXRichString LineWithWildcard)
        {
            if (LineWithWildcard == null || LineWithWildcard.AdaptFormat == null)
            {
                return;
            }
            int WildcardPos = LineWithWildcard.AdaptFormat.WildcardPos;

            if (WildcardPos < 0)
            {
                return;
            }

            string s1           = LineWithWildcard.s.ToString();
            string WildcardChar = String.Empty + s1[WildcardPos];

            if (CharUtils.IsSurrogatePair(s1, WildcardPos) && WildcardPos + 1 < s1.Length)
            {
                WildcardChar += s1[WildcardPos + 1];
            }
            string sOrg = s1;

            s1 = s1.Remove(WildcardPos, WildcardChar.Length);//consider the case the string has 0 wildcards.
            string sOld = s1;
            real   wc;
            real   OldWc = LineWithWildcard.XExtent;

            do
            {
                real md;
                wc = RenderMetrics.CalcTextExtent(Canvas, FontCache, Zoom100, AFont, new TRichString(s1), out md).Width;
                if (wc < MaxTextWidth)
                {
                    sOld  = s1;
                    OldWc = wc;
                    s1    = s1.Insert(WildcardPos, WildcardChar);
                }
            }while (wc < MaxTextWidth);

            LineWithWildcard.s = new TRichString(sOld);
            if (sOrg.Length > sOld.Length)
            {
                LineWithWildcard.AdaptFormat.RemovedPosition(WildcardPos, sOrg.Length - sOld.Length);                            //a line with a wildcard can have 0 characters in the wildcard.
            }
            if (sOrg.Length < sOld.Length)
            {
                LineWithWildcard.AdaptFormat.InsertedPosition(WildcardPos, sOld.Length - sOrg.Length);
            }
            LineWithWildcard.XExtent = OldWc;
            if (TextExtent.Width < OldWc)
            {
                TextExtent.Width = OldWc;
            }
        }