示例#1
0
        private static RectangleF CalcTextCoordsAlpha0(real[] X, real[] Y, TVAlign VAlign, ref THAlign HAlign, real Indent, ref RectangleF CellRect, real Clp, ref SizeF TextExtent, bool FmtGeneral, bool Vertical, bool IsLeftToRight, TXRichStringList TextLines, double Linespacing)
        {
            RectangleF ContainingRect;
            real       AcumY      = 0;
            real       MinX       = 0;
            real       TextHeight = Y.Length < 1 ? TextExtent.Height : (float)(TextLines[Y.Length - 1].YExtent + (TextExtent.Height - TextLines[Y.Length - 1].YExtent) * Linespacing); //Last line doesn't add linespace.

            for (int i = 0; i < X.Length; i++)
            {
                switch (VAlign)
                {
                case TVAlign.Top: Y[i] = AcumY + CellRect.Top + Clp + TextLines[i].YExtent; break;                         //Used to be "CellRect.Top + Clp + TextExtent.Height * Lines" instead, but it goes too low.

                case TVAlign.Center: Y[i] = AcumY + (CellRect.Top + CellRect.Bottom - TextHeight) / 2 + TextLines[i].YExtent; break;

                default: Y[i] = AcumY + CellRect.Bottom - Clp - TextHeight + TextLines[i].YExtent; break;
                }                 //case

                AcumY += (float)(TextLines[i].YExtent * Linespacing);


                THAlign RHAlign = HAlign;
                if (FmtGeneral)
                {
                    if (IsLeftToRight)
                    {
                        RHAlign = THAlign.Right; HAlign = RHAlign;
                    }
                    if (Vertical)
                    {
                        RHAlign = THAlign.Center; HAlign = RHAlign;
                    }
                }
                switch (RHAlign)
                {
                case THAlign.Right: X[i] = CellRect.Right - Clp - TextLines[i].XExtent - Indent; break;

                case THAlign.Center: X[i] = (CellRect.Left + CellRect.Right - TextLines[i].XExtent) / 2; break;

                default: X[i] = CellRect.Left + Clp + 1f * FlexCelRender.DispMul / 100f + Indent; break;
                }                 //case

                if (i == 0 || MinX > X[i])
                {
                    MinX = X[i];
                }
            }
            ContainingRect = new RectangleF(MinX, Y[0] - TextLines[0].YExtent, TextExtent.Width, TextHeight);
            return(ContainingRect);
        }
示例#2
0
        private static RectangleF CalcTextCoordsRotated(real[] X, real[] Y, TVAlign VAlign, THAlign HAlign, real Alpha, ref RectangleF CellRect, real Clp, bool FmtGeneral, real SinAlpha, real CosAlpha, TXRichStringList TextLines, double Linespacing)
        {
            //General horiz align depends on the rotation
            THAlign RHAlign = HAlign;

            if (FmtGeneral)
            {
                if (Alpha == 90)
                {
                    RHAlign = THAlign.Right;
                }
                else if (Alpha > 0)
                {
                    RHAlign = THAlign.Left;
                }
                else if (Alpha != -90)
                {
                    RHAlign = THAlign.Right;
                }
                else
                {
                    RHAlign = THAlign.Left;
                }
            }


            /*
             * This is quite complex because each box of text has 4 corners. We always write on left-bottom coordinate, but to keep
             * calculations easy, we will calculate the left-bottom for alpha > 0, and left-top for alpha < 0
             *            ___                   ___x
             * (Alpha>0) /  /      (Alpha < 0)  \  \
             *          /  /                     \  \
             *          --x                       ---
             *
             * We will then adjust the x coord for alpha < 0 to be left-bottom.
             */

            real xdiff = 0;
            real XOfs = 0;
            real GlobalMinBoxX = 0, GlobalMaxBoxX = 0;

            for (int i = 0; i < TextLines.Count; i++)
            {
                real hcosAlpha = TextLines[i].YExtent * CosAlpha;
                real wsinAlpha = TextLines[i].XExtent * SinAlpha;
                real dy        = Math.Abs(wsinAlpha) + hcosAlpha;

                switch (VAlign)
                {
                case TVAlign.Top:
                    Y[i] = CellRect.Top + Clp + dy;
                    break;

                case TVAlign.Center:
                    Y[i] = (CellRect.Top + CellRect.Bottom + dy) / 2;
                    break;

                default:
                    Y[i] = CellRect.Bottom - Clp;
                    break;
                }                 //case

                if (Alpha < 0)
                {
                    Y[i] -= dy;
                }


                //Now accumulate in x
                real wcosAlpha = TextLines[i].XExtent * CosAlpha;
                real hsinAlpha = TextLines[i].YExtent * SinAlpha;

                if (i > 0)
                {
                    int  z    = Alpha > 0? i: i - 1;
                    real xinc = TextLines[z].YExtent / SinAlpha;                      //xinc here is what we need to stack boxes one after the other, keeping the same Y.
                    XOfs += xinc;
                }

                X[i] = XOfs;
                if (i > 0)
                {
                    X[i] += (Y[0] - Y[i]) * CosAlpha / SinAlpha;                         //if both Y are not aligned, we need to substract that offset.
                }
                switch (RHAlign)
                {
                case THAlign.Right:
                    real MaxBoxX = X[i] + wcosAlpha;
                    if (MaxBoxX > GlobalMaxBoxX)
                    {
                        GlobalMaxBoxX = MaxBoxX;
                        xdiff         = CellRect.Right - Clp - MaxBoxX;
                    }

                    break;

                case THAlign.Center:
                    real cMaxBoxX = X[i] + wcosAlpha;
                    if (cMaxBoxX > GlobalMaxBoxX)
                    {
                        GlobalMaxBoxX = cMaxBoxX;
                    }
                    real cMinBoxX = X[i] - Math.Abs(hsinAlpha);
                    if (cMinBoxX < GlobalMinBoxX)
                    {
                        GlobalMinBoxX = cMinBoxX;
                    }
                    if (i == TextLines.Count - 1)
                    {
                        if (Alpha > 0)
                        {
                            real h0sinAlpha = TextLines[0].YExtent * SinAlpha;
                            xdiff = (CellRect.Left + CellRect.Right - (GlobalMaxBoxX - GlobalMinBoxX)) / 2 + h0sinAlpha;
                        }
                        else
                        {
                            real w0cosAlpha = TextLines[0].XExtent * CosAlpha;
                            xdiff = (CellRect.Left + CellRect.Right + (GlobalMaxBoxX - GlobalMinBoxX)) / 2 - w0cosAlpha;
                        }
                    }

                    break;

                default:
                    real MinBoxX = X[i] - Math.Abs(hsinAlpha);
                    if (MinBoxX < GlobalMinBoxX)
                    {
                        GlobalMinBoxX = MinBoxX;
                        xdiff         = CellRect.Left + Clp - MinBoxX;
                    }
                    break;
                }                 //case
            }

            real MinX = 0, MinY = 0, MaxX = 0, MaxY = 0;

            //second pass. adjust offsets. if alpha < 0, adjust x to be left-bottom, to write the text.
            for (int i = 0; i < TextLines.Count; i++)
            {
                X[i] += xdiff;

                real wcosAlpha = TextLines[i].XExtent * CosAlpha;
                real hsinAlpha = TextLines[i].YExtent * SinAlpha;
                real hcosAlpha = TextLines[i].YExtent * CosAlpha;
                real wsinAlpha = TextLines[i].XExtent * SinAlpha;

                if (i == 0)
                {
                    CalcBox(X[i], Y[i], Alpha, wcosAlpha, hsinAlpha, hcosAlpha, wsinAlpha, out MinX, out MinY, out MaxX, out MaxY);
                }
                else
                {
                    real aMinX, aMinY, aMaxX, aMaxY;
                    CalcBox(X[i], Y[i], Alpha, wcosAlpha, hsinAlpha, hcosAlpha, wsinAlpha, out aMinX, out aMinY, out aMaxX, out aMaxY);
                    MinX = Math.Min(MinX, aMinX);
                    MaxX = Math.Max(MaxX, aMaxX);
                    MinY = Math.Min(MinY, aMinY);
                    MaxY = Math.Max(MaxY, aMaxY);
                }

                if (Alpha < 0)
                {
                    Y[i] += hcosAlpha;
                    X[i] += hsinAlpha;                     //adjust because we are not using the same x to write the text.
                }
            }
            return(RectangleF.FromLTRB(MinX, MinY, MaxX, MaxY));
        }
示例#3
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));
            }
        }