Example #1
0
        internal static void WriteText(ExcelFile Workbook, IFlxGraphics Canvas, TFontCache FontCache, real Zoom100, Font AFont, Color AFontColor, real x, real y, real SubOfs, TRichString OutText, real Alpha, real MaxDescent, TAdaptativeFormats AdaptativeFormats)
        {
            if (OutText.Length == 0)
            {
                return;
            }

            if (Alpha != 0)
            {
                Canvas.SaveTransform();
            }
            try
            {
                if (Alpha != 0)
                {
                    Canvas.Rotate(x, y, Alpha);
                }

                using (Brush TextBrush = new SolidBrush(AFontColor))
                {
                    if (OutText.RTFRunCount == 0)
                    {
                        if (AdaptativeFormats == null || AdaptativeFormats.Separators == null || AdaptativeFormats.Separators.Length == 0) //formats are only applied to non rich text cells.
                        {
                            Canvas.DrawString(OutText.Value, AFont, TextBrush, x, y + SubOfs);
                        }
                        else
                        {
                            DrawAdaptativeString(Canvas, AdaptativeFormats, OutText.Value, AFont, TextBrush, x, y + SubOfs);
                        }
                    }
                    else
                    {
                        SizeF Result;

                        string s1 = OutText.Value.Substring(0, OutText.RTFRun(0).FirstChar);
                        if (s1.Length > 0)
                        {
                            Result = Canvas.MeasureString(s1, AFont, new TPointF(x, y));
                            Canvas.DrawString(s1, AFont, TextBrush, x, y + SubOfs - (MaxDescent - Canvas.FontDescent(AFont)));
                            x += Result.Width;
                        }

                        for (int i = 0; i < OutText.RTFRunCount - 1; i++)
                        {
                            TFlxFont       Fx     = OutText.GetFont(OutText.RTFRun(i).FontIndex);
                            TSubscriptData Sub    = new TSubscriptData(Fx.Style);
                            Font           MyFont = FontCache.GetFont(Fx, Zoom100 * Sub.Factor);
                            {
                                using (Brush MyBrush = new SolidBrush(GetColor(Workbook, Fx.Color)))
                                {
                                    int Start = OutText.RTFRun(i).FirstChar;
                                    if (Start >= OutText.Length)
                                    {
                                        Start = OutText.Length;
                                    }
                                    int Len = OutText.RTFRun(i + 1).FirstChar;
                                    if (Len >= OutText.Length)
                                    {
                                        Len = OutText.Length;
                                    }
                                    Len -= Start;

                                    string s2 = OutText.Value.Substring(Start, Len);
                                    Result = Canvas.MeasureString(s2, MyFont, new TPointF(x, y));
                                    Canvas.DrawString(s2, MyFont, MyBrush, x, y + Sub.Offset(Canvas, MyFont) - (MaxDescent - Canvas.FontDescent(MyFont)));
                                    x += Result.Width;
                                }
                            }
                        }
                        TFlxFont       Fy      = OutText.GetFont(OutText.RTFRun(OutText.RTFRunCount - 1).FontIndex);
                        TSubscriptData Suby    = new TSubscriptData(Fy.Style);
                        Font           MyFont2 = FontCache.GetFont(Fy, Zoom100 * Suby.Factor);
                        {
                            using (Brush MyBrush = new SolidBrush(GetColor(Workbook, Fy.Color)))
                            {
                                int Start = OutText.RTFRun(OutText.RTFRunCount - 1).FirstChar;
                                if (Start >= OutText.Length)
                                {
                                    Start = OutText.Length;
                                }

                                string s3 = OutText.Value.Substring(Start);
                                Result = Canvas.MeasureString(s3, MyFont2, new TPointF(x, y));
                                Canvas.DrawString(s3, MyFont2, MyBrush, x, y + Suby.Offset(Canvas, MyFont2) - (MaxDescent - Canvas.FontDescent(MyFont2)));
                            }
                        }
                    }
                }
            }
            finally
            {
                if (Alpha != 0)
                {
                    Canvas.ResetTransform();
                }
            }
        }
Example #2
0
        internal static SizeF CalcTextExtent(IFlxGraphics Canvas, TFontCache FontCache, real Zoom100,
                                             Font AFont, TRichString Text, out real MaxDescent)
        {
            MaxDescent = Canvas.FontDescent(AFont);
            if (Text.RTFRunCount == 0)
            {
                return(Canvas.MeasureStringEmptyHasHeight(Text.Value, AFont));
            }

            real  x = 0;
            real  y = 0;
            SizeF Result;

            Result = Canvas.MeasureString(Text.Value.Substring(0, Text.RTFRun(0).FirstChar), AFont, new TPointF(0, 0));
            x      = Result.Width; y = Result.Height;


            for (int i = 0; i < Text.RTFRunCount - 1; i++)
            {
                TFlxFont       Fx     = Text.GetFont(Text.RTFRun(i).FontIndex);
                TSubscriptData Sub    = new TSubscriptData(Fx.Style);
                Font           MyFont = FontCache.GetFont(Fx, Zoom100 * Sub.Factor);
                {
                    int Start = Text.RTFRun(i).FirstChar;
                    if (Start >= Text.Length)
                    {
                        Start = Text.Length;
                    }
                    int Len = Text.RTFRun(i + 1).FirstChar;
                    if (Len >= Text.Length)
                    {
                        Len = Text.Length;
                    }
                    Len -= Start;
                    if (Len < 0)
                    {
                        continue;       //wrong file, (i+1)FirstChar < (i).FirstChar
                    }
                    Result     = Canvas.MeasureString(Text.Value.Substring(Start, Len), MyFont, new TPointF(0, 0));
                    x         += Result.Width; y = Math.Max(y + Sub.Offset(Canvas, MyFont), Result.Height);
                    MaxDescent = Math.Max(MaxDescent, Canvas.FontDescent(MyFont) + Sub.Offset(Canvas, MyFont));
                }
            }


            TFlxFont       Fy      = Text.GetFont(Text.RTFRun(Text.RTFRunCount - 1).FontIndex);
            TSubscriptData Suby    = new TSubscriptData(Fy.Style);
            Font           MyFont2 = FontCache.GetFont(Fy, Zoom100 * Suby.Factor);

            {
                int Start = Text.RTFRun(Text.RTFRunCount - 1).FirstChar;
                if (Start >= Text.Length)
                {
                    Start = Text.Length;
                }
                Result     = Canvas.MeasureStringEmptyHasHeight(Text.Value.Substring(Start), MyFont2);
                x         += Result.Width; y = Math.Max(y + Suby.Offset(Canvas, MyFont2), Result.Height);
                MaxDescent = Math.Max(MaxDescent, Canvas.FontDescent(MyFont2) + Suby.Offset(Canvas, MyFont2));
            }

            return(new SizeF(x, y));
        }