Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// If fields vector is not null, find and add the fields of this format to
        /// the fields vector by iterating through its AttributedCharacterIterator
        /// </summary>
        ///
        /// <param name="format">the format to find fields for</param>
        /// <param name="arg">object to format</param>
        /// <param name="begin">the index where the string this format has formatted begins</param>
        /// <param name="fields">fields vector, each entry in this vector are of typeFieldContainer.</param>
        private void Handleformat(Format format, Object arg, int begin,
                                  List <FieldContainer> fields)
        {
            if (fields != null)
            {
                AttributedCharacterIterator iterator = format
                                                       .FormatToCharacterIterator(arg);
                while (iterator.GetIndex() != iterator.GetEndIndex())
                {
                    int start_0 = iterator.GetRunStart();
                    int end_1   = iterator.GetRunLimit();

                    IIterator <ILOG.J2CsMapping.Text.AttributedCharacterIterator_Constants.Attribute> it = new ILOG.J2CsMapping.Collections.Generics.IteratorAdapter <ILOG.J2CsMapping.Text.AttributedCharacterIterator_Constants.Attribute>(new ILOG.J2CsMapping.Collections.Generics.ListSet <ILOG.J2CsMapping.Text.AttributedCharacterIterator_Constants.Attribute>(iterator.GetAttributes().Keys).GetEnumerator());
                    while (it.HasNext())
                    {
                        AttributedCharacterIterator_Constants.Attribute attribute_2 = (AttributedCharacterIterator_Constants.Attribute)it
                                                                                      .Next();
                        Object value_ren = iterator.GetAttribute(attribute_2);
                        fields.Add(new MessageFormat.FieldContainer(begin + start_0, begin + end_1,
                                                                    attribute_2, value_ren));
                    }
                    iterator.SetIndex(end_1);
                }
            }
        }
Ejemplo n.º 3
0
        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());
        }
Ejemplo n.º 4
0
        public AttributedString(AttributedCharacterIterator iterator)
        {
            if (iterator.GetBeginIndex() > iterator.GetEndIndex())
            {
                // text.0A=Invalid substring range
                throw new ArgumentException("text.0A"); //$NON-NLS-1$
            }
            StringBuilder buffer = new StringBuilder();

            for (int i = iterator.GetBeginIndex(); i < iterator.GetEndIndex(); i++)
            {
                buffer.Append(iterator.Current());
                iterator.Next();
            }
            text = buffer.ToString();
            ILOG.J2CsMapping.Collections.Generics.ISet <AttributedCharacterIterator_Constants.Attribute> attributes = iterator
                                                                                                                      .GetAllAttributeKeys();
            if (attributes == null)
            {
                return;
            }
            attributeMap = new Dictionary <AttributedCharacterIterator_Constants.Attribute, IList <Range> >(
                (attributes.Count * 4 / 3) + 1);

            IIterator <AttributedCharacterIterator_Constants.Attribute> it = new ILOG.J2CsMapping.Collections.Generics.IteratorAdapter <ILOG.J2CsMapping.Text.AttributedCharacterIterator_Constants.Attribute>(attributes.GetEnumerator());

            while (it.HasNext())
            {
                AttributedCharacterIterator_Constants.Attribute attribute = it.Next();
                iterator.SetIndex(0);
                while (iterator.Current() != ILOG.J2CsMapping.Text.CharacterIterator.Done)
                {
                    int    start_0   = iterator.GetRunStart(attribute);
                    int    limit     = iterator.GetRunLimit(attribute);
                    Object value_ren = iterator.GetAttribute(attribute);
                    if (value_ren != null)
                    {
                        AddAttribute(attribute, value_ren, start_0, limit);
                    }
                    iterator.SetIndex(limit);
                }
            }
        }
Ejemplo n.º 5
0
        private AttributedString(AttributedCharacterIterator iterator, int start_0,
                                 int end_1, ILOG.J2CsMapping.Collections.Generics.ISet <AttributedCharacterIterator_Constants.Attribute> attributes)
        {
            if (start_0 < iterator.GetBeginIndex() || end_1 > iterator.GetEndIndex() ||
                start_0 > end_1)
            {
                throw new ArgumentException();
            }

            if (attributes == null)
            {
                return;
            }

            StringBuilder buffer = new StringBuilder();

            iterator.SetIndex(start_0);
            while (iterator.GetIndex() < end_1)
            {
                buffer.Append(iterator.Current());
                iterator.Next();
            }
            text         = buffer.ToString();
            attributeMap = new Dictionary <AttributedCharacterIterator_Constants.Attribute, IList <Range> >(
                (attributes.Count * 4 / 3) + 1);

            IIterator <AttributedCharacterIterator_Constants.Attribute> it = new ILOG.J2CsMapping.Collections.Generics.IteratorAdapter <ILOG.J2CsMapping.Text.AttributedCharacterIterator_Constants.Attribute>(attributes.GetEnumerator());

            while (it.HasNext())
            {
                AttributedCharacterIterator_Constants.Attribute attribute = it.Next();
                iterator.SetIndex(start_0);
                while (iterator.GetIndex() < end_1)
                {
                    Object value_ren = iterator.GetAttribute(attribute);
                    int    runStart  = iterator.GetRunStart(attribute);
                    int    limit     = iterator.GetRunLimit(attribute);
                    if ((value_ren is ILOG.J2CsMapping.Util.Annotation && runStart >= start_0 && limit <= end_1) ||
                        (value_ren != null && !(value_ren is ILOG.J2CsMapping.Util.Annotation)))
                    {
                        AddAttribute(attribute, value_ren, ((runStart < start_0) ? start_0
                                : runStart) - start_0, ((limit > end_1) ? end_1 : limit)
                                     - start_0);
                    }
                    iterator.SetIndex(limit);
                }
            }
        }
Ejemplo n.º 6
0
        }       //	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);
            }
        }
Ejemplo n.º 7
0
        }       //	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