Exemple #1
0
        internal static RectangleF CalcTextCoords(out real[] X, out real[] Y, TRichString OutText, TVAlign VAlign,
                                                  ref THAlign HAlign, real Indent, real Alpha, RectangleF CellRect, real Clp, SizeF TextExtent,
                                                  bool FmtGeneral, bool Vertical, real SinAlpha, real CosAlpha, TXRichStringList TextLines, double Linespacing0, TVFlxAlignment VJustify)
        {
            double Linespacing = VJustify == TVFlxAlignment.distributed || VJustify == TVFlxAlignment.justify ? 1.0 : Linespacing0;

            bool TextLeftToRight = IsLeftToRight(OutText.ToString());

            X = new real[TextLines.Count]; Y = new real[TextLines.Count];

            if (Alpha == 0)              //optimize the most common case
            {
                return(CalcTextCoordsAlpha0(X, Y, VAlign, ref HAlign, Indent, ref CellRect, Clp, ref TextExtent, FmtGeneral, Vertical, TextLeftToRight, TextLines, Linespacing));
            }

            else
            {
                // There is rotation. Now values of TextExtent are not ok, since lines will stack.for example ///////  Each line has the same y, and the x is calculated as height/cosAlpha
                return(CalcTextCoordsRotated(X, Y, VAlign, HAlign, Alpha, ref CellRect, Clp, FmtGeneral, SinAlpha, CosAlpha, TextLines, Linespacing));
            }
        }
Exemple #2
0
        internal override bool OnFound(ExcelFile xls, object oldval, int row, int col)
        {
            TFormula oldFmla = oldval as TFormula;

            if (!FSearchInFormulas && oldFmla != null)
            {
                return(false);                                                   //do not replace if it is a formula.
            }
            if (oldval == null)
            {
                return(false);
            }

            TRichString OldStr = oldval as TRichString;

            if (OldStr == null)
            {
                OldStr = new TRichString(FlxConvert.ToString(oldval));
            }
            TRichString newStr = OldStr.Replace(SearchToStr, NewValue.ToString(), FCaseInsensitive);

            if (newStr != null && newStr.Value != null && newStr.Length > 0 && newStr.Value.StartsWith(TFormulaMessages.TokenString(TFormulaToken.fmStartFormula)))
            {
                TFormulaSpan Span = oldFmla != null ? oldFmla.Span : new TFormulaSpan();
                xls.SetCellValue(row, col, new TFormula(newStr.Value, null, Span));
            }
            else
            {
                if (oldFmla != null && !oldFmla.Span.IsOneCell)
                {
                    return(false);                                            //can't replace a shared formula with simple text.
                }
                xls.SetCellFromString(row, col, newStr);
            }

            ReplaceCount++;
            return(false);
        }
Exemple #3
0
        internal static void SplitText(IFlxGraphics Canvas, TFontCache FontCache, real Zoom100,
                                       TRichString Text, Font AFont, real w, TXRichStringList TextLines, out SizeF TextExtent, bool Vertical, TFloatList MaxDescent, TAdaptativeFormats AdaptFormat)
        {
            TextLines.Clear();
            MaxDescent.Clear();

            int idx = 0;
            int fit = 0;


            TextExtent = new SizeF(0, 0);
            if (w <= 0 || Text.Value.Length <= 0)
            {
                return;
            }

            while (idx < Text.Value.Length)
            {
                int Enter     = Text.Value.IndexOf((char)0x0A, idx);
                int MaxLength = Text.Value.Length - idx;
                if (Enter >= 0)
                {
                    MaxLength = Enter - idx;
                }

                if (Vertical)
                {
                    fit = 1;
                    CharUtils.SameOrMore(Text.Value, idx, ref fit);
                }
                else
                {
                    //Not a really efficient way, but...
                    //First Guess. whole string.
                    fit = MaxLength;

                    real md;
                    real wc = CalcTextExtent(Canvas, FontCache, Zoom100, AFont, Text.Substring(idx, fit), out md).Width;
                    FitOneLine(Canvas, FontCache, Zoom100, Text, AFont, w, idx, ref fit, ref wc);

                    if (fit <= 0)
                    {
                        fit = 1;                               //avoid infinite loop
                    }
                    CharUtils.SameOrMore(Text.Value, idx, ref fit);


                    if (Text.Value.IndexOf(' ', idx, fit) >= 0)
                    {
                        int minfit = 1;
                        CharUtils.SameOrMore(Text.Value, idx, ref minfit);
                        while (fit > minfit && fit < MaxLength && Text.Value[idx + fit] != ' ')
                        {
                            fit--;
                        }
                    }
                    while (fit < MaxLength && Text.Value[idx + fit] == ' ')
                    {
                        fit++;
                    }
                    //No need to adjust fit for surrogates. it will always be at the start of one.
                }

                //int Enter=Text.Value.IndexOf((char)0x0A, idx, fit);
                //if (Enter>0) fit=Enter-idx;
                int TextLen = Math.Min(MaxLength, fit);
                TextLines.Add(new TXRichString(Text.Substring(idx, TextLen), true, 0, 0, TAdaptativeFormats.CopyTo(AdaptFormat, idx, TextLen)));

                if (fit + idx < Text.Value.Length && Text.Value[idx + fit] == (char)0x0A)
                {
                    TextLines[TextLines.Count - 1].Split = false;
                    if (idx + fit < Text.Value.Length - 1)                  //An Enter at the end behaves different, it means we have a new empty line.
                    {
                        idx++;
                    }
                }
                if (fit + idx >= Text.Value.Length)
                {
                    TextLines[TextLines.Count - 1].Split = false;
                }

                idx += fit;

                //Recalculate dx
                real        mdx   = 0;
                TRichString sx    = TextLines[TextLines.Count - 1].s;
                SizeF       bSize = CalcTextExtent(Canvas, FontCache, Zoom100, AFont, sx, out mdx);
                if (bSize.Height == 0)
                {
                    real  mdx3;
                    SizeF bSize3 = CalcTextExtent(Canvas, FontCache, Zoom100, AFont, new TRichString("M"), out mdx3);
                    bSize.Height = bSize3.Height;
                }

                SizeF bSize2 = bSize;
                if (sx != null && sx.Length > 0 && sx.ToString()[sx.Length - 1] == ' ')             //This is to right align line with spaces at the end.
                {
                    real mdx2;
                    bSize2 = CalcTextExtent(Canvas, FontCache, Zoom100, AFont, sx.RightTrim(), out mdx2);
                }
                TextLines[TextLines.Count - 1].XExtent = bSize2.Width;
                TextLines[TextLines.Count - 1].YExtent = bSize.Height;                 // not bSize2.Height; This might be even 0.

                MaxDescent.Add(mdx);
                if (TextExtent.Width < bSize.Width)
                {
                    TextExtent.Width = bSize.Width;
                }
                TextExtent.Height += bSize.Height;
            }             //while
        }