// 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);
 }
        // ------------------------------------------------------------------
        // Determines the max total height for this figure element, subtracts the element margins to determine the maximum size the
        // Subpage can be formatted at.
        // ------------------------------------------------------------------
        private double LimitTotalHeightFromAnchor(double height, double elementMarginHeight)
        {
            Figure element = (Figure)Element;
            FigureVerticalAnchor vertAnchor = element.VerticalAnchor;

            double maxTotalHeight = 0.0;

            // Value is in pixels. Now we limit value to max out depending on anchoring.
            if (FigureHelper.IsVerticalPageAnchor(vertAnchor))
            {
                maxTotalHeight = StructuralCache.CurrentFormatContext.PageHeight;
            }
            else
            {
                Thickness pageMargin = StructuralCache.CurrentFormatContext.PageMargin;
                maxTotalHeight = StructuralCache.CurrentFormatContext.PageHeight - pageMargin.Top - pageMargin.Bottom;
            }

            if ((height + elementMarginHeight) > maxTotalHeight)
            {
                height = Math.Max(TextDpi.MinWidth, maxTotalHeight - elementMarginHeight);
            }

            return(height);
        }
        // Token: 0x060067D1 RID: 26577 RVA: 0x001D1984 File Offset: 0x001CFB84
        internal static double CalculateFigureHeight(StructuralCache structuralCache, Figure figure, FigureLength figureLength, out bool isHeightAuto)
        {
            double num;

            if (figureLength.IsPage)
            {
                num = structuralCache.CurrentFormatContext.PageHeight * figureLength.Value;
            }
            else if (figureLength.IsContent)
            {
                Thickness pageMargin = structuralCache.CurrentFormatContext.PageMargin;
                num = (structuralCache.CurrentFormatContext.PageHeight - pageMargin.Top - pageMargin.Bottom) * figureLength.Value;
            }
            else if (figureLength.IsColumn)
            {
                int    num2;
                double num3;
                double num4;
                double num5;
                FigureHelper.GetColumnMetrics(structuralCache, out num2, out num3, out num4, out num5);
                double num6 = figureLength.Value;
                if (num6 > (double)num2)
                {
                    num6 = (double)num2;
                }
                int num7 = (int)num6;
                if ((double)num7 == num6 && num7 > 0)
                {
                    num7--;
                }
                num = num3 * num6 + num4 * (double)num7;
            }
            else
            {
                num = FigureHelper.CalculateFigureCommon(figureLength);
            }
            if (!DoubleUtil.IsNaN(num))
            {
                FigureVerticalAnchor verticalAnchor = figure.VerticalAnchor;
                if (FigureHelper.IsVerticalPageAnchor(verticalAnchor))
                {
                    num = Math.Max(1.0, Math.Min(num, structuralCache.CurrentFormatContext.PageHeight));
                }
                else
                {
                    Thickness pageMargin2 = structuralCache.CurrentFormatContext.PageMargin;
                    num = Math.Max(1.0, Math.Min(num, structuralCache.CurrentFormatContext.PageHeight - pageMargin2.Top - pageMargin2.Bottom));
                }
                TextDpi.EnsureValidPageWidth(ref num);
                isHeightAuto = false;
            }
            else
            {
                num          = structuralCache.CurrentFormatContext.PageHeight;
                isHeightAuto = true;
            }
            return(num);
        }
Esempio n. 4
0
        private static bool IsValidVerticalAnchor(object o)
        {
            FigureVerticalAnchor value = (FigureVerticalAnchor)o;

            return(value == FigureVerticalAnchor.ContentBottom ||
                   value == FigureVerticalAnchor.ContentCenter ||
                   value == FigureVerticalAnchor.ContentTop ||
                   value == FigureVerticalAnchor.PageBottom ||
                   value == FigureVerticalAnchor.PageCenter ||
                   value == FigureVerticalAnchor.PageTop ||
                   value == FigureVerticalAnchor.ParagraphTop);
            // || value == FigureVerticalAnchor.CharacterBottom
            // || value == FigureVerticalAnchor.CharacterCenter
            // || value == FigureVerticalAnchor.CharacterTop;
        }
        // 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: 0x060067F5 RID: 26613 RVA: 0x001D3770 File Offset: 0x001D1970
        private double LimitTotalHeightFromAnchor(double height, double elementMarginHeight)
        {
            Figure figure = (Figure)base.Element;
            FigureVerticalAnchor verticalAnchor = figure.VerticalAnchor;
            double num;

            if (FigureHelper.IsVerticalPageAnchor(verticalAnchor))
            {
                num = base.StructuralCache.CurrentFormatContext.PageHeight;
            }
            else
            {
                Thickness pageMargin = base.StructuralCache.CurrentFormatContext.PageMargin;
                num = base.StructuralCache.CurrentFormatContext.PageHeight - pageMargin.Top - pageMargin.Bottom;
            }
            if (height + elementMarginHeight > num)
            {
                height = Math.Max(TextDpi.MinWidth, num - elementMarginHeight);
            }
            return(height);
        }
 // ------------------------------------------------------------------
 // Returns whether a vertical anchor is relative to content
 // ------------------------------------------------------------------
 internal static bool IsVerticalContentAnchor(FigureVerticalAnchor verticalAnchor)
 {
     return verticalAnchor == FigureVerticalAnchor.ContentTop || 
            verticalAnchor == FigureVerticalAnchor.ContentBottom || 
            verticalAnchor == FigureVerticalAnchor.ContentCenter;
 }
 // ------------------------------------------------------------------
 // Returns whether a vertical anchor is relative to page
 // ------------------------------------------------------------------
 internal static bool IsVerticalPageAnchor(FigureVerticalAnchor verticalAnchor)
 {
     return verticalAnchor == FigureVerticalAnchor.PageTop || 
            verticalAnchor == FigureVerticalAnchor.PageBottom || 
            verticalAnchor == FigureVerticalAnchor.PageCenter;
 }
        /// <summary>
        /// Returns an appropriate search rectangle for collision based on anchor properties.
        /// </summary>
        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 fsrcSearch;

            if(FigureHelper.IsHorizontalPageAnchor(horizAnchor))
            {
                fsrcSearch.u = fsrcPage.u;
                fsrcSearch.du = fsrcPage.du;
            }
            else if(FigureHelper.IsHorizontalContentAnchor(horizAnchor))
            {
                fsrcSearch.u = fsrcMargin.u;
                fsrcSearch.du = fsrcMargin.du;
            }
            else
            {
                fsrcSearch.u = fsrcTrack.u;
                fsrcSearch.du = fsrcTrack.du;
            }

            if(FigureHelper.IsVerticalPageAnchor(vertAnchor))
            {
                fsrcSearch.v = fsrcPage.v;
                fsrcSearch.dv = fsrcPage.dv;
            }
            else if(FigureHelper.IsVerticalContentAnchor(vertAnchor))
            {
                fsrcSearch.v = fsrcMargin.v;
                fsrcSearch.dv = fsrcMargin.dv;
            }
            else
            {
                fsrcSearch.v = fsrcFigurePreliminary.v;
                fsrcSearch.dv = (fsrcTrack.v + fsrcTrack.dv) - fsrcFigurePreliminary.v;
            }

            return fsrcSearch;
        }
Esempio n. 10
0
 // ------------------------------------------------------------------
 // Returns whether a vertical anchor is relative to content
 // ------------------------------------------------------------------
 internal static bool IsVerticalContentAnchor(FigureVerticalAnchor verticalAnchor)
 {
     return(verticalAnchor == FigureVerticalAnchor.ContentTop ||
            verticalAnchor == FigureVerticalAnchor.ContentBottom ||
            verticalAnchor == FigureVerticalAnchor.ContentCenter);
 }
Esempio n. 11
0
 // ------------------------------------------------------------------
 // Returns whether a vertical anchor is relative to page
 // ------------------------------------------------------------------
 internal static bool IsVerticalPageAnchor(FigureVerticalAnchor verticalAnchor)
 {
     return(verticalAnchor == FigureVerticalAnchor.PageTop ||
            verticalAnchor == FigureVerticalAnchor.PageBottom ||
            verticalAnchor == FigureVerticalAnchor.PageCenter);
 }
Esempio n. 12
0
        // ------------------------------------------------------------------
        // Height figure size calculation
        // ------------------------------------------------------------------
        internal static double CalculateFigureHeight(StructuralCache structuralCache, Figure figure, FigureLength figureLength, out bool isHeightAuto)
        {
            double value;

            if (figureLength.IsPage)
            {
                value = (structuralCache.CurrentFormatContext.PageHeight) * figureLength.Value;
            }
            else if (figureLength.IsContent) // Column to be treated same as content
            {
                Thickness pageMargin = structuralCache.CurrentFormatContext.PageMargin;

                value = (structuralCache.CurrentFormatContext.PageHeight - pageMargin.Top - pageMargin.Bottom) * figureLength.Value;
            }
            else if (figureLength.IsColumn)
            {
                // Height is calculated based on column width, since column height is the same as content. Per spec.
                // Retrieve all column metrics for current page
                int    cColumns;
                double columnWidth;
                double gap;
                double rule;
                FigureHelper.GetColumnMetrics(structuralCache, out cColumns, out columnWidth, out gap, out rule);

                // We do this to prevent a 2.0 columns from spanning 2.0 + gap, so we just check for edge
                double lengthValue = figureLength.Value;
                if (lengthValue > cColumns)
                {
                    lengthValue = cColumns;
                }
                int columnGapsSpanned = (int)lengthValue;
                if (columnGapsSpanned == lengthValue && columnGapsSpanned > 0)
                {
                    columnGapsSpanned -= 1;
                }

                value = (columnWidth * lengthValue) + gap * columnGapsSpanned;
            }
            else
            {
                value = FigureHelper.CalculateFigureCommon(figureLength);
            }

            if (!double.IsNaN(value))
            {
                FigureVerticalAnchor verticalAnchor = figure.VerticalAnchor;

                // Value is in pixels. Now we limit value to max out depending on anchoring.
                if (FigureHelper.IsVerticalPageAnchor(verticalAnchor))
                {
                    value = Math.Max(1, Math.Min(value, structuralCache.CurrentFormatContext.PageHeight));
                }
                else // Column and paragraph anchoring still max out at content height
                {
                    Thickness pageMargin = structuralCache.CurrentFormatContext.PageMargin;
                    value = Math.Max(1, Math.Min(value, structuralCache.CurrentFormatContext.PageHeight - pageMargin.Top - pageMargin.Bottom));
                }

                TextDpi.EnsureValidPageWidth(ref value);

                isHeightAuto = false;
            }
            else
            {
                value        = structuralCache.CurrentFormatContext.PageHeight;
                isHeightAuto = true;
            }

            return(value);
        }
        internal void GetFigureProperties(FigureParaClient paraClient, int fInTextLine, uint fswdir, int fBottomUndefined, out int dur, out int dvr, out PTS.FSFIGUREPROPS fsfigprops, out int cPolygons, out int cVertices, out int durDistTextLeft, out int durDistTextRight, out int dvrDistTextTop, out int dvrDistTextBottom)
        {
            Invariant.Assert(base.StructuralCache.CurrentFormatContext.FinitePage);
            uint    num     = PTS.FlowDirectionToFswdir((FlowDirection)base.Element.GetValue(FrameworkElement.FlowDirectionProperty));
            Figure  figure  = (Figure)base.Element;
            MbpInfo mbpInfo = MbpInfo.FromElement(base.Element, base.StructuralCache.TextFormatterHost.PixelsPerDip);

            durDistTextLeft = (durDistTextRight = (dvrDistTextTop = (dvrDistTextBottom = 0)));
            bool   flag;
            double width = FigureHelper.CalculateFigureWidth(base.StructuralCache, figure, figure.Width, out flag);
            double d     = this.LimitTotalWidthFromAnchor(width, TextDpi.FromTextDpi(mbpInfo.MarginLeft + mbpInfo.MarginRight));
            int    num2  = Math.Max(1, TextDpi.ToTextDpi(d) - (mbpInfo.BPLeft + mbpInfo.BPRight));
            bool   flag2;
            double height = FigureHelper.CalculateFigureHeight(base.StructuralCache, figure, figure.Height, out flag2);
            double d2     = this.LimitTotalHeightFromAnchor(height, TextDpi.FromTextDpi(mbpInfo.MarginTop + mbpInfo.MarginBottom));
            int    num3   = Math.Max(1, TextDpi.ToTextDpi(d2) - (mbpInfo.BPTop + mbpInfo.BPBottom));
            int    num4   = 1;

            PTS.FSCOLUMNINFO[] array = new PTS.FSCOLUMNINFO[num4];
            array[0].durBefore = 0;
            array[0].durWidth  = num2;
            PTS.FSRECT fsrect = new PTS.FSRECT(0, 0, num2, num3);
            PTS.FSFMTR fsfmtr;
            IntPtr     intPtr;
            IntPtr     intPtr2;

            PTS.FSBBOX fsbbox;
            IntPtr     zero;
            int        num5;

            this.CreateSubpageFiniteHelper(base.PtsContext, IntPtr.Zero, 0, this._mainTextSegment.Handle, IntPtr.Zero, 0, 1, fswdir, num2, num3, ref fsrect, num4, array, 0, out fsfmtr, out intPtr, out intPtr2, out dvr, out fsbbox, out zero, out num5);
            if (intPtr2 != IntPtr.Zero)
            {
                PTS.Validate(PTS.FsDestroySubpageBreakRecord(base.PtsContext.Context, intPtr2));
            }
            if (PTS.ToBoolean(fsbbox.fDefined))
            {
                if (fsbbox.fsrc.du < num2 && flag)
                {
                    if (intPtr != IntPtr.Zero)
                    {
                        PTS.Validate(PTS.FsDestroySubpage(base.PtsContext.Context, intPtr), base.PtsContext);
                    }
                    if (zero != IntPtr.Zero)
                    {
                        MarginCollapsingState marginCollapsingState = base.PtsContext.HandleToObject(zero) as MarginCollapsingState;
                        PTS.ValidateHandle(marginCollapsingState);
                        marginCollapsingState.Dispose();
                        zero = IntPtr.Zero;
                    }
                    num2 = fsbbox.fsrc.du + 1;
                    array[0].durWidth = num2;
                    PTS.FSRECT fsrect2 = new PTS.FSRECT(0, 0, num2, num3);
                    PTS.FSFMTR fsfmtr2;
                    IntPtr     intPtr3;
                    this.CreateSubpageFiniteHelper(base.PtsContext, IntPtr.Zero, 0, this._mainTextSegment.Handle, IntPtr.Zero, 0, 1, fswdir, num2, num3, ref fsrect2, num4, array, 0, out fsfmtr2, out intPtr, out intPtr3, out dvr, out fsbbox, out zero, out num5);
                    if (intPtr3 != IntPtr.Zero)
                    {
                        PTS.Validate(PTS.FsDestroySubpageBreakRecord(base.PtsContext.Context, intPtr3));
                    }
                }
            }
            else
            {
                num2 = TextDpi.ToTextDpi(TextDpi.MinWidth);
            }
            dur = num2 + mbpInfo.MBPLeft + mbpInfo.MBPRight;
            if (zero != IntPtr.Zero)
            {
                MarginCollapsingState marginCollapsingState2 = base.PtsContext.HandleToObject(zero) as MarginCollapsingState;
                PTS.ValidateHandle(marginCollapsingState2);
                marginCollapsingState2.Dispose();
                zero = IntPtr.Zero;
            }
            dvr += mbpInfo.MBPTop + mbpInfo.MBPBottom;
            if (!flag2)
            {
                dvr = TextDpi.ToTextDpi(d2) + mbpInfo.MarginTop + mbpInfo.MarginBottom;
            }
            FigureHorizontalAnchor horizontalAnchor = figure.HorizontalAnchor;
            FigureVerticalAnchor   verticalAnchor   = figure.VerticalAnchor;

            fsfigprops.fskrefU = (PTS.FSKREF)(horizontalAnchor / FigureHorizontalAnchor.ContentLeft);
            fsfigprops.fskrefV = (PTS.FSKREF)(verticalAnchor / FigureVerticalAnchor.ContentTop);
            fsfigprops.fskalfU = (PTS.FSKALIGNFIG)(horizontalAnchor % FigureHorizontalAnchor.ContentLeft);
            fsfigprops.fskalfV = (PTS.FSKALIGNFIG)(verticalAnchor % FigureVerticalAnchor.ContentTop);
            if (!PTS.ToBoolean(fInTextLine))
            {
                if (fsfigprops.fskrefU == PTS.FSKREF.fskrefChar)
                {
                    fsfigprops.fskrefU = PTS.FSKREF.fskrefMargin;
                    fsfigprops.fskalfU = PTS.FSKALIGNFIG.fskalfMin;
                }
                if (fsfigprops.fskrefV == PTS.FSKREF.fskrefChar)
                {
                    fsfigprops.fskrefV = PTS.FSKREF.fskrefMargin;
                    fsfigprops.fskalfV = PTS.FSKALIGNFIG.fskalfMin;
                }
            }
            fsfigprops.fskwrap       = PTS.WrapDirectionToFskwrap(figure.WrapDirection);
            fsfigprops.fNonTextPlane = 0;
            fsfigprops.fAllowOverlap = 0;
            fsfigprops.fDelayable    = PTS.FromBoolean(figure.CanDelayPlacement);
            cPolygons = (cVertices = 0);
            paraClient.SubpageHandle = intPtr;
        }
        //-------------------------------------------------------------------
        // 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;
        }
        internal void GetFigureProperties(
            FigureParaClient paraClient,        // IN:
            int fInTextLine,                    // IN:  it is attached to text line
            uint fswdir,                        // IN:  current direction
            int fBottomUndefined,               // IN:  bottom of page is not defined
            out int dur,                        // OUT: width of figure
            out int dvr,                        // OUT: height of figure
            out PTS.FSFIGUREPROPS fsfigprops,   // OUT: figure attributes
            out int cPolygons,                  // OUT: number of polygons
            out int cVertices,                  // OUT: total number of vertices in all polygons
            out int durDistTextLeft,            // OUT: distance to text from MinU side
            out int durDistTextRight,           // OUT: distance to text from MaxU side
            out int dvrDistTextTop,             // OUT: distance to text from MinV side
            out int dvrDistTextBottom)          // OUT: distance to text from MaxV side
        {
            Invariant.Assert(StructuralCache.CurrentFormatContext.FinitePage);

            uint fswdirPara = PTS.FlowDirectionToFswdir(((FlowDirection)Element.GetValue(FrameworkElement.FlowDirectionProperty)));

            IntPtr pfsFigureContent;

            PTS.FSBBOX fsbbox;
            int        cColumns;
            int        dvrTopSpace;

            PTS.FSCOLUMNINFO[] columnInfoCollection;
            IntPtr             pmcsclientOut;
            MbpInfo            mbp;

            Figure element = (Figure)Element;

            // Initialize the subpage size. PTS subpage margin is always set to 0 for Figures.
            // If width on figure is specified, use the specified value.
            // Border and padding of the figure is extracted from available subpage width.
            // We use StructuralCache.CurrentFormatContext's page dimensions as limiting values for figure MBP
            mbp = MbpInfo.FromElement(Element);
            // We do not mirror margin as it's used to dist text left and right, and is unnecessary.

            durDistTextLeft = durDistTextRight = dvrDistTextTop = dvrDistTextBottom = 0;

            // Calculate specified width. IsAuto flag is needed because Auto is formatted the same way as column and will
            // not return Double.NaN.
            bool   isWidthAuto;
            double specifiedWidth = FigureHelper.CalculateFigureWidth(StructuralCache, element,
                                                                      element.Width,
                                                                      out isWidthAuto);


            double anchorLimitedWidth = LimitTotalWidthFromAnchor(specifiedWidth, TextDpi.FromTextDpi(mbp.MarginLeft + mbp.MarginRight));
            int    subpageWidth       = Math.Max(1, TextDpi.ToTextDpi(anchorLimitedWidth) - (mbp.BPLeft + mbp.BPRight));

            // Calculate figure height, IsAuto flag is used as specifiedHeight will never be NaN.
            bool   isHeightAuto;
            double specifiedHeight = FigureHelper.CalculateFigureHeight(StructuralCache, element,
                                                                        element.Height,
                                                                        out isHeightAuto);

            double anchorLimitedHeight = LimitTotalHeightFromAnchor(specifiedHeight, TextDpi.FromTextDpi(mbp.MarginTop + mbp.MarginBottom));
            int    subpageHeight       = Math.Max(1, TextDpi.ToTextDpi(anchorLimitedHeight) - (mbp.BPTop + mbp.BPBottom));

            // Initialize column info. Figure always has just 1 column.
            cColumns             = 1;
            columnInfoCollection = new PTS.FSCOLUMNINFO[cColumns];
            columnInfoCollection[0].durBefore = 0;
            columnInfoCollection[0].durWidth  = subpageWidth;

            // Create subpage
            {
                PTS.FSFMTR fsfmtr;
                IntPtr     brParaOut;
                PTS.FSRECT marginRect = new PTS.FSRECT(0, 0, subpageWidth, subpageHeight);

                CreateSubpageFiniteHelper(PtsContext, IntPtr.Zero, PTS.False, _mainTextSegment.Handle, IntPtr.Zero, PTS.False, PTS.True,
                                          fswdir, subpageWidth, subpageHeight, ref marginRect,
                                          cColumns, columnInfoCollection, PTS.False,
                                          out fsfmtr, out pfsFigureContent, out brParaOut, out dvr, out fsbbox, out pmcsclientOut,
                                          out dvrTopSpace);

                if (brParaOut != IntPtr.Zero)
                {
                    PTS.Validate(PTS.FsDestroySubpageBreakRecord(PtsContext.Context, brParaOut));
                }
            }

            // PTS subpage does not support autosizing, but Figure needs to autosize to its
            // content. To workaround this problem, second format of subpage is performed, if
            // necessary. It means that if the width of bounding box is smaller than subpage's
            // width, second formatting is performed.

            if (PTS.ToBoolean(fsbbox.fDefined))
            {
                if (fsbbox.fsrc.du < subpageWidth && isWidthAuto)
                {
                    // There is a need to reformat PTS subpage, so destroy any resourcces allocated by PTS
                    // during previous formatting.
                    if (pfsFigureContent != IntPtr.Zero)
                    {
                        PTS.Validate(PTS.FsDestroySubpage(PtsContext.Context, pfsFigureContent), PtsContext);
                    }
                    if (pmcsclientOut != IntPtr.Zero)
                    {
                        MarginCollapsingState mcs = PtsContext.HandleToObject(pmcsclientOut) as MarginCollapsingState;
                        PTS.ValidateHandle(mcs);
                        mcs.Dispose();
                        pmcsclientOut = IntPtr.Zero;
                    }
                    // Create subpage with new width.
                    subpageWidth = fsbbox.fsrc.du + 1; // add 1/300px to avoid rounding errors
                    columnInfoCollection[0].durWidth = subpageWidth;

                    // Create subpage
                    PTS.FSFMTR fsfmtr;
                    IntPtr     brParaOut;
                    PTS.FSRECT marginRect = new PTS.FSRECT(0, 0, subpageWidth, subpageHeight);

                    CreateSubpageFiniteHelper(PtsContext, IntPtr.Zero, PTS.False, _mainTextSegment.Handle, IntPtr.Zero, PTS.False, PTS.True,
                                              fswdir, subpageWidth, subpageHeight, ref marginRect,
                                              cColumns, columnInfoCollection, PTS.False,
                                              out fsfmtr, out pfsFigureContent, out brParaOut, out dvr, out fsbbox, out pmcsclientOut,
                                              out dvrTopSpace);

                    if (brParaOut != IntPtr.Zero)
                    {
                        PTS.Validate(PTS.FsDestroySubpageBreakRecord(PtsContext.Context, brParaOut));
                    }
                }
            }
            else
            {
                subpageWidth = TextDpi.ToTextDpi(TextDpi.MinWidth);
            }


            // Get the size of the figure. For height PTS already reports calculated value.
            // But width is the same as subpage width. Include margins in dur since we are not using
            // distance to text anymore.
            dur = subpageWidth + mbp.MBPLeft + mbp.MBPRight;

            // Destroy objects created by PTS, but not used here.
            if (pmcsclientOut != IntPtr.Zero)
            {
                MarginCollapsingState mcs = PtsContext.HandleToObject(pmcsclientOut) as MarginCollapsingState;
                PTS.ValidateHandle(mcs);
                mcs.Dispose();
                pmcsclientOut = IntPtr.Zero;
            }

            dvr += mbp.MBPTop + mbp.MBPBottom;
            if (!isHeightAuto)
            {
                // Replace height with explicit height if specified, adding margins in addition to height
                // Border and padding are included in specified height but margins are external
                dvr = TextDpi.ToTextDpi(anchorLimitedHeight) + mbp.MarginTop + mbp.MarginBottom;
            }

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

            fsfigprops.fskrefU = (PTS.FSKREF)(((int)horzAnchor) / 3);
            fsfigprops.fskrefV = (PTS.FSKREF)(((int)vertAnchor) / 3);
            fsfigprops.fskalfU = (PTS.FSKALIGNFIG)(((int)horzAnchor) % 3);
            fsfigprops.fskalfV = (PTS.FSKALIGNFIG)(((int)vertAnchor) % 3);

            // PTS does not allow to anchor delayed figures to 'Character'
            if (!PTS.ToBoolean(fInTextLine))
            {
                if (fsfigprops.fskrefU == PTS.FSKREF.fskrefChar)
                {
                    fsfigprops.fskrefU = PTS.FSKREF.fskrefMargin;
                    fsfigprops.fskalfU = PTS.FSKALIGNFIG.fskalfMin;
                }
                if (fsfigprops.fskrefV == PTS.FSKREF.fskrefChar)
                {
                    fsfigprops.fskrefV = PTS.FSKREF.fskrefMargin;
                    fsfigprops.fskalfV = PTS.FSKALIGNFIG.fskalfMin;
                }
            }

            // Always wrap text on both sides of the floater.
            fsfigprops.fskwrap       = PTS.WrapDirectionToFskwrap(element.WrapDirection);
            fsfigprops.fNonTextPlane = PTS.False;
            fsfigprops.fAllowOverlap = PTS.False;
            fsfigprops.fDelayable    = PTS.FromBoolean(element.CanDelayPlacement);

            // Tight wrap is disabled for now.
            cPolygons = cVertices = 0;

            // Update handle to PTS subpage.
            ((FigureParaClient)paraClient).SubpageHandle = pfsFigureContent;
        }
        // Token: 0x06002CAC RID: 11436 RVA: 0x000C9618 File Offset: 0x000C7818
        private static bool IsValidVerticalAnchor(object o)
        {
            FigureVerticalAnchor figureVerticalAnchor = (FigureVerticalAnchor)o;

            return(figureVerticalAnchor == FigureVerticalAnchor.ContentBottom || figureVerticalAnchor == FigureVerticalAnchor.ContentCenter || figureVerticalAnchor == FigureVerticalAnchor.ContentTop || figureVerticalAnchor == FigureVerticalAnchor.PageBottom || figureVerticalAnchor == FigureVerticalAnchor.PageCenter || figureVerticalAnchor == FigureVerticalAnchor.PageTop || figureVerticalAnchor == FigureVerticalAnchor.ParagraphTop);
        }