Beispiel #1
0
 // ------------------------------------------------------------------
 // Constructor.
 // ------------------------------------------------------------------
 internal ParaEllipsisLineProperties(TextParagraphProperties lp)
 {
     _lp = lp;
 }
 /// <summary>
 /// Formats a text line.
 /// </summary>
 /// <param name="textSource">The text source.</param>
 /// <param name="firstTextSourceIndex">The first character index to start the text line from.</param>
 /// <param name="paragraphWidth">A <see cref="double"/> value that specifies the width of the paragraph that the line fills.</param>
 /// <param name="paragraphProperties">A <see cref="TextParagraphProperties"/> value that represents paragraph properties,
 /// such as TextWrapping, TextAlignment, or TextStyle.</param>
 /// <param name="previousLineBreak">A <see cref="TextLineBreak"/> value that specifies the text formatter state,
 /// in terms of where the previous line in the paragraph was broken by the text formatting process.</param>
 /// <returns>The formatted line.</returns>
 public abstract TextLine FormatLine(ITextSource textSource, int firstTextSourceIndex, double paragraphWidth,
                                     TextParagraphProperties paragraphProperties, TextLineBreak?previousLineBreak = null);
        public TextLine FormatLine(TextSource textSource, int firstCharIndex, double paragraphWidth, TextParagraphProperties paragraphProperties, TextLineBreak previousLineBreak)
        {
            var runs = new List <Tuple <TextRun, GlyphRun, int, double> >();

            int    index = firstCharIndex;
            double x = paragraphProperties.Indent, height = 0, baseline = 0;
            double trailWhitespaceWidth = 0;

            while (true)
            {
                var run       = textSource.GetTextRun(index);
                var textProps = run.Properties ?? paragraphProperties.DefaultTextRunProperties;
                var fontSize  = textProps.FontRenderingEmSize;
                var len       = run.Length;
                if (textProps != null)
                {
                    height   = Math.Max(height, (int)(textProps.Typeface.FontFamily.LineSpacing * fontSize));
                    baseline = Math.Max(baseline, (int)(textProps.Typeface.FontFamily.Baseline * fontSize));
                }

                if (run is TextEndOfLine || run == null)
                {
                    index += len;
                    runs.Add(Tuple.Create(run, (GlyphRun)null, 0, 0.0));
                    break;
                }
                else if (run is TextCharacters)
                {
                    var chrs       = (TextCharacters)run;
                    var charBuf    = getCharBuf(chrs.CharacterBufferReference);
                    var charOffset = getCharOffset(chrs.CharacterBufferReference);

                    GlyphTypeface gl;
                    if (!textProps.Typeface.TryGetGlyphTypeface(out gl))
                    {
                        throw new Exception("GlyphTypeface does not exists for font '" + textProps.Typeface.FontFamily + "'.");
                    }

                    ushort[] glyphIndexes  = new ushort[len];
                    double[] advanceWidths = new double[len];

                    double totalWidth      = 0;
                    int    trailWhitespace = 0;
                    trailWhitespaceWidth = 0;
                    for (int n = 0; n < len; n++)
                    {
                        var c = charBuf[charOffset + n];

                        ushort glyphIndex;
                        double width;

                        if (c == '\t')
                        {
                            glyphIndex = gl.CharacterToGlyphMap[' '];
                            width      = paragraphProperties.DefaultIncrementalTab - x % paragraphProperties.DefaultIncrementalTab;
                        }
                        else
                        {
                            if (!gl.CharacterToGlyphMap.TryGetValue(c, out glyphIndex))
                            {
                                glyphIndex = gl.CharacterToGlyphMap['?'];
                            }
                            width = gl.AdvanceWidths[glyphIndex] * fontSize;
                        }

                        glyphIndexes[n]  = glyphIndex;
                        advanceWidths[n] = width;

                        if (char.IsWhiteSpace(c))
                        {
                            trailWhitespace++;
                            trailWhitespaceWidth += width;
                        }
                        else
                        {
                            totalWidth          += trailWhitespaceWidth + width;
                            trailWhitespaceWidth = 0;
                            trailWhitespace      = 0;
                        }
                    }
                    var origin = new Point(x, 0);

                    var glyphRun = new GlyphRun(
                        gl, 0, false, fontSize, glyphIndexes, origin, advanceWidths,
                        null, null, null, null, null, null);
                    runs.Add(Tuple.Create(run, glyphRun, trailWhitespace, trailWhitespaceWidth));

                    x += totalWidth + trailWhitespaceWidth;

                    index += len;
                }
                else if (run is TextEmbeddedObject)
                {
                    var obj     = (TextEmbeddedObject)run;
                    var metrics = obj.Format(paragraphWidth - x);
                    runs.Add(Tuple.Create(run, (GlyphRun)null, 0, metrics.Width));

                    height = Math.Max(height, obj.Format(paragraphWidth - x).Height);
                    x     += metrics.Width;

                    index += len;
                }
            }

            return(new GlyphRunLine {
                entries = runs.ToArray(),
                baseline = baseline,
                width = x - trailWhitespaceWidth,
                height = height,
                mode = mode
            });
        }
Beispiel #4
0
        internal TextMarkerSource(
            TextParagraphProperties textParagraphProperties,
            TextMarkerStyle markerStyle,
            int autoNumberingIndex
            )
        {
            Debug.Assert(markerStyle != TextMarkerStyle.None);

            _textParagraphProperties = textParagraphProperties;
            TextRunProperties defaultRunProperties = _textParagraphProperties.DefaultTextRunProperties;

            PixelsPerDip = defaultRunProperties.PixelsPerDip;
            string symbolString = null;

            if (IsKnownSymbolMarkerStyle(markerStyle))
            {
                switch (markerStyle)
                {
                case TextMarkerStyle.Disc:
                    symbolString = "\x9f"; break;

                case TextMarkerStyle.Circle:
                    symbolString = "\xa1"; break;

                case TextMarkerStyle.Square:
                    symbolString = "\x71"; break;

                case TextMarkerStyle.Box:
                    symbolString = "\xa7"; break;
                }

                Typeface defaultTypeface = defaultRunProperties.Typeface;

                // recreate a new marker run properties based on symbol typeface e.g. Wingding
                _textRunProperties = new GenericTextRunProperties(
                    new Typeface(
                        new FontFamily("Wingdings"),
                        defaultTypeface.Style,
                        defaultTypeface.Weight,
                        defaultTypeface.Stretch
                        ),
                    defaultRunProperties.FontRenderingEmSize,
                    defaultRunProperties.FontHintingEmSize,
                    PixelsPerDip,
                    defaultRunProperties.TextDecorations,
                    defaultRunProperties.ForegroundBrush,
                    defaultRunProperties.BackgroundBrush,
                    defaultRunProperties.BaselineAlignment,
                    CultureMapper.GetSpecificCulture(defaultRunProperties.CultureInfo),
                    null // default number substitution for culture
                    );
            }
            else if (IsKnownIndexMarkerStyle(markerStyle))
            {
                // Internal client code should have already validated this.
                Debug.Assert(autoNumberingIndex > 0);

                _textRunProperties = defaultRunProperties;

                int counter = autoNumberingIndex;

                switch (markerStyle)
                {
                case TextMarkerStyle.Decimal:
                    _characterArray = ConvertNumberToString(counter, false, DecimalNumerics);
                    break;

                case TextMarkerStyle.LowerLatin:
                    _characterArray = ConvertNumberToString(counter, true, LowerLatinNumerics);
                    break;

                case TextMarkerStyle.UpperLatin:
                    _characterArray = ConvertNumberToString(counter, true, UpperLatinNumerics);
                    break;

                case TextMarkerStyle.LowerRoman:
                    symbolString = ConvertNumberToRomanString(counter, false);
                    break;

                case TextMarkerStyle.UpperRoman:
                    symbolString = ConvertNumberToRomanString(counter, true);
                    break;
                }
            }
            else
            {
                Debug.Assert(false, "Invalid marker style");
            }

            if (symbolString != null)
            {
                _characterArray = symbolString.ToCharArray();
            }

            Debug.Assert(_characterArray != null);
        }
Beispiel #5
0
        /// <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));
            }
        }
Beispiel #6
0
 public TextLine FormatLine(TextSource textSource, int firstCharIndex, double paragraphWidth,
                            TextParagraphProperties paragraphProperties, TextLineBreak previousLineBreak)
 {
     return(formatter.FormatLine(textSource, firstCharIndex, paragraphWidth, paragraphProperties, previousLineBreak));
 }
Beispiel #7
0
 // ------------------------------------------------------------------
 // GetTextMarkerProperties
 // ------------------------------------------------------------------
 internal TextMarkerProperties GetTextMarkerProperties(TextParagraphProperties textParaProps)
 {
     return(new TextSimpleMarkerProperties(_style, _offset, _index, textParaProps));
 }
Beispiel #8
0
        public static void FormatAndDrawLines(TextChange?change,
                                              int textStorePosition,
                                              ICustomTextSource source,
                                              double paragraphWidth0,
                                              Point linePosition,
                                              int lineNo,
                                              TextParagraphProperties genericTextParagraphProperties,
                                              DrawingContext myDc,
                                              Func <InputTuple, ILineInfo2Base?, object?> delegate1,
                                              ILineInfo2Base [] lineInfos,
                                              int liIndex,
                                              int batchLines,
                                              DrawingGroup myGroup0,
                                              object?batchArg, Func <DrawingContext?, DrawingGroup, ILineInfo2Base[], int, bool, object?, bool> batchAction, int?end)
        {
            TextLineBreak?prev = null;

            var myGroup        = myGroup0;
            var initialLineSet = true;

            while (textStorePosition < end.GetValueOrDefault(source.Length))
            {
                // Debug.WriteLine(Thread.CurrentThread.ManagedThreadId + ": "+ textStorePosition);
                var paragraphWidth = paragraphWidth0 - linePosition.X;
                if (paragraphWidth < 0)
                {
                    paragraphWidth = 0;
                }
                var textParagraphProperties = source.GetTextParagraphProperties(textStorePosition);

                var        pp  = textParagraphProperties ?? genericTextParagraphProperties;
                InputTuple in1 = new InputTuple(null, linePosition,
                                                source.AsTextSource(), textStorePosition, null,
                                                null, change, lineNo);
                var(height, length, _, li, prev1) = DoFormatLine2(source.AsTextSource(),
                                                                  textStorePosition, paragraphWidth, pp, myDc, linePosition, delegate1, in1, CreateLineInfo, lineNo, prev);
                prev = prev1;

                // var boundingRect = new Rect(linePosition.X, linePosition.Y, widthWithWs, height);

                lineInfos[liIndex++] = li;

                linePosition.Y += height;
                lineNo++;

                // Update the index position in the text store.
                textStorePosition += length;

                // if (lineNo % (lineCount / 10) == 0)
                // progress?.Report(new UpdateProgress(textStorePosition, lineNo, lineCount));

                if (lineNo <= 0 || lineNo % batchLines != 0)
                {
                    continue;
                }

                if (batchAction(myDc, myGroup, lineInfos, liIndex, initialLineSet, batchArg))
                {
                    myGroup = new DrawingGroup();
                    myDc    = myGroup.Open();
                }

                liIndex        = 0;
                initialLineSet = false;
            }

            if (lineNo % batchLines != 0)
            {
                batchAction(myDc, myGroup, lineInfos, liIndex, initialLineSet, batchArg);
            }
            // progress?.Report(new UpdateProgress(textStorePosition, lineNo, lineCount));
        }
Beispiel #9
0
 public TextLine FormatLine(TextSource textSource, int firstCharIndex, double paragraphWidth, TextParagraphProperties paragraphProperties)
 {
     return(TextLineImpl.Create(paragraphProperties, firstCharIndex, (int)paragraphWidth, textSource));
 }
 // Token: 0x06006866 RID: 26726 RVA: 0x001D6D10 File Offset: 0x001D4F10
 internal void Format(Line.FormattingContext ctx, int dcp, int width, int trackWidth, TextParagraphProperties lineProps, TextLineBreak textLineBreak)
 {
     this._formattingContext = ctx;
     this._dcp           = dcp;
     this._host.Context  = this;
     this._wrappingWidth = TextDpi.FromTextDpi(width);
     this._trackWidth    = TextDpi.FromTextDpi(trackWidth);
     this._mirror        = (lineProps.FlowDirection == FlowDirection.RightToLeft);
     this._indent        = lineProps.Indent;
     try
     {
         if (ctx.LineFormatLengthTarget == -1)
         {
             this._line = this._host.TextFormatter.FormatLine(this._host, dcp, this._wrappingWidth, lineProps, textLineBreak, ctx.TextRunCache);
         }
         else
         {
             this._line = this._host.TextFormatter.RecreateLine(this._host, dcp, ctx.LineFormatLengthTarget, this._wrappingWidth, lineProps, textLineBreak, ctx.TextRunCache);
         }
         this._runs = this._line.GetTextRunSpans();
         Invariant.Assert(this._runs != null, "Cannot retrieve runs collection.");
         if (this._formattingContext.MeasureMode)
         {
             List <InlineObject> list = new List <InlineObject>(1);
             int num = this._dcp;
             foreach (TextSpan <TextRun> textSpan in this._runs)
             {
                 TextRun value = textSpan.Value;
                 if (value is InlineObjectRun)
                 {
                     list.Add(new InlineObject(num, ((InlineObjectRun)value).UIElementIsland, (TextParagraph)this._paraClient.Paragraph));
                 }
                 else if (value is FloatingRun)
                 {
                     if (((FloatingRun)value).Figure)
                     {
                         this._hasFigures = true;
                     }
                     else
                     {
                         this._hasFloaters = true;
                     }
                 }
                 num += textSpan.Length;
             }
             if (list.Count == 0)
             {
                 list = null;
             }
             this.TextParagraph.SubmitInlineObjects(dcp, dcp + this.ActualLength, list);
         }
     }
     finally
     {
         this._host.Context = null;
     }
 }