public void AddLine(LineMetrics line) { lineMetrices.Add(line); }
/// <summary> /// Style line instead of word by word. Some tags such as bold, italic, font etc will be added to multiple words /// Less common styles added on each word it applies. /// </summary> /// <param name="line"></param> public static void StyleLine(LineMetrics line) { StringBuilder sb = new StringBuilder(); ChunkMetrics prev = line.ChunkMetrices.ElementAt(0); StyleWord(prev, true); for (int i = 1; i < line.ChunkMetrices.Count; i++) { StringBuilder closeTags = new StringBuilder(); if (line.ChunkMetrices.ElementAt(i).FontFamily != prev.FontFamily) { } if (line.ChunkMetrices.ElementAt(i).GetFontSize() != prev.GetFontSize()) { } if (line.ChunkMetrices.ElementAt(i).Bold) { if (!prev.Bold) { sb.Append("<b>"); } } else { if (prev.Bold) { closeTags.Append("</b>"); } } if (line.ChunkMetrices.ElementAt(i).Italic) { } // The bottom four decorating will be less common and so added word by word if (line.ChunkMetrices.ElementAt(i).Strikethrough) { sb.Append("<s>"); closeTags.Append("</s>"); } if (line.ChunkMetrices.ElementAt(i).Underline) { sb.Append("<u>"); closeTags.Append("</u>"); } if (line.ChunkMetrices.ElementAt(i).Superscript) { sb.Append("<sup>"); closeTags.Append("</sup"); } if (line.ChunkMetrices.ElementAt(i).Subscript) { sb.Append("<sub>"); closeTags.Append("</sub>"); } sb.Append(line.ChunkMetrices.ElementAt(i)); sb.Append(closeTags); } }
public float LineWidthProportion(LineMetrics line) { return(line.ContentWidth() / pageMaxWidth); }
public float LineHeightProportion(LineMetrics line) { return(line.ContentHeight() / pageMaxHeight); }
/// Captures text using a simplified algorithm for inserting hard returns and spaces /// @param renderInfo render info public virtual void RenderText(TextRenderInfo renderInfo) { // todo handle adding last line string text = renderInfo.GetText().Replace('\t', ' '); if (!Utils.FloatsNearlyEqual(renderInfo.GetBaseline().GetStartPoint().Get(Vector.I2), baseline, 0.01f) && !Utils.FloatsNearlyEqual(renderInfo.GetAscentLine().GetStartPoint().Get(Vector.I2), ascent, 0.01f)) { startOfNewline = true; } if (startOfNewline) { if (currLine != null) { if (currChunk.ChunkStr.Length > 0) { StartNewWord(); startOfChunk = true; } currLine.RightMostPos = bottomRight.Get(Vector.I1); currLine.LineSpacingBelow = currLine.Descent - renderInfo.GetAscentLine().GetStartPoint().Get(Vector.I2); } currLine = new LineMetrics(); pageMetrics.AddLine(currLine); currLine.Ascent = renderInfo.GetAscentLine().GetStartPoint().Get(Vector.I2); currLine.Descent = renderInfo.GetDescentLine().GetStartPoint().Get(Vector.I2); currLine.Baseline = renderInfo.GetBaseline().GetStartPoint().Get(Vector.I2); currLine.LeftMostPos = renderInfo.GetBaseline().GetStartPoint().Get(Vector.I1); currLine.LineSpacingAbove = descent - currLine.Ascent; startOfNewline = false; } CharMetrics charMetrics; // Check if there is space char required between chunks if (GetResultantText().Length > 0 && IsSpaceRequired(bottomRight.Get(Vector.I1), renderInfo.GetBaseline().GetStartPoint().Get(Vector.I1), renderInfo.GetBaseline().GetStartPoint().Get(Vector.I2), renderInfo.GetSingleSpaceWidth())) // todo switch order { charMetrics = new CharMetrics(' '); charMetrics.BottomLeft = new Vector3D(bottomLeft); charMetrics.TopLeft = new Vector3D(topLeft); charMetrics.BottomRight = new Vector3D(renderInfo.GetBaseline().GetStartPoint()); charMetrics.TopRight = new Vector3D(renderInfo.GetAscentLine().GetStartPoint()); this.charMetrices.Add(charMetrics); text = " " + text; // todo extra spacing? e.g. handle if it is 4x singlespace width } TextRenderInfo lastChar = null; int charInd = 0; foreach (TextRenderInfo charInfo in renderInfo.GetCharacterRenderInfos()) { if (charInfo.GetText().Length == 0) { continue; } if (lastChar != null && IsSpaceRequired(lastChar.GetBaseline().GetEndPoint().Get(Vector.I1), charInfo.GetBaseline().GetStartPoint().Get(Vector.I1), renderInfo.GetSingleSpaceWidth())) { charMetrics = new CharMetrics(' '); charMetrics.FontSize = charInfo.GetFontSize(); charMetrics.BottomLeft = new Vector3D(lastChar.GetBaseline().GetEndPoint()); charMetrics.TopLeft = new Vector3D(lastChar.GetAscentLine().GetEndPoint()); charMetrics.BottomRight = new Vector3D(charInfo.GetBaseline().GetStartPoint()); charMetrics.TopRight = new Vector3D(charInfo.GetAscentLine().GetStartPoint()); charMetrices.Add(charMetrics); text = text.Insert(charInd + 1, " "); } char c = charInfo.GetText()[0] == '\t' ? ' ' : charInfo.GetText()[0]; charMetrics = new CharMetrics(c); charMetrics.FontSize = charInfo.GetFontSize(); charMetrics.BottomLeft = new Vector3D(charInfo.GetBaseline().GetStartPoint()); charMetrics.TopLeft = new Vector3D(charInfo.GetAscentLine().GetStartPoint()); charMetrics.BottomRight = new Vector3D(charInfo.GetBaseline().GetEndPoint()); charMetrics.TopRight = new Vector3D(charInfo.GetAscentLine().GetEndPoint()); charMetrices.Add(charMetrics); lastChar = charInfo; charInd++; } if (startOfChunk) { if (Utils.FloatsNearlyEqual(currLine.Baseline, baseline, 0.001f)) { float horSpacing = Math.Abs( bottomRight.Get(Vector.I1) - renderInfo.GetBaseline().GetStartPoint().Get(Vector.I1)); if (horSpacing > spaceWidth) { Console.Write(""); } } bottomLeft = renderInfo.GetBaseline().GetStartPoint(); topLeft = renderInfo.GetAscentLine().GetStartPoint(); currChunk.BottomLeft = new Vector3D(bottomLeft); currChunk.TopLeft = new Vector3D(topLeft); baseline = renderInfo.GetBaseline().GetStartPoint().Get(Vector.I2); ascent = renderInfo.GetAscentLine().GetStartPoint().Get(Vector.I2); descent = renderInfo.GetDescentLine().GetStartPoint().Get(Vector.I2); spaceWidth = renderInfo.GetSingleSpaceWidth(); startOfChunk = false; } bottomRight = renderInfo.GetBaseline().GetEndPoint(); topRight = renderInfo.GetAscentLine().GetEndPoint(); string currFont = renderInfo.GetFont() != null?renderInfo.GetFont().ToString() : ""; if (currChunk.FontFamily == null && currFont.Length > 0) { currChunk.FontFamily = currFont; } //Check if faux bold is used if ((renderInfo.GetTextRenderMode() == (int)TextRenderMode.FillThenStrokeText) || // todo include render mode for outsets etc? renderInfo.GetFont().GetFontProgram().GetFontNames().IsBold()) { currChunk.Bold = true; } if (!(Utils.FloatsNearlyEqual(renderInfo.GetFont().GetFontProgram().GetFontMetrics().GetItalicAngle(), 0, 0.001f)) || renderInfo.GetFont().GetFontProgram().GetFontNames().IsItalic()) { currChunk.Italic = true; } if (currChunk.FillColor == null && renderInfo.GetFillColor() != null) { currChunk.FillColor = ProcessColorInfo(renderInfo.GetFillColor()); } if (currChunk.StrokeColor == null && renderInfo.GetStrokeColor() != null) { currChunk.StrokeColor = ProcessColorInfo(renderInfo.GetStrokeColor()); } currChunk.Append(text); result.Append(text); // todo include newlines }