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; }
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; }