Esempio n. 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();
                }
            }
        }
Esempio n. 2
0
        internal static void DrawPlainText(IFlxGraphics Canvas, ExcelFile Workbook, TShapeProperties ShProp, RectangleF Coords, TShadowInfo ShadowInfo, TClippingStyle Clipping, float Zoom100)
        {
            string Text = GetGeoText(ShProp);

            if (Text == null)
            {
                return;
            }
            Text = Text.Replace("\n", String.Empty);
            string[] Lines = Text.Split('\r');
            if (Lines == null || Lines.Length <= 0)
            {
                return;
            }
            int LinesLength = Lines[Lines.Length - 1].Length == 0? Lines.Length - 1: Lines.Length;               //Last line is an empty enter.

            if (LinesLength <= 0)
            {
                return;
            }

            using (Font TextFont = GetGeoFont(ShProp))
            {
                using (Pen pe = GetPen(ShProp, Workbook, ShadowInfo))
                {
                    Canvas.SaveTransform();
                    try
                    {
                        float   LineGap = Canvas.FontLinespacing(TextFont);
                        SizeF[] Sizes   = new SizeF[LinesLength];
                        Sizes[0]         = Canvas.MeasureStringEmptyHasHeight(Lines[0], TextFont);
                        Sizes[0].Height -= LineGap; //Linespacing is not included here.

                        SizeF sz = Sizes[0];
                        for (int i = 1; i < LinesLength; i++)
                        {
                            Sizes[i] = Canvas.MeasureStringEmptyHasHeight(Lines[i], TextFont);
                            if (Sizes[i].Width > sz.Width)
                            {
                                sz.Width = Sizes[i].Width;
                            }
                            sz.Height += Sizes[i].Height;
                        }

                        if (sz.Width <= 0 || sz.Height <= 0 || Coords.Width <= 0 || Coords.Height <= 0)
                        {
                            return;
                        }
                        float rx = Coords.Width / sz.Width;
                        float ry = Coords.Height / sz.Height;
                        Canvas.Scale(rx, ry);

                        using (Brush br = GetBrush(new RectangleF(Coords.Left / rx, Coords.Top / ry, sz.Width, sz.Height), ShProp, Workbook, ShadowInfo, Zoom100)) //Mast be selected AFTER scaling, so gradients work.
                        {
                            float y = LineGap;
                            for (int i = 0; i < LinesLength; i++)
                            {
                                y += Sizes[i].Height;
                                float x = (sz.Width - Sizes[i].Width) / 2f;
                                Canvas.DrawString(Lines[i], TextFont, pe, br, Coords.Left / rx + x, Coords.Top / ry + y);
                            }
                        }
                    }
                    finally
                    {
                        Canvas.ResetTransform();
                    }
                }
            }
        }