示例#1
0
        internal TextParagraphCache( 
            FormatSettings      settings,
            int                 firstCharIndex, 
            int                 paragraphWidth
            )
        {
            Invariant.Assert(settings != null); 

            // create full text 
            _finiteFormatWidth = settings.GetFiniteFormatWidth(paragraphWidth); 
            _fullText = FullTextState.Create(settings, firstCharIndex, _finiteFormatWidth);
 
            // acquiring LS context
            TextFormatterContext context = settings.Formatter.AcquireContext(_fullText, IntPtr.Zero);

            _fullText.SetTabs(context); 

            IntPtr ploparabreakValue = IntPtr.Zero; 
 
            LsErr lserr = context.CreateParaBreakingSession(
                firstCharIndex, 
                _finiteFormatWidth,
                // breakrec is not needed before the first cp of para cache
                // since we handle Bidi break ourselves.
                IntPtr.Zero, 
                ref ploparabreakValue,
                ref _penalizedAsJustified 
                ); 

            // get the exception in context before it is released 
            Exception callbackException = context.CallbackException;

            // release the context
            context.Release(); 

            if(lserr != LsErr.None) 
            { 
                GC.SuppressFinalize(this);
                if(callbackException != null) 
                {
                    // rethrow exception thrown in callbacks
                    throw new InvalidOperationException(SR.Get(SRID.CreateParaBreakingSessionFailure, lserr), callbackException);
                } 
                else
                { 
                    // throw with LS error codes 
                    TextFormatterContext.ThrowExceptionFromLsError(SR.Get(SRID.CreateParaBreakingSessionFailure, lserr), lserr);
                } 
            }

            _ploparabreak.Value = ploparabreakValue;
 
            // keep context alive till here
            GC.KeepAlive(context); 
        } 
            /// <summary>
            /// Constructing a FullTextLine
            /// </summary>
            /// <param name="settings">text formatting settings</param>
            /// <param name="cpFirst">Line's first cp</param>
            /// <param name="lineLength">character length of the line</param>
            /// <param name="paragraphWidth">paragraph width</param>
            /// <param name="lineFlags">line formatting control flags</param>
            internal FullTextLine(
                FormatSettings          settings,
                int                     cpFirst,
                int                     lineLength,
                int                     paragraphWidth,
                LineFlags               lineFlags
                )
                : this(settings.TextFormattingMode, settings.Pap.Justify)
            {
                if (    (lineFlags & LineFlags.KeepState) != 0
                    ||  settings.Pap.AlwaysCollapsible)
                {
                    _statusFlags |= StatusFlags.KeepState;
                }

                int finiteFormatWidth = settings.GetFiniteFormatWidth(paragraphWidth);

                FullTextState fullText = FullTextState.Create(settings, cpFirst, finiteFormatWidth);

                // formatting the line
                FormatLine(
                    fullText,
                    cpFirst,
                    lineLength,
                    fullText.FormatWidth,
                    finiteFormatWidth,
                    paragraphWidth,
                    lineFlags,
                    null    // collapsingSymbol
                    );
            }