// Token: 0x060067F6 RID: 26614 RVA: 0x001D3800 File Offset: 0x001D1A00
 private PTS.FSRECT CalculateSearchArea(FigureHorizontalAnchor horizAnchor, FigureVerticalAnchor vertAnchor, ref PTS.FSRECT fsrcPage, ref PTS.FSRECT fsrcMargin, ref PTS.FSRECT fsrcTrack, ref PTS.FSRECT fsrcFigurePreliminary)
 {
     PTS.FSRECT result;
     if (FigureHelper.IsHorizontalPageAnchor(horizAnchor))
     {
         result.u  = fsrcPage.u;
         result.du = fsrcPage.du;
     }
     else if (FigureHelper.IsHorizontalContentAnchor(horizAnchor))
     {
         result.u  = fsrcMargin.u;
         result.du = fsrcMargin.du;
     }
     else
     {
         result.u  = fsrcTrack.u;
         result.du = fsrcTrack.du;
     }
     if (FigureHelper.IsVerticalPageAnchor(vertAnchor))
     {
         result.v  = fsrcPage.v;
         result.dv = fsrcPage.dv;
     }
     else if (FigureHelper.IsVerticalContentAnchor(vertAnchor))
     {
         result.v  = fsrcMargin.v;
         result.dv = fsrcMargin.dv;
     }
     else
     {
         result.v  = fsrcFigurePreliminary.v;
         result.dv = fsrcTrack.v + fsrcTrack.dv - fsrcFigurePreliminary.v;
     }
     return(result);
 }
        // Token: 0x060067F4 RID: 26612 RVA: 0x001D36C0 File Offset: 0x001D18C0
        private double LimitTotalWidthFromAnchor(double width, double elementMarginWidth)
        {
            Figure figure = (Figure)base.Element;
            FigureHorizontalAnchor horizontalAnchor = figure.HorizontalAnchor;
            double num;

            if (FigureHelper.IsHorizontalPageAnchor(horizontalAnchor))
            {
                num = base.StructuralCache.CurrentFormatContext.PageWidth;
            }
            else if (FigureHelper.IsHorizontalContentAnchor(horizontalAnchor))
            {
                Thickness pageMargin = base.StructuralCache.CurrentFormatContext.PageMargin;
                num = base.StructuralCache.CurrentFormatContext.PageWidth - pageMargin.Left - pageMargin.Right;
            }
            else
            {
                int    num2;
                double num3;
                double num4;
                double num5;
                FigureHelper.GetColumnMetrics(base.StructuralCache, out num2, out num3, out num4, out num5);
                num = num3;
            }
            if (width + elementMarginWidth > num)
            {
                width = Math.Max(TextDpi.MinWidth, num - elementMarginWidth);
            }
            return(width);
        }
        // ------------------------------------------------------------------
        // Determines the max total width for this figure element, subtracts the element margins to determine the maximum size the
        // Subpage can be formatted at.
        // ------------------------------------------------------------------
        private double LimitTotalWidthFromAnchor(double width, double elementMarginWidth)
        {
            Figure element = (Figure)Element;
            FigureHorizontalAnchor horizAnchor = element.HorizontalAnchor;

            double maxTotalWidth = 0.0;

            // Value is in pixels. Now we limit value to max out depending on anchoring.
            if (FigureHelper.IsHorizontalPageAnchor(horizAnchor))
            {
                maxTotalWidth = StructuralCache.CurrentFormatContext.PageWidth;
            }
            else if (FigureHelper.IsHorizontalContentAnchor(horizAnchor))
            {
                Thickness pageMargin = StructuralCache.CurrentFormatContext.PageMargin;
                maxTotalWidth = StructuralCache.CurrentFormatContext.PageWidth - pageMargin.Left - pageMargin.Right;
            }
            else
            {
                double columnWidth, gap, rule;
                int    cColumns;

                FigureHelper.GetColumnMetrics(StructuralCache, out cColumns, out columnWidth, out gap, out rule);

                maxTotalWidth = columnWidth;
            }

            if ((width + elementMarginWidth) > maxTotalWidth)
            {
                width = Math.Max(TextDpi.MinWidth, maxTotalWidth - elementMarginWidth);
            }

            return(width);
        }
        // Token: 0x060067ED RID: 26605 RVA: 0x001D3304 File Offset: 0x001D1504
        internal void CalcFigurePosition(FigureParaClient paraClient, uint fswdir, ref PTS.FSRECT fsrcPage, ref PTS.FSRECT fsrcMargin, ref PTS.FSRECT fsrcTrack, ref PTS.FSRECT fsrcFigurePreliminary, int fMustPosition, int fInTextLine, out int fPushToNextTrack, out PTS.FSRECT fsrcFlow, out PTS.FSRECT fsrcOverlap, out PTS.FSBBOX fsbbox, out PTS.FSRECT fsrcSearch)
        {
            Figure figure = (Figure)base.Element;
            FigureHorizontalAnchor horizontalAnchor = figure.HorizontalAnchor;
            FigureVerticalAnchor   verticalAnchor   = figure.VerticalAnchor;

            fsrcSearch = this.CalculateSearchArea(horizontalAnchor, verticalAnchor, ref fsrcPage, ref fsrcMargin, ref fsrcTrack, ref fsrcFigurePreliminary);
            if (verticalAnchor == FigureVerticalAnchor.ParagraphTop && fsrcFigurePreliminary.v != fsrcMargin.v && fsrcFigurePreliminary.v + fsrcFigurePreliminary.dv > fsrcTrack.v + fsrcTrack.dv && !PTS.ToBoolean(fMustPosition))
            {
                fPushToNextTrack = 1;
            }
            else
            {
                fPushToNextTrack = 0;
            }
            fsrcFlow = fsrcFigurePreliminary;
            if (FigureHelper.IsHorizontalColumnAnchor(horizontalAnchor))
            {
                fsrcFlow.u += this.CalculateParagraphToColumnOffset(horizontalAnchor, fsrcFigurePreliminary);
            }
            fsrcFlow.u += TextDpi.ToTextDpi(figure.HorizontalOffset);
            fsrcFlow.v += TextDpi.ToTextDpi(figure.VerticalOffset);
            fsrcOverlap = fsrcFlow;
            if (!FigureHelper.IsHorizontalPageAnchor(horizontalAnchor) && horizontalAnchor != FigureHorizontalAnchor.ColumnCenter && horizontalAnchor != FigureHorizontalAnchor.ContentCenter)
            {
                int    num;
                double d;
                double d2;
                double num2;
                FigureHelper.GetColumnMetrics(base.StructuralCache, out num, out d, out d2, out num2);
                int num3 = TextDpi.ToTextDpi(d);
                int num4 = TextDpi.ToTextDpi(d2);
                int num5 = num3 + num4;
                int num6 = fsrcOverlap.du / num5;
                int du   = (num6 + 1) * num5 - num4;
                fsrcOverlap.du = du;
                if (horizontalAnchor == FigureHorizontalAnchor.ContentRight || horizontalAnchor == FigureHorizontalAnchor.ColumnRight)
                {
                    fsrcOverlap.u = fsrcFlow.u + fsrcFlow.du + num4 - fsrcOverlap.du;
                }
                fsrcSearch.u  = fsrcOverlap.u;
                fsrcSearch.du = fsrcOverlap.du;
            }
            fsbbox          = default(PTS.FSBBOX);
            fsbbox.fDefined = 1;
            fsbbox.fsrc     = fsrcFlow;
        }
        // Token: 0x060067D0 RID: 26576 RVA: 0x001D18A4 File Offset: 0x001CFAA4
        internal static double CalculateFigureWidth(StructuralCache structuralCache, Figure figure, FigureLength figureLength, out bool isWidthAuto)
        {
            isWidthAuto = figureLength.IsAuto;
            FigureHorizontalAnchor horizontalAnchor = figure.HorizontalAnchor;
            double num;

            if (figureLength.IsPage || (figureLength.IsAuto && FigureHelper.IsHorizontalPageAnchor(horizontalAnchor)))
            {
                num = structuralCache.CurrentFormatContext.PageWidth * figureLength.Value;
            }
            else if (figureLength.IsAbsolute)
            {
                num = FigureHelper.CalculateFigureCommon(figureLength);
            }
            else
            {
                int    num2;
                double num3;
                double num4;
                double num5;
                FigureHelper.GetColumnMetrics(structuralCache, out num2, out num3, out num4, out num5);
                if (figureLength.IsContent || (figureLength.IsAuto && FigureHelper.IsHorizontalContentAnchor(horizontalAnchor)))
                {
                    num = (num3 * (double)num2 + num4 * (double)(num2 - 1)) * figureLength.Value;
                }
                else
                {
                    double value = figureLength.Value;
                    int    num6  = (int)value;
                    if ((double)num6 == value && num6 > 0)
                    {
                        num6--;
                    }
                    num = num3 * value + num4 * (double)num6;
                }
            }
            Invariant.Assert(!DoubleUtil.IsNaN(num));
            return(num);
        }
        //-------------------------------------------------------------------
        // CalcFigurePosition
        //-------------------------------------------------------------------
        internal void CalcFigurePosition(
            FigureParaClient paraClient,          // IN:
            uint fswdir,                          // IN:  current direction
            ref PTS.FSRECT fsrcPage,              // IN:  page rectangle
            ref PTS.FSRECT fsrcMargin,            // IN:  rectangle within page margins
            ref PTS.FSRECT fsrcTrack,             // IN:  track rectangle
            ref PTS.FSRECT fsrcFigurePreliminary, // IN:  prelim figure rect calculated from figure props
            int fMustPosition,                    // IN:  must find position in this track?
            int fInTextLine,                      // IN:  it is attached to text line
            out int fPushToNextTrack,             // OUT: push to next track?
            out PTS.FSRECT fsrcFlow,              // OUT: FlowAround rectangle
            out PTS.FSRECT fsrcOverlap,           // OUT: Overlap rectangle
            out PTS.FSBBOX fsbbox,                // OUT: bbox
            out PTS.FSRECT fsrcSearch)            // OUT: search area for overlap
        {
            Figure element = (Figure)Element;

            // If overlapping happens, let PTS find another position withing
            // the track rectangle.

            FigureHorizontalAnchor horizAnchor = element.HorizontalAnchor;
            FigureVerticalAnchor   vertAnchor  = element.VerticalAnchor;

            fsrcSearch = CalculateSearchArea(horizAnchor, vertAnchor, ref fsrcPage, ref fsrcMargin, ref fsrcTrack, ref fsrcFigurePreliminary);

            if (vertAnchor == FigureVerticalAnchor.ParagraphTop &&
                fsrcFigurePreliminary.v != fsrcMargin.v &&                                               // If we're not at the top of the column
                ((fsrcFigurePreliminary.v + fsrcFigurePreliminary.dv) > (fsrcTrack.v + fsrcTrack.dv)) && // And we exceed column height
                !PTS.ToBoolean(fMustPosition))                                                           // Can delay placement is handled by figure properties.
            {
                fPushToNextTrack = PTS.True;
            }
            else
            {
                fPushToNextTrack = PTS.False;
            }


            // Use rectangle proposed by PTS and make sure that figure fits completely in the page.

            fsrcFlow = fsrcFigurePreliminary;

            if (FigureHelper.IsHorizontalColumnAnchor(horizAnchor))
            {
                fsrcFlow.u += CalculateParagraphToColumnOffset(horizAnchor, fsrcFigurePreliminary);
            }

            // Apply horizontal and vertical offsets. Offsets are limited by page height and width
            fsrcFlow.u += TextDpi.ToTextDpi(element.HorizontalOffset);
            fsrcFlow.v += TextDpi.ToTextDpi(element.VerticalOffset);

            // Overlap rectangle is the same as flow around rect
            fsrcOverlap = fsrcFlow;


            /* If we're anchored to column/content left or right, inflate our overlap width to prevent from aligning two figures right next to one another
             * by incorporating column gap information */
            if (!FigureHelper.IsHorizontalPageAnchor(horizAnchor) &&
                horizAnchor != FigureHorizontalAnchor.ColumnCenter &&
                horizAnchor != FigureHorizontalAnchor.ContentCenter)
            {
                double columnWidth, gap, rule;
                int    cColumns;

                FigureHelper.GetColumnMetrics(StructuralCache, out cColumns, out columnWidth, out gap, out rule);

                int duColumnWidth            = TextDpi.ToTextDpi(columnWidth);
                int duGapWidth               = TextDpi.ToTextDpi(gap);
                int duColumnWidthWithGap     = duColumnWidth + duGapWidth;
                int fullColumns              = (fsrcOverlap.du / duColumnWidthWithGap);
                int duRoundedToNearestColumn = ((fullColumns + 1) * duColumnWidthWithGap) - duGapWidth;

                fsrcOverlap.du = duRoundedToNearestColumn; // Round overlap rect to nearest column

                if (horizAnchor == FigureHorizontalAnchor.ContentRight ||
                    horizAnchor == FigureHorizontalAnchor.ColumnRight)
                {
                    fsrcOverlap.u = (fsrcFlow.u + fsrcFlow.du + duGapWidth) - fsrcOverlap.du;
                }

                // Force search rect to only work vertically within overlap space.
                fsrcSearch.u  = fsrcOverlap.u;
                fsrcSearch.du = fsrcOverlap.du;
            }

            // Bounding box is equal to actual size of the figure.
            fsbbox          = new PTS.FSBBOX();
            fsbbox.fDefined = PTS.True;
            fsbbox.fsrc     = fsrcFlow;
        }