コード例 #1
0
        /// <summary>
        /// Constructs a <code>LineBreakMeasurer</code> for the specified text.
        /// </summary>
        /// <param name="text"> the text for which this <code>LineBreakMeasurer</code>
        ///     produces <code>TextLayout</code> objects; the text must contain
        ///     at least one character; if the text available through
        ///     <code>iter</code> changes, further calls to this
        ///     <code>LineBreakMeasurer</code> instance are undefined (except,
        ///     in some cases, when <code>insertChar</code> or
        ///     <code>deleteChar</code> are invoked afterward - see below) </param>
        /// <param name="breakIter"> the <seealso cref="BreakIterator"/> which defines line
        ///     breaks </param>
        /// <param name="frc"> contains information about a graphics device which is
        ///       needed to measure the text correctly;
        ///       text measurements can vary slightly depending on the
        ///       device resolution, and attributes such as antialiasing; this
        ///       parameter does not specify a translation between the
        ///       <code>LineBreakMeasurer</code> and user space </param>
        /// <exception cref="IllegalArgumentException"> if the text has less than one character </exception>
        /// <seealso cref= LineBreakMeasurer#insertChar </seealso>
        /// <seealso cref= LineBreakMeasurer#deleteChar </seealso>
        public LineBreakMeasurer(AttributedCharacterIterator text, BreakIterator breakIter, FontRenderContext frc)
        {
            if (text.EndIndex - text.BeginIndex < 1)
            {
                throw new IllegalArgumentException("Text must contain at least one character.");
            }

            this.BreakIter = breakIter;
            this.Measurer  = new TextMeasurer(text, frc);
            this.Limit     = text.EndIndex;
            this.Pos       = this.Start = text.BeginIndex;

            CharIter = new CharArrayIterator(Measurer.Chars, this.Start);
            this.BreakIter.SetText(CharIter);
        }
コード例 #2
0
        internal LineLayout NextLine()
        {
            if (_currentPos < _currentRun && !Format.NoWrap)
            {
                return(NextTextLayoutFromMeasurer());
            }

            _charsConsumed += _currentRun;
            if (_charsConsumed >= _s.Length)
            {
                return(null);
            }

            string s;
            int    lineBreakIndex = _s.IndexOf(NewLine, _charsConsumed);

            if (lineBreakIndex >= 0)
            {
                s = _s.Substring(_charsConsumed, lineBreakIndex - _charsConsumed + NewLine.Length);
            }
            else
            {
                s = _s.Substring(_charsConsumed);
            }

            _currentRun = s.Length;
            _currentPos = 0;

            text.AttributedString aS = new text.AttributedString(s);

            // TODO: add more attribs according to StringFormat
            aS.addAttribute(font.TextAttribute.FONT, _font.NativeObject);
            if ((_font.Style & FontStyle.Underline) != FontStyle.Regular)
            {
                aS.addAttribute(font.TextAttribute.UNDERLINE, font.TextAttribute.UNDERLINE_ON);
            }
            if ((_font.Style & FontStyle.Strikeout) != FontStyle.Regular)
            {
                aS.addAttribute(font.TextAttribute.STRIKETHROUGH, font.TextAttribute.STRIKETHROUGH_ON);
            }

            text.AttributedCharacterIterator charIter = aS.getIterator();

            _measurer = new font.TextMeasurer(charIter, _frc);
            return(NextTextLayoutFromMeasurer());
        }
コード例 #3
0
		internal LineLayout NextLine() {
			if (_currentPos < _currentRun && !Format.NoWrap)
				return NextTextLayoutFromMeasurer();

			_charsConsumed += _currentRun;
			if (_charsConsumed >= _s.Length)
				return null;

			string s;
			int lineBreakIndex = _s.IndexOf(NewLine, _charsConsumed);
			if (lineBreakIndex >= 0) {
				s = _s.Substring(_charsConsumed, lineBreakIndex - _charsConsumed + NewLine.Length);
			}
			else
				s = _s.Substring(_charsConsumed);

			_currentRun = s.Length;
			_currentPos = 0;

			text.AttributedString aS = new text.AttributedString(s);
				
			// TODO: add more attribs according to StringFormat
			aS.addAttribute(font.TextAttribute.FONT, _font.NativeObject);
			if((_font.Style & FontStyle.Underline) != FontStyle.Regular)
				aS.addAttribute(font.TextAttribute.UNDERLINE, font.TextAttribute.UNDERLINE_ON);
			if((_font.Style & FontStyle.Strikeout) != FontStyle.Regular)
				aS.addAttribute(font.TextAttribute.STRIKETHROUGH, font.TextAttribute.STRIKETHROUGH_ON);

			text.AttributedCharacterIterator charIter = aS.getIterator();

			_measurer = new font.TextMeasurer(charIter, _frc);
			return NextTextLayoutFromMeasurer();
		}