Exemple #1
0
        internal Font GetFont(TFlxFont Fx, real Adj)
        {
            // Not really need to keep a cache in WPF.
            Font NewFont = ExcelFont.CreateFont(Fx, Adj);

            return(NewFont);
        }
Exemple #2
0
 internal real Offset(IFlxGraphics Canvas, Font MyFont)
 {
     if (FOffset != 0)
     {
         SizeF Sz = Canvas.MeasureString("Mg", MyFont);
         return(Sz.Height / FOffset);
     }
     return(0);
 }
Exemple #3
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (FFont != null)
         {
             FFont.Dispose();
         }
         FFont = null;
     }
 }
Exemple #4
0
        private static int DoFullGetRowHeight(TFlxFont Fx)
        {
            using (Font MyFont = ExcelFont.CreateFont(Fx.Name, (Fx.Size20 / 20F), ExcelFont.ConvertFontStyle(Fx)))
            {
#if (MONOTOUCH)
                real h = MyFont.LineHeight;
#else
                real h = MyFont.GetHeight(75);
#endif
                return((int)(h * 20.87 + 5));
            }
        }
Exemple #5
0
        /// <summary>
        /// Tries to create a new font given the Excel data.
        /// </summary>
        /// <param name="Fx">FlexCel font with the font information.</param>
        /// <param name="Adj">An adjustment parameter to multiply the FontSize.</param>
        public static Font CreateFont(TFlxFont Fx, real Adj)
        {
            Font Result = new Font();

            Result.Family    = new FontFamily(Fx.Name);
            Result.SizeInPix = Fx.Size20 / 20.0 * FlxConsts.PixToPoints * Adj; //fontsize is in pixels, not points
            if ((Fx.Style & TFlxFontStyles.Italic) != 0)
            {
                Result.Style = FontStyles.Italic;
            }
            else
            {
                Result.Style = FontStyles.Normal;
            }
            if ((Fx.Style & TFlxFontStyles.Bold) != 0)
            {
                Result.Weight = FontWeights.Bold;
            }
            else
            {
                Result.Weight = FontWeights.Normal;
            }

            Result.Decorations = new TextDecorationCollection();
            if ((Fx.Style & TFlxFontStyles.StrikeOut) != 0)
            {
                Result.Decorations.Add(TextDecorations.Strikethrough);
            }
            if (Fx.Underline != TFlxUnderline.None)
            {
                Result.Decorations.Add(TextDecorations.Underline);
            }
            if (Fx.Underline == TFlxUnderline.Double || Fx.Underline == TFlxUnderline.DoubleAccounting)
            {
                Result.Decorations.Add(TextDecorations.Baseline);
            }

            Result.Freeze();
            return(Result);
        }
Exemple #6
0
        private static real DoFullGetFont0Width(TFlxFont Fx)
        {
#if (MONOTOUCH)
            using (Font MyFont = ExcelFont.CreateFont(Fx.Name, (Fx.Size20 / 20F), ExcelFont.ConvertFontStyle(Fx)))
            {
                using (MonoTouch.Foundation.NSString o = new MonoTouch.Foundation.NSString("0"))
                {
                    return(o.StringSize(MyFont).Width);
                }
            }
#else
            using (Font MyFont = ExcelFont.CreateFont(Fx.Name, (Fx.Size20 / 20F), ExcelFont.ConvertFontStyle(Fx)))
            {
                using (Bitmap bm = new Bitmap(1, 1))
                {
                    using (Graphics gr = Graphics.FromImage(bm))
                        using (StringFormat sfTemplate = StringFormat.GenericTypographic)                 //GenericTypographic returns a NEW instance. It has to be disposed.
                        {
                            using (StringFormat sf = (StringFormat)sfTemplate.Clone())                    //Even when sfTemplate is a new instance, changing directly on it will change the standard generic typographic :(
                            {
                                //sf.SetMeasurableCharacterRanges was causing a deadlock here.
                                //DONT DO!!

                                /*CharacterRange[] r = {new CharacterRange(0,1)};
                                 * sf.SetMeasurableCharacterRanges(r);*/

                                sf.Alignment     = StringAlignment.Near; //this should be set, but just in case someone changed it.
                                sf.LineAlignment = StringAlignment.Far;  //this should be set, but just in case someone changed it.
                                sf.FormatFlags   = 0;
                                gr.PageUnit      = GraphicsUnit.Pixel;
                                SizeF sz = gr.MeasureString("0", MyFont, 1000, sf);
                                return((real)Math.Round(sz.Width));
                            }
                        }
                }
            }
#endif
        }
        public System.Drawing.SizeF DrawString(System.Drawing.PointF point, float width, MonoTouch.UIKit.UIFont font, float minFontSize, float actualFontSize, MonoTouch.UIKit.UILineBreakMode breakMode, MonoTouch.UIKit.UIBaselineAdjustment adjustment)
        {
            float temp = actualFontSize;

            return(DrawString(point, width, font, minFontSize, ref temp, breakMode, adjustment));
        }
Exemple #8
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();
                    }
                }
            }
        }
Exemple #9
0
 internal TFontInfo(Font aFont)
 {
     FFont = aFont;
 }