Ejemplo n.º 1
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.º 2
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);
            }
        }