/// <summary> /// Creating a simple text run /// </summary> /// <param name="settings">text formatting settings</param> /// <param name="charString">character string associated to textrun</param> /// <param name="textRun">text run</param> /// <param name="cp">first cp of the run</param> /// <param name="cpFirst">first cp of the line</param> /// <param name="runLength">run length</param> /// <param name="widthLeft">maximum run width</param> /// <param name="idealRunOffsetUnRounded">run's offset from the beginning of the line</param> /// <returns>a SimpleRun object</returns> static public SimpleRun Create( FormatSettings settings, CharacterBufferRange charString, TextRun textRun, int cp, int cpFirst, int runLength, int widthLeft, int idealRunOffsetUnRounded ) { SimpleRun run = null; if (textRun is TextCharacters) { if ( textRun.Properties.BaselineAlignment != BaselineAlignment.Baseline || (textRun.Properties.TextEffects != null && textRun.Properties.TextEffects.Count != 0) ) { // fast path does not handle the following conditions // o non-default baseline alignment // o text drawing effect ( return null; } TextDecorationCollection textDecorations = textRun.Properties.TextDecorations; if ( textDecorations != null && textDecorations.Count != 0 && !textDecorations.ValueEquals(TextDecorations.Underline)) { // we only support a single underline return null; } settings.DigitState.SetTextRunProperties(textRun.Properties); if (settings.DigitState.RequiresNumberSubstitution) { // don't support number substitution in fast path return null; } bool canProcessTabsInSimpleShapingPath = CanProcessTabsInSimpleShapingPath( settings.Pap, settings.Formatter.TextFormattingMode ); if (charString[0] == TextStore.CharCarriageReturn) { // CR in the middle of text stream treated as explicit paragraph break // simple hard line break runLength = 1; if (charString.Length > 1 && charString[1] == TextStore.CharLineFeed) { runLength = 2; } // This path handles the case where the backing store breaks the text run in between // a Carriage Return and a Line Feed. So we fetch the next run to check whether the next // character is a line feed. else if (charString.Length == 1) { // Prefetch to check for line feed. TextRun newRun; int newRunLength; CharacterBufferRange newBufferRange = settings.FetchTextRun( cp + 1, cpFirst, out newRun, out newRunLength ); if (newBufferRange.Length > 0 && newBufferRange[0] == TextStore.CharLineFeed) { // Merge the 2 runs. int lengthOfRun = 2; char[] characterArray = new char[lengthOfRun]; characterArray[0] = TextStore.CharCarriageReturn; characterArray[1] = TextStore.CharLineFeed; TextRun mergedTextRun = new TextCharacters(characterArray, 0, lengthOfRun, textRun.Properties); return new SimpleRun(lengthOfRun, mergedTextRun, (Flags.EOT | Flags.Ghost), settings.Formatter); } } return new SimpleRun(runLength, textRun, (Flags.EOT | Flags.Ghost), settings.Formatter); } else if (charString[0] == TextStore.CharLineFeed) { // LF in the middle of text stream treated as explicit paragraph break // simple hard line break runLength = 1; return new SimpleRun(runLength, textRun, (Flags.EOT | Flags.Ghost), settings.Formatter); } else if (canProcessTabsInSimpleShapingPath && charString[0] == TextStore.CharTab) { return CreateSimpleRunForTab(settings, textRun, idealRunOffsetUnRounded); } // attempt to create a simple run for text run = CreateSimpleTextRun( charString, textRun, settings.Formatter, widthLeft, settings.Pap.EmergencyWrap, canProcessTabsInSimpleShapingPath ); if (run == null) { // fail to create simple text run, the run content is too complex return null; } // Check for underline condition if (textDecorations != null && textDecorations.Count == 1 ) { run.Underline = textDecorations[0]; } } else if (textRun is TextEndOfLine) { run = new SimpleRun(runLength, textRun, (Flags.EOT | Flags.Ghost), settings.Formatter); } else if (textRun is TextHidden) { // hidden run run = new SimpleRun(runLength, textRun, Flags.Ghost, settings.Formatter); } return run; }
/// <summary> /// Creating a simple text run /// </summary> /// <param name="settings">text formatting settings</param> /// <param name="cp">first cp of the run</param> /// <param name="cpFirst">first cp of the line</param> /// <param name="widthLeft">maxium run width</param> /// <param name="widthMax">maximum column width</param> /// <param name="idealRunOffsetUnRounded">run's offset from the beginning of the line</param> /// <returns>a SimpleRun object</returns> static public SimpleRun Create( FormatSettings settings, int cp, int cpFirst, int widthLeft, int widthMax, int idealRunOffsetUnRounded ) { TextRun textRun; int runLength; CharacterBufferRange charBufferRange = settings.FetchTextRun( cp, cpFirst, out textRun, out runLength ); return Create( settings, charBufferRange, textRun, cp, cpFirst, runLength, widthLeft, idealRunOffsetUnRounded ); }