예제 #1
0
        //-------------------------------------------------------------------
        //
        //  Constructors
        //
        //-------------------------------------------------------------------

        #region Constructors

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="host">
        /// TextFormatter host
        /// </param>
        /// <param name="cpPara">
        /// Character position of paragraph
        /// </param>
        /// <param name="durTrack">
        /// Track width
        /// </param>
        /// <param name="paraClient">
        /// Owner of the line
        /// </param>
        /// <param name="runCache">
        /// Text run cache
        /// </param>
        internal OptimalTextSource(TextFormatterHost host, int cpPara, int durTrack, TextParaClient paraClient, TextRunCache runCache) : base(paraClient)
        {
            _host     = host;
            _durTrack = durTrack;
            _runCache = runCache;
            _cpPara   = cpPara;
        }
예제 #2
0
 /// <summary>
 /// Client to ask for the possible smallest and largest paragraph width that can fully contain the passing text content
 /// </summary>
 /// <param name="textSource">an object representing text layout clients text source for TextFormatter.</param>
 /// <param name="firstCharIndex">character index to specify where in the source text the line starts</param>
 /// <param name="paragraphProperties">properties that can change from one paragraph to the next, such as text flow direction, text alignment, or indentation.</param>
 /// <param name="textRunCache">an object representing content cache of the client.</param>
 /// <returns>min max paragraph width</returns>
 public override MinMaxParagraphWidth FormatMinMaxParagraphWidth(
     TextSource textSource,
     int firstCharIndex,
     TextParagraphProperties paragraphProperties,
     TextRunCache textRunCache
     )
 {
     throw new NotImplementedException("Managed.TextFormatting.TextFormatter.FormatMinMaxParagraphWidth");
 }
예제 #3
0
        /// <summary>
        /// Format and produce a text line either with or without previously known
        /// line break point.
        /// </summary>
        private TextLine FormatLineInternal(
            TextSource textSource,
            int firstCharIndex,
            int lineLength,
            double paragraphWidth,
            TextParagraphProperties paragraphProperties,
            TextLineBreak previousLineBreak,
            TextRunCache textRunCache
            )
        {
            EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordText, EventTrace.Level.Verbose, EventTrace.Event.WClientStringBegin, "TextFormatterImp.FormatLineInternal Start");

            // prepare formatting settings
            FormatSettings settings = PrepareFormatSettings(
                textSource,
                firstCharIndex,
                paragraphWidth,
                paragraphProperties,
                previousLineBreak,
                textRunCache,
                (lineLength != 0), // Do optimal break if break is given
                true,              // isSingleLineFormatting
                _textFormattingMode
                );

            TextLine textLine = null;

            if (!settings.Pap.AlwaysCollapsible &&
                previousLineBreak == null &&
                lineLength <= 0
                )
            {
                // simple text line.
                textLine = SimpleTextLine.Create(
                    settings,
                    firstCharIndex,
                    RealToIdealFloor(paragraphWidth),
                    textSource.PixelsPerDip
                    ) as TextLine;
            }

            if (textLine == null)
            {
                // content is complex, creating complex line
                textLine = new TextMetrics.FullTextLine(
                    settings,
                    firstCharIndex,
                    lineLength,
                    RealToIdealFloor(paragraphWidth),
                    LineFlags.None
                    ) as TextLine;
            }

            EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordText, EventTrace.Level.Verbose, EventTrace.Event.WClientStringEnd, "TextFormatterImp.FormatLineInternal End");

            return(textLine);
        }
예제 #4
0
        internal override TextParagraphCache CreateParagraphCache(
#endif
            TextSource textSource,
            int firstCharIndex,
            double paragraphWidth,
            TextParagraphProperties paragraphProperties,
            TextLineBreak previousLineBreak,
            TextRunCache textRunCache
            )
        {
            throw new NotImplementedException("Managed.TextFormatting.TextFormatter.CreateParagraphCache");
        }
예제 #5
0
 /// <summary>
 /// Client to format a text line that fills a paragraph in the document.
 /// </summary>
 /// <param name="textSource">an object representing text layout clients text source for TextFormatter.</param>
 /// <param name="firstCharIndex">character index to specify where in the source text the line starts</param>
 /// <param name="paragraphWidth">width of paragraph in which the line fills</param>
 /// <param name="paragraphProperties">properties that can change from one paragraph to the next, such as text flow direction, text alignment, or indentation.</param>
 /// <param name="previousLineBreak">LineBreak property of the previous text line, or null if this is the first line in the paragraph</param>
 /// <param name="textRunCache">an object representing content cache of the client.</param>
 /// <returns>object representing a line of text that client interacts with. </returns>
 public override TextLine FormatLine(
     TextSource textSource,
     int firstCharIndex,
     double paragraphWidth,
     TextParagraphProperties paragraphProperties,
     TextLineBreak previousLineBreak,
     TextRunCache textRunCache
     )
 {
     return(FormatLineInternal(
                textSource,
                firstCharIndex,
                0,
                paragraphWidth,
                paragraphProperties,
                previousLineBreak,
                textRunCache));
 }
        internal override TextLine RecreateLine(
#endif
            TextSource textSource,
            int firstCharIndex,
            int lineLength,
            double paragraphWidth,
            TextParagraphProperties paragraphProperties,
            TextLineBreak previousLineBreak,
            TextRunCache textRunCache
            )
        {
            return(FormatLineInternal(
                       textSource,
                       firstCharIndex,
                       lineLength,
                       paragraphWidth,
                       paragraphProperties,
                       previousLineBreak,
                       textRunCache
                       ));
        }
        internal override TextParagraphCache CreateParagraphCache(
#endif
            TextSource textSource,
            int firstCharIndex,
            double paragraphWidth,
            TextParagraphProperties paragraphProperties,
            TextLineBreak previousLineBreak,
            TextRunCache textRunCache
            )
        {
            // prepare formatting settings
            FormatSettings settings = PrepareFormatSettings(
                textSource,
                firstCharIndex,
                paragraphWidth,
                paragraphProperties,
                previousLineBreak,
                textRunCache,
                true,   // optimalBreak
                false,  // !isSingleLineFormatting
                _textFormattingMode
                );

            //
            // Optimal paragraph formatting session specific check
            //
            if (!settings.Pap.Wrap && settings.Pap.OptimalBreak)
            {
                // Optimal paragraph must wrap.
                throw new ArgumentException(SR.Get(SRID.OptimalParagraphMustWrap));
            }

            // create paragraph content cache object
            return(new TextParagraphCache(
                       settings,
                       firstCharIndex,
                       RealToIdeal(paragraphWidth)
                       ));
        }
        /// <summary>
        /// Validate all the relevant text formatting initial settings and package them
        /// </summary>
        private FormatSettings PrepareFormatSettings(
            TextSource textSource,
            int firstCharIndex,
            double paragraphWidth,
            TextParagraphProperties paragraphProperties,
            TextLineBreak previousLineBreak,
            TextRunCache textRunCache,
            bool useOptimalBreak,
            bool isSingleLineFormatting,
            TextFormattingMode textFormattingMode
            )
        {
            VerifyTextFormattingArguments(
                textSource,
                firstCharIndex,
                paragraphWidth,
                paragraphProperties,
                textRunCache
                );

            if (textRunCache.Imp == null)
            {
                // No run cache object available, create one
                textRunCache.Imp = new TextRunCacheImp();
            }

            // initialize formatting settings
            return(new FormatSettings(
                       this,
                       textSource,
                       textRunCache.Imp,
                       new ParaProp(this, paragraphProperties, useOptimalBreak),
                       previousLineBreak,
                       isSingleLineFormatting,
                       textFormattingMode,
                       false
                       ));
        }
        /// <summary>
        /// Client to ask for the possible smallest and largest paragraph width that can fully contain the passing text content
        /// </summary>
        /// <param name="textSource">an object representing text layout clients text source for TextFormatter.</param>
        /// <param name="firstCharIndex">character index to specify where in the source text the line starts</param>
        /// <param name="paragraphProperties">properties that can change from one paragraph to the next, such as text flow direction, text alignment, or indentation.</param>
        /// <param name="textRunCache">an object representing content cache of the client.</param>
        /// <returns>min max paragraph width</returns>
        public override MinMaxParagraphWidth FormatMinMaxParagraphWidth(
            TextSource textSource,
            int firstCharIndex,
            TextParagraphProperties paragraphProperties,
            TextRunCache textRunCache
            )
        {
            // prepare formatting settings
            FormatSettings settings = PrepareFormatSettings(
                textSource,
                firstCharIndex,
                0,      // infinite paragraphWidth
                paragraphProperties,
                null,   // always format the whole paragraph - no previousLineBreak
                textRunCache,
                false,  // optimalBreak
                true,   // isSingleLineFormatting
                _textFormattingMode
                );

            // create specialized line specifically for min/max calculation
            TextMetrics.FullTextLine line = new TextMetrics.FullTextLine(
                settings,
                firstCharIndex,
                0,  // lineLength
                0,  // paragraph width has no significant meaning in min/max calculation
                (LineFlags.KeepState | LineFlags.MinMax)
                );

            // line width in this case is the width of a line when the entire paragraph is laid out
            // as a single long line.
            MinMaxParagraphWidth minMax = new MinMaxParagraphWidth(line.MinWidth, line.Width);

            line.Dispose();
            return(minMax);
        }
예제 #10
0
        // ------------------------------------------------------------------
        // Create and format text line.
        //
        //      lineStartIndex - index of the first character in the line
        //      width - wrapping width of the line
        //      lineProperties - properties of the line
        //      textRunCache - run cache used by text formatter
        //      showParagraphEllipsis - true if paragraph ellipsis is shown
        //                              at the end of the line
        // ------------------------------------------------------------------
        internal void Format(int dcp, double width, TextParagraphProperties lineProperties, TextLineBreak textLineBreak, TextRunCache textRunCache, bool showParagraphEllipsis)
        {
#if TEXTPANELLAYOUTDEBUG
            TextPanelDebug.IncrementCounter("Line.Format", TextPanelDebug.Category.TextView);
#endif
            _mirror = (lineProperties.FlowDirection == FlowDirection.RightToLeft);
            _dcp    = dcp;
            _showParagraphEllipsis = showParagraphEllipsis;
            _wrappingWidth         = width;
            _line = _owner.TextFormatter.FormatLine(this, dcp, width, lineProperties, textLineBreak, textRunCache);
        }
예제 #11
0
        //-------------------------------------------------------------------
        //
        //  Internal Methods
        //
        //-------------------------------------------------------------------

        #region Internal Methods

        /// <summary>
        /// Create and format text line.
        /// </summary>
        /// <param name="dcp">First character position for the line.</param>
        /// <param name="formatWidth">Width to pass to LS formatter.</param>
        /// <param name="paragraphWidth">Line wrapping width.</param>
        /// <param name="lineProperties">Line's properties.</param>
        /// <param name="textRunCache">Run cache.</param>
        /// <param name="formatter">Text formatter.</param>
        /// <remarks>
        /// formatWidth/paragraphWidth is an attempt to work around bug 114719.
        /// Unfortunately, Line Services cannot guarantee that once a line
        /// has been measured, measuring the same content with the actual line
        /// width will produce the same line.
        ///
        /// For example, suppose we format dcp 0 with paragraphWidth = 100.
        /// Suppose this results in a line from dcp 0 - 10, with width = 95.
        ///
        /// We would expect that a call to FormatLine with dcp = 0,
        /// paragraphWidth = 95 would result in the same 10 char line.
        /// But in practice it might return a 9 char line.
        ///
        /// The workaround is to pass in an explicit formatting width across
        /// multiple calls, even if the paragraphWidth changes.
        /// </remarks>
        internal void Format(int dcp, double formatWidth, double paragraphWidth, LineProperties lineProperties, TextRunCache textRunCache, TextFormatter formatter)
        {
            _lineProperties = lineProperties;
            _dcp            = dcp;
            _paragraphWidth = paragraphWidth;

            // We must ignore TextAlignment here since formatWidth does not
            // necessarilly equal paragraphWidth.  We'll adjust on later calls.
            lineProperties.IgnoreTextAlignment = (lineProperties.TextAlignment != TextAlignment.Justify);
            try
            {
                _line = formatter.FormatLine(this, dcp, formatWidth, lineProperties, null, textRunCache);
            }
            finally
            {
                lineProperties.IgnoreTextAlignment = false;
            }
        }
        /// <summary>
        /// Verify all text formatting arguments
        /// </summary>
        private void VerifyTextFormattingArguments(
            TextSource textSource,
            int firstCharIndex,
            double paragraphWidth,
            TextParagraphProperties paragraphProperties,
            TextRunCache textRunCache
            )
        {
            if (textSource == null)
            {
                throw new ArgumentNullException("textSource");
            }

            if (textRunCache == null)
            {
                throw new ArgumentNullException("textRunCache");
            }

            if (paragraphProperties == null)
            {
                throw new ArgumentNullException("paragraphProperties");
            }

            if (paragraphProperties.DefaultTextRunProperties == null)
            {
                throw new ArgumentNullException("paragraphProperties.DefaultTextRunProperties");
            }

            if (paragraphProperties.DefaultTextRunProperties.Typeface == null)
            {
                throw new ArgumentNullException("paragraphProperties.DefaultTextRunProperties.Typeface");
            }

            if (DoubleUtil.IsNaN(paragraphWidth))
            {
                throw new ArgumentOutOfRangeException("paragraphWidth", SR.Get(SRID.ParameterValueCannotBeNaN));
            }

            if (double.IsInfinity(paragraphWidth))
            {
                throw new ArgumentOutOfRangeException("paragraphWidth", SR.Get(SRID.ParameterValueCannotBeInfinity));
            }

            if (paragraphWidth < 0 ||
                paragraphWidth > Constants.RealInfiniteWidth)
            {
                throw new ArgumentOutOfRangeException("paragraphWidth", SR.Get(SRID.ParameterMustBeBetween, 0, Constants.RealInfiniteWidth));
            }

            double realMaxFontRenderingEmSize = Constants.RealInfiniteWidth / Constants.GreatestMutiplierOfEm;

            if (paragraphProperties.DefaultTextRunProperties.FontRenderingEmSize < 0 ||
                paragraphProperties.DefaultTextRunProperties.FontRenderingEmSize > realMaxFontRenderingEmSize)
            {
                throw new ArgumentOutOfRangeException("paragraphProperties.DefaultTextRunProperties.FontRenderingEmSize", SR.Get(SRID.ParameterMustBeBetween, 0, realMaxFontRenderingEmSize));
            }

            if (paragraphProperties.Indent > Constants.RealInfiniteWidth)
            {
                throw new ArgumentOutOfRangeException("paragraphProperties.Indent", SR.Get(SRID.ParameterCannotBeGreaterThan, Constants.RealInfiniteWidth));
            }

            if (paragraphProperties.LineHeight > Constants.RealInfiniteWidth)
            {
                throw new ArgumentOutOfRangeException("paragraphProperties.LineHeight", SR.Get(SRID.ParameterCannotBeGreaterThan, Constants.RealInfiniteWidth));
            }

            if (paragraphProperties.DefaultIncrementalTab < 0 ||
                paragraphProperties.DefaultIncrementalTab > Constants.RealInfiniteWidth)
            {
                throw new ArgumentOutOfRangeException("paragraphProperties.DefaultIncrementalTab", SR.Get(SRID.ParameterMustBeBetween, 0, Constants.RealInfiniteWidth));
            }
        }
예제 #13
0
 // Token: 0x0600662D RID: 26157 RVA: 0x001CB874 File Offset: 0x001C9A74
 internal void Format(int dcp, double width, TextParagraphProperties lineProperties, TextLineBreak textLineBreak, TextRunCache textRunCache, bool showParagraphEllipsis)
 {
     this._mirror = (lineProperties.FlowDirection == FlowDirection.RightToLeft);
     this._dcp    = dcp;
     this._showParagraphEllipsis = showParagraphEllipsis;
     this._wrappingWidth         = width;
     this._line = this._owner.TextFormatter.FormatLine(this, dcp, width, lineProperties, textLineBreak, textRunCache);
 }
예제 #14
0
 // Token: 0x06008AAB RID: 35499 RVA: 0x00257686 File Offset: 0x00255886
 internal FormattingContext(bool measureMode, bool clearOnLeft, bool clearOnRight, TextRunCache textRunCache)
 {
     this.MeasureMode            = measureMode;
     this.ClearOnLeft            = clearOnLeft;
     this.ClearOnRight           = clearOnRight;
     this.TextRunCache           = textRunCache;
     this.LineFormatLengthTarget = -1;
 }
 // Token: 0x06004134 RID: 16692 RVA: 0x0012A210 File Offset: 0x00128410
 internal void Format(int dcp, double formatWidth, double paragraphWidth, LineProperties lineProperties, TextRunCache textRunCache, TextFormatter formatter)
 {
     this._lineProperties = lineProperties;
     this._dcp            = dcp;
     this._paragraphWidth = paragraphWidth;
     lineProperties.IgnoreTextAlignment = (lineProperties.TextAlignment != TextAlignment.Justify);
     try
     {
         this._line = formatter.FormatLine(this, dcp, formatWidth, lineProperties, null, textRunCache);
     }
     finally
     {
         lineProperties.IgnoreTextAlignment = false;
     }
 }