public TextLayout(AttributedCharacterIterator text) { fullText = text.GetText(); trimText = fullText; font = text.GetFont(); layout = font.FontFamily; stringColor = text.GetColor(); int start = text.GetBeginIndex(); int limit = text.GetEndIndex(); if (start == limit) { throw new ArgumentException("Zero length iterator passed to TextLayout constructor."); } int len = limit - start; text.First(); char[] chars = new char[len]; int n = 0; for (char c = text.First(); c != DONE; c = text.Next()) { chars[n++] = c; } GetGraphicLayout(fullText, text.GetFont()); }
public LineBreakMeasurer(AttributedCharacterIterator text) { //GetGraphics(); if (text.GetEndIndex() - text.GetBeginIndex() < 1) { throw new ArgumentException("Text must contain at least one character."); } this.limit = text.GetEndIndex(); this.pos = this.start = text.GetBeginIndex(); // extract chars fChars = new char[text.GetEndIndex() - text.GetBeginIndex()]; int n = 0; for (char c = text.First(); c != DONE; c = text.Next()) { fChars[n++] = c; } text.First(); stringFont = (Font)text.GetAttribute(TextAttribute.FONT); stringColor = (Color)text.GetAttribute(TextAttribute.FOREGROUND); characterCount = fChars.Length; }
public override string ToString() { StringBuilder sb = new StringBuilder("StringElement["); sb.Append("Bounds=").Append(GetBounds()) .Append(",Height=").Append(p_height).Append("(").Append(p_maxHeight) .Append("),Width=").Append(p_width).Append("(").Append(p_maxHeight) .Append("),PageLocation=").Append(p_pageLocation).Append(" - "); for (int i = 0; i < m_string_paper.Length; i++) { if (m_string_paper.Length > 1) { sb.Append(Env.NL).Append(i).Append(":"); } AttributedCharacterIterator iter = m_string_paper[i].GetIterator(); for (char c = iter.First(); c != DONE; c = iter.Next()) { sb.Append(c); } } if (m_ID != null) { sb.Append(",ID=(").Append(m_ID.ToStringX()).Append(")"); } sb.Append("]"); return(sb.ToString()); } // toString
/// <summary> /// Create a new StyledParagraph over the given styled text. </summary> /// <param name="aci"> an iterator over the text </param> /// <param name="chars"> the characters extracted from aci </param> public StyledParagraph(AttributedCharacterIterator aci, char[] chars) { int start = aci.BeginIndex; int end = aci.EndIndex; Length = end - start; int index = start; aci.First(); do { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int nextRunStart = aci.getRunLimit(); int nextRunStart = aci.RunLimit; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int localIndex = index-start; int localIndex = index - start; //JAVA TO C# CONVERTER TODO TASK: Java wildcard generics are not converted to .NET: //ORIGINAL LINE: java.util.Map<? extends java.text.AttributedCharacterIterator_Attribute, ?> attributes = aci.getAttributes(); IDictionary <?, ?> attributes = aci.Attributes; attributes = AddInputMethodAttrs(attributes); Decoration d = Decoration.getDecoration(attributes); AddDecoration(d, localIndex); Object f = GetGraphicOrFont(attributes); if (f == null) { AddFonts(chars, attributes, localIndex, nextRunStart - start); } else { AddFont(f, localIndex); } aci.Index = nextRunStart; index = nextRunStart; } while (index < end); // Add extra entries to starts arrays with the length // of the paragraph. 'this' is used as a dummy value // in the Vector. if (Decorations != null) { DecorationStarts = AddToVector(this, Length, Decorations, DecorationStarts); } if (Fonts != null) { FontStarts = AddToVector(this, Length, Fonts, FontStarts); } }
} // translate public override void PaintPdf(XGraphics g2D, int pageNo, PointF pageStart, Ctx ctx, bool isView) { m_solidbrush = new SolidBrush(Color.Black); PointF location = GetAbsoluteLocation(pageStart); // if (m_originalString != null) { Translate(ctx); } AttributedString aString = null; AttributedCharacterIterator iter = null; // AttributedCharacterIterator iter2 = null; float xPos = (float)location.X; float yPos = (float)location.Y; float yPen = 0f; float height = 0f; float width = 0f; // for all lines for (int i = 0; i < m_string_paper.Length; i++) { // Get Text if (isView) { if (m_string_view[i] == null) { continue; } aString = m_string_view[i]; } else { if (m_string_paper[i] == null) { continue; } aString = m_string_paper[i]; } iter = aString.GetIterator(); // Zero Length if (iter.GetBeginIndex() == iter.GetEndIndex()) { continue; } // Check for Tab (just first) and 16 bit characters int tabPos = -1; bool is8Bit = true; for (char c = iter.First(); c != DONE; c = iter.Next()) { if (c == '\t' && tabPos == -1) { tabPos = iter.GetIndex(); } if (c > 255) { is8Bit = false; } } TextLayout layout = null; float xPen = xPos; // No Limit if (p_maxWidth == 0f) { if (tabPos == -1) { layout = new TextLayout(iter); yPen = yPos + layout.GetAscent(); // layout.draw(g2D, xPen, yPen); //m_font); //g2D.setPaint(m_paint); //XFont d = new XFont(m_font, new XPdfFontOptions(PdfSharp.Pdf.PdfFontEncoding.Unicode, PdfSharp.Pdf.PdfFontEmbedding.Automatic)); //StringBuilder txt = new StringBuilder(); //txt.Append("\u202D") //.Append(iter.GetText()) //.Append("\u202C"); //g2D.DrawString( XPdfFontOptions options = new XPdfFontOptions(PdfSharp.Pdf.PdfFontEncoding.Unicode, PdfSharp.Pdf.PdfFontEmbedding.Always); PdfSharp.Drawing.Layout.XTextFormatter tf = new PdfSharp.Drawing.Layout.XTextFormatter(g2D); //XStringFormat sf = new XStringFormat(); //sf.Alignment = XStringAlignment.Near; //tf.Alignment = PdfSharp.Drawing.Layout.XParagraphAlignment.Left; //tf.DrawString(iter.GetText(), new XFont(m_font, options), new XSolidBrush(XColors.Black), (double)xPen, (double)yPen); g2D.DrawString(iter.GetText(), new XFont(m_font, options), new XSolidBrush(XColors.Black), (double)xPen, (double)yPen, new XStringFormat() { Alignment = XStringAlignment.Near }); // yPos += layout.GetAscent() + layout.GetDescent() + layout.GetLeading(); if (width < layout.GetAdvance()) { width = layout.GetAdvance(); } } else // we have a tab { LineBreakMeasurer measurer = new LineBreakMeasurer(iter); layout = measurer.NextLayout(9999, tabPos); float lineHeight_1 = layout.GetAscent() + layout.GetDescent() + layout.GetLeading(); yPen = yPos + layout.GetAscent(); g2D.DrawString(iter.GetText(), new XFont(m_font, new XPdfFontOptions(PdfSharp.Pdf.PdfFontEncoding.Unicode, PdfSharp.Pdf.PdfFontEmbedding.Always)), new XSolidBrush(XColors.Black), (double)xPen, (double)yPen); // first part before tab xPen = GetTabPos(xPos, layout.GetAdvance()); float lineWidth = xPen - xPos; layout = measurer.NextLayout(9999);//, iter.getEndIndex(), true); float lineHeight_2 = layout.GetAscent() + layout.GetDescent() + layout.GetLeading(); //layout.draw(g2D, xPen, yPen); // second part after tab // yPos += Math.Max(lineHeight_1, lineHeight_2); lineWidth += layout.GetAdvance(); if (width < lineWidth) { width = lineWidth; } } // log.finest( "StringElement.paint - No Limit - " + location.x + "/" + yPos // + " w=" + layout.getAdvance() + ",h=" + lineHeight + ", Bounds=" + layout.getBounds()); } // Size Limits else { bool fastDraw = LayoutEngine.s_FASTDRAW; if (fastDraw && !isView && !is8Bit) { fastDraw = false; } LineBreakMeasurer measurer = new LineBreakMeasurer(iter); while (measurer.GetPosition() < iter.GetEndIndex()) { if (tabPos == -1) { layout = measurer.NextLayout(p_maxWidth); // use fastDraw if the string fits in one line if (fastDraw && iter.GetEndIndex() != measurer.GetPosition()) { fastDraw = false; } } else // tab { fastDraw = false; layout = measurer.NextLayout(p_maxWidth, tabPos); } // Line Height float lineHeight = layout.GetAscent() + layout.GetDescent() + layout.GetLeading(); if (p_maxHeight == -1f && i == 0) // one line only { p_maxHeight = lineHeight; } // If we have hight left over if (p_maxHeight == 0f || (height + lineHeight) <= p_maxHeight) { yPen = (float)location.Y + height + layout.GetAscent(); // Tab in Text if (tabPos != -1) { layout.Draw(g2D, (double)xPen, (double)yPen); // first part before tab xPen = GetTabPos(xPos, layout.GetAdvance()); layout = measurer.NextLayout(p_width, iter.GetEndIndex()); tabPos = -1; // reset (just one tab) } else if ((X_AD_PrintFormatItem.FIELDALIGNMENTTYPE_TrailingRight.Equals(p_FieldAlignmentType) && layout.IsLeftToRight()) || (X_AD_PrintFormatItem.FIELDALIGNMENTTYPE_LeadingLeft.Equals(p_FieldAlignmentType)) && !layout.IsLeftToRight()) { xPen += p_maxWidth - layout.GetAdvance(); } else if (X_AD_PrintFormatItem.FIELDALIGNMENTTYPE_Center.Equals(p_FieldAlignmentType)) { xPen += (p_maxWidth - layout.GetAdvance()) / 2; } else if (X_AD_PrintFormatItem.FIELDALIGNMENTTYPE_Block.Equals(p_FieldAlignmentType) && measurer.GetPosition() < iter.GetEndIndex()) { //layout = layout.getJustifiedLayout(p_maxWidth); fastDraw = false; } if (fastDraw) { //g2D.setFont(m_font); //g2D.setPaint(m_paint); g2D.DrawString(iter.GetText(), new XFont(m_font, new XPdfFontOptions(PdfSharp.Pdf.PdfFontEncoding.Unicode, PdfSharp.Pdf.PdfFontEmbedding.Always)), new XSolidBrush(XColors.Black), (double)xPen, (double)yPen - 7); } else { layout.Draw(g2D, (double)xPen, (double)yPen); } height += lineHeight; // log.finest( "StringElement.paint - Limit - " + xPen + "/" + yPen // + " w=" + layout.getAdvance() + ",h=" + lineHeight + ", Align=" + p_FieldAlignmentType + ", Max w=" + p_maxWidth + ",h=" + p_maxHeight + ", Bounds=" + layout.getBounds()); } } width = p_maxWidth; } // size limits } // for all strings if (m_check != null) { int x = (int)(location.X + width + 1); int y = (int)(location.Y); //g2D.DrawImage((bool)m_check ? LayoutEngine.IMAGE_TRUE : LayoutEngine.IMAGE_FALSE, x, y); } }
} // getTabPos protected override bool CalculateSize() { try { if (p_sizeCalculated) { return(true); } // //FontRenderContext frc = new FontRenderContext(null, true, true); TextLayout layout = null; p_height = 0f; p_width = 0f; // No Limit if (p_maxWidth == 0f && p_maxHeight == 0f) { foreach (AttributedString element in m_string_paper) { AttributedCharacterIterator iter = element.GetIterator(); if (iter.GetBeginIndex() == iter.GetEndIndex()) { continue; } // Check for Tab (just first) int tabPos = -1; for (char c = iter.First(); c != DONE && tabPos == -1; c = iter.Next()) { if (c == '\t') { tabPos = iter.GetIndex(); } } if (tabPos == -1) { layout = new TextLayout(iter); p_height += layout.GetAscent() + layout.GetDescent() + layout.GetLeading(); if (p_width < layout.GetAdvance()) { p_width = layout.GetAdvance(); } } else // with tab { LineBreakMeasurer measurer = new LineBreakMeasurer(iter); layout = measurer.NextLayout(9999, tabPos); p_height += layout.GetAscent() + layout.GetDescent() + layout.GetLeading(); float width = GetTabPos(0, layout.GetAdvance()); layout = measurer.NextLayout(9999, iter.GetEndIndex()); width += layout.GetAdvance(); if (p_width < width) { p_width = width; } } } // for all strings // Add CheckBox Size if (m_check != null) { p_width += LayoutEngine.IMAGE_SIZE.width; if (p_height < LayoutEngine.IMAGE_SIZE.height) { p_height = LayoutEngine.IMAGE_SIZE.height; } } } // Size Limits else { p_width = p_maxWidth; for (int i = 0; i < m_string_paper.Length; i++) { AttributedCharacterIterator iter = m_string_paper[i].GetIterator(); if (iter.GetBeginIndex() == iter.GetEndIndex()) { continue; } LineBreakMeasurer measurer = new LineBreakMeasurer(iter); // System.out.println("StringLength=" + m_originalString.length() + " MaxWidth=" + p_maxWidth + " MaxHeight=" + p_maxHeight); while (measurer.GetPosition() < iter.GetEndIndex()) { // no need to expand tab space for limited space layout = measurer.NextLayout(p_maxWidth); float lineHeight = layout.GetAscent() + layout.GetDescent() + layout.GetLeading(); // System.out.println(" LineWidth=" + layout.getAdvance() + " LineHeight=" + lineHeight); if (p_maxHeight == -1f && i == 0) // one line only { p_maxHeight = lineHeight; } if (p_maxHeight == 0f || (p_height + lineHeight) <= p_maxHeight) { p_height += lineHeight; } } } // for all strings // Add CheckBox Size if (m_check != null) { // p_width += LayoutEngine.IMAGE_SIZE.width; if (p_height < LayoutEngine.IMAGE_SIZE.height) { p_height = LayoutEngine.IMAGE_SIZE.height; } } // System.out.println(" Width=" + p_width + " Height=" + p_height); } // System.out.println("StringElement.calculate size - Width=" // + p_width + "(" + p_maxWidth + ") - Height=" + p_height + "(" + p_maxHeight + ")"); // Enlarge Size when aligned and max size is given if (p_FieldAlignmentType != null) { bool changed = false; if (p_height < p_maxHeight) { p_height = p_maxHeight; changed = true; } if (p_width < p_maxWidth) { p_width = p_maxWidth; changed = true; } if (changed) { log.Finest("Width=" + p_width + "(" + p_maxWidth + ") - Height=" + p_height + "(" + p_maxHeight + ")"); } } } catch { } return(true); } // calculateSize
/// <summary> /// Returns a parameter string identifying this event. /// This method is useful for event-logging and for debugging. /// It contains the event ID in text form, the characters of the /// committed and composed text /// separated by "+", the number of committed characters, /// the caret, and the visible position. /// </summary> /// <returns> a string identifying the event and its attributes </returns> public override String ParamString() { String typeStr; switch (Id) { case INPUT_METHOD_TEXT_CHANGED: typeStr = "INPUT_METHOD_TEXT_CHANGED"; break; case CARET_POSITION_CHANGED: typeStr = "CARET_POSITION_CHANGED"; break; default: typeStr = "unknown type"; break; } String textString; if (Text_Renamed == null) { textString = "no text"; } else { StringBuilder textBuffer = new StringBuilder("\""); int committedCharacterCount = this.CommittedCharacterCount_Renamed; char c = Text_Renamed.First(); while (committedCharacterCount-- > 0) { textBuffer.Append(c); c = Text_Renamed.Next(); } textBuffer.Append("\" + \""); while (c != java.text.CharacterIterator_Fields.DONE) { textBuffer.Append(c); c = Text_Renamed.Next(); } textBuffer.Append("\""); textString = textBuffer.ToString(); } String countString = CommittedCharacterCount_Renamed + " characters committed"; String caretString; if (Caret_Renamed == null) { caretString = "no caret"; } else { caretString = "caret: " + Caret_Renamed.ToString(); } String visiblePositionString; if (VisiblePosition_Renamed == null) { visiblePositionString = "no visible position"; } else { visiblePositionString = "visible position: " + VisiblePosition_Renamed.ToString(); } return(typeStr + ", " + textString + ", " + countString + ", " + caretString + ", " + visiblePositionString); }
/// <summary> /// Initialize state, including fChars array, direction, and /// fBidi. /// </summary> private void InitAll(AttributedCharacterIterator text) { FStart = text.BeginIndex; // extract chars FChars = new char[text.EndIndex - FStart]; int n = 0; for (char c = text.First(); c != java.text.CharacterIterator_Fields.DONE; c = text.Next()) { FChars[n++] = c; } text.First(); FBidi = new Bidi(text); if (FBidi.LeftToRight) { FBidi = null; } text.First(); //JAVA TO C# CONVERTER TODO TASK: Java wildcard generics are not converted to .NET: //ORIGINAL LINE: java.util.Map<? extends java.text.AttributedCharacterIterator_Attribute, ?> paragraphAttrs = text.getAttributes(); IDictionary <?, ?> paragraphAttrs = text.Attributes; NumericShaper shaper = AttributeValues.getNumericShaping(paragraphAttrs); if (shaper != null) { shaper.Shape(FChars, 0, FChars.Length); } FParagraph = new StyledParagraph(text, FChars); { // set paragraph attributes // If there's an embedded graphic at the start of the // paragraph, look for the first non-graphic character // and use it and its font to initialize the paragraph. // If not, use the first graphic to initialize. FJustifyRatio = AttributeValues.getJustification(paragraphAttrs); bool haveFont = TextLine.AdvanceToFirstFont(text); if (haveFont) { Font defaultFont = TextLine.GetFontAtCurrentPos(text); int charsStart = text.Index - text.BeginIndex; LineMetrics lm = defaultFont.GetLineMetrics(FChars, charsStart, charsStart + 1, FFrc); FBaseline = (sbyte)lm.BaselineIndex; FBaselineOffsets = lm.BaselineOffsets; } else { // hmmm what to do here? Just try to supply reasonable // values I guess. GraphicAttribute graphic = (GraphicAttribute)paragraphAttrs[TextAttribute.CHAR_REPLACEMENT]; FBaseline = TextLayout.GetBaselineFromGraphic(graphic); //JAVA TO C# CONVERTER TODO TASK: Java wildcard generics are not converted to .NET: //ORIGINAL LINE: java.util.Hashtable<java.text.AttributedCharacterIterator_Attribute, ?> fmap = new java.util.Hashtable<>(5, (float)0.9); Dictionary <AttributedCharacterIterator_Attribute, ?> fmap = new Dictionary <AttributedCharacterIterator_Attribute, ?>(5, (float)0.9); Font dummyFont = new Font(fmap); LineMetrics lm = dummyFont.GetLineMetrics(" ", 0, 1, FFrc); FBaselineOffsets = lm.BaselineOffsets; } FBaselineOffsets = TextLine.GetNormalizedOffsets(FBaselineOffsets, FBaseline); } InvalidateComponents(); }