protected internal virtual TextString convertToCharacters(string text, Graphics2D g, FontFactory fontFactory, ColorFactory colorFactory)
        {
            TextString        characters = new TextString();
            FontRenderContext frc        = g.getFontRenderContext();
            double            lastx      = 0;

            for (int i = 0; i < text.Length; i++)
            {
                Font          font   = fontFactory.getFont(i);
                char          c      = text[i];
                FontMetrics   fm     = g.getFontMetrics(font);
                Rectangle2D   bounds = font.getStringBounds(Convert.ToString(c), frc);
                TextCharacter tc     = new TextCharacter();
                tc.Character = c;
                tc.Font      = font;
                tc.Width     = fm.charWidth(c);
                tc.Height    = fm.getAscent() + fm.getDescent();
                tc.Ascent    = fm.getAscent();
                tc.Descent   = fm.getDescent();
                tc.X         = lastx;
                tc.Y         = 0;
                tc.Font      = font;
                tc.Color     = colorFactory.getColor(i);
                lastx       += bounds.getWidth();
                characters.addCharacter(tc);
            }
            return(characters);
        }
Exemplo n.º 2
0
        private void CachedLabel()
        {
            string v;


            if (_containsProperty)
            {
                v = GUIPropertyManager.Parse(_labelText);
                if (v == null)
                {
                    v = String.Empty;
                }
            }
            else
            {
                v = _labelText;
            }
            if (v != _cachedTextLabel)
            {
                _textwidth       = 0;
                _textheight      = 0;
                _reCalculate     = true;
                _cachedTextLabel = v;
                _context         = null;
            }
        }
Exemplo n.º 3
0
        /// <summary> Returns the logical bounds of the given text.
        ///
        /// </summary>
        /// <param name="text">the text.
        /// </param>
        /// <returns> the logical bounds of the text.
        /// </returns>
        public virtual System.Drawing.RectangleF getTextLogicalBounds(System.String text)
        {
#if PENDING
            //UPGRADE_TODO: Class 'java.awt.font.FontRenderContext' was converted to 'System.Windows.Forms.Control' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073_3"'
            //UPGRADE_ISSUE: Constructor 'java.awt.font.FontRenderContext.FontRenderContext' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaawtfontFontRenderContextFontRenderContext_javaawtgeomAffineTransform_boolean_boolean_3"'
            System.Drawing.Text.TextRenderingHint frc = new FontRenderContext(new System.Drawing.Drawing2D.Matrix(), true, state.usesFractionalFontMetrics);
            //UPGRADE_ISSUE: Class 'java.awt.font.GlyphVector' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaawtfontGlyphVector_3"'
            //UPGRADE_TODO: Method 'java.awt.Font.createGlyphVector' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1095_3"'
            GlyphVector gv = state.font.createGlyphVector(frc, text);

            //UPGRADE_ISSUE: Method 'java.awt.font.GlyphVector.getLogicalBounds' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaawtfontGlyphVector_3"'
            return(gv.getLogicalBounds());
#endif
            return(new System.Drawing.RectangleF()); //TODO PENDING
        }
Exemplo n.º 4
0
        /// <summary> Draws the given text using the current font, Fill color and
        /// other settings. The positions of the characters are given
        /// as an array of floats. Each position is given as two
        /// numbers the x-position and y-position.
        ///
        /// </summary>
        /// <param name="text">the text to be drawn.
        /// </param>
        /// <param name="positions">the positions of the characters.
        /// </param>
        public virtual void drawText(System.String text, float[] positions)
        {
#if PENDING
            //UPGRADE_TODO: Class 'java.awt.font.FontRenderContext' was converted to 'System.Windows.Forms.Control' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073_3"'
            //UPGRADE_ISSUE: Constructor 'java.awt.font.FontRenderContext.FontRenderContext' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaawtfontFontRenderContextFontRenderContext_javaawtgeomAffineTransform_boolean_boolean_3"'
            System.Drawing.Text.TextRenderingHint frc = new FontRenderContext(new System.Drawing.Drawing2D.Matrix(), true, true);
            //UPGRADE_ISSUE: Class 'java.awt.font.GlyphVector' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaawtfontGlyphVector_3"'
            //UPGRADE_TODO: Method 'java.awt.Font.createGlyphVector' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1095_3"'
            GlyphVector gv = state.font.createGlyphVector(frc, text);

            //UPGRADE_ISSUE: Method 'java.awt.font.GlyphVector.getGlyphCodes' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaawtfontGlyphVector_3"'
            //UPGRADE_ISSUE: Method 'java.awt.font.GlyphVector.getNumGlyphs' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaawtfontGlyphVector_3"'
            drawGlyphs(gv.getGlyphCodes(0, gv.getNumGlyphs(), null), positions);
#endif
        }
Exemplo n.º 5
0
        internal override System.Drawing.Rectangle getBounds(DrawContext context, System.Drawing.Drawing2D.Matrix transform)
        {
#if PENDING
            System.Drawing.Rectangle r = System.Drawing.Rectangle.Empty;

            //UPGRADE_TODO: Class 'java.awt.font.FontRenderContext' was converted to 'System.Windows.Forms.Control' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073_3"'
            //UPGRADE_ISSUE: Constructor 'java.awt.font.FontRenderContext.FontRenderContext' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaawtfontFontRenderContextFontRenderContext_javaawtgeomAffineTransform_boolean_boolean_3"'
            System.Drawing.Text.TextRenderingHint frc = new FontRenderContext(transform, false, true);
            for (int i = 0; i < glyphCodes.Length; i++)
            {
                //UPGRADE_ISSUE: Class 'java.awt.font.GlyphVector' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaawtfontGlyphVector_3"'
                //UPGRADE_TODO: Method 'java.awt.Font.createGlyphVector' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1095_3"'
                GlyphVector gv = font.createGlyphVector(frc, new int[] { glyphCodes[i] });
                System.Drawing.Rectangle gr = gv.getPixelBounds(frc, positions[i * 2], positions[i * 2 + 1]);

                if (r.IsEmpty)
                {
                    r = gr;
                }
                else
                {
                    r = System.Drawing.Rectangle.Union(r, gr);
                }
            }
            if (r.IsEmpty)
            {
                return(new System.Drawing.Rectangle());
            }

            Filter filter = context.AAFilter;

            // Compensate for the antialiasing filter
            if (filter != null)
            {
                //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1042_3"'
                //UPGRADE_NOTE: ref keyword was added to struct-type parameters. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1303_3"'
                r = addMargin(ref r, (int)System.Math.Ceiling(filter.Width), (int)System.Math.Ceiling(filter.Height));
            }
            return(r);
#endif
            return(new System.Drawing.Rectangle());
        }
Exemplo n.º 6
0
    public TextElement[] GetTextElements(float textWidth, FontRenderContext frc){
        TextRun run = _shape.GetTextRun();
        if (run == null) return null;

        String text = Run.GetText();
        if (text == null || text.Equals("")) return null;

        AttributedString at = GetAttributedString(Run);

        AttributedCharacterIterator it = at.GetIterator();
        int paragraphStart = it.GetBeginIndex();
        int paragraphEnd = it.GetEndIndex();

        List<TextElement> lines = new List<TextElement>();
        LineBreakMeasurer measurer = new LineBreakMeasurer(it, frc);
        measurer.SetPosition(paragraphStart);
        while (measurer.GetPosition() < paragraphEnd) {
            int startIndex = measurer.GetPosition();
            int nextBreak = text.IndexOf('\n', measurer.GetPosition() + 1);

            bool prStart = text[startIndex] == '\n';
            if(prStart) measurer.SetPosition(startIndex++);

            RichTextRun rt = Run.GetRichTextRunAt(startIndex == text.Length ? (startIndex-1) : startIndex);
            if(rt == null) {
                logger.log(POILogger.WARN,  "RichTextRun not found at pos" + startIndex + "; text.Length: " + text.Length);
                break;
            }

            float wrappingWidth = textWidth - _shape.GetMarginLeft() - _shape.GetMarginRight();
            int bulletOffset = rt.GetBulletOffset();
            int textOffset = rt.GetTextOffset();
            int indent = rt.GetIndentLevel();

            TextRulerAtom ruler = Run.GetTextRuler();
            if(ruler != null) {
                int bullet_val = ruler.GetBulletOffsets()[indent]*Shape.POINT_DPI/Shape.MASTER_DPI;
                int text_val = ruler.GetTextOffsets()[indent]*Shape.POINT_DPI/Shape.MASTER_DPI;
                if(bullet_val > text_val){
                    int a = bullet_val;
                    bullet_val = text_val;
                    text_val = a;
                }
                if(bullet_val != 0 ) bulletOffset = bullet_val;
                if(text_val != 0) textOffset = text_val;
            }

            if(bulletOffset > 0 || prStart || startIndex == 0) wrappingWidth -= textOffset;

            if (_shape.GetWordWrap() == TextShape.WrapNone) {
                wrappingWidth = _shape.Sheet.GetSlideShow().GetPageSize().width;
            }

            TextLayout textLayout = measurer.nextLayout(wrappingWidth + 1,
                    nextBreak == -1 ? paragraphEnd : nextBreak, true);
            if (textLayout == null) {
                textLayout = measurer.nextLayout(textWidth,
                    nextBreak == -1 ? paragraphEnd : nextBreak, false);
            }
            if(textLayout == null){
                logger.log(POILogger.WARN, "Failed to break text into lines: wrappingWidth: "+wrappingWidth+
                        "; text: " + rt.GetText());
                measurer.SetPosition(rt.GetEndIndex());
                continue;
            }
            int endIndex = measurer.GetPosition();

            float lineHeight = (float)textLayout.GetBounds().Height;
            int linespacing = rt.GetLineSpacing();
            if(linespacing == 0) linespacing = 100;

            TextElement el = new TextElement();
            if(linespacing >= 0){
                el.ascent = textLayout.GetAscent()*linespacing/100;
            } else {
                el.ascent = -linespacing*Shape.POINT_DPI/Shape.MASTER_DPI;
            }

            el._align = rt.GetAlignment();
            el.advance = textLayout.GetAdvance();
            el._textOffset = textOffset;
            el._text = new AttributedString(it, startIndex, endIndex);
            el.textStartIndex = startIndex;
            el.textEndIndex = endIndex;

            if (prStart){
                int sp = rt.GetSpaceBefore();
                float spaceBefore;
                if(sp >= 0){
                    spaceBefore = lineHeight * sp/100;
                } else {
                    spaceBefore = -sp*Shape.POINT_DPI/Shape.MASTER_DPI;
                }
                el.ascent += spaceBefore;
            }

            float descent;
            if(linespacing >= 0){
                descent = (textLayout.GetDescent() + textLayout.GetLeading())*linespacing/100;
            } else {
                descent = -linespacing*Shape.POINT_DPI/Shape.MASTER_DPI;
            }
            if (prStart){
                int sp = rt.GetSpaceAfter();
                float spaceAfter;
                if(sp >= 0){
                    spaceAfter = lineHeight * sp/100;
                } else {
                    spaceAfter = -sp*Shape.POINT_DPI/Shape.MASTER_DPI;
                }
                el.ascent += spaceAfter;
            }
            el.descent = descent;

            if(rt.IsBullet() && (prStart || startIndex == 0)){
                it.SetIndex(startIndex);

                AttributedString bat = new AttributedString(Character.ToString(rt.GetBulletChar()));
                Color clr = rt.GetBulletColor();
                if (clr != null) bat.AddAttribute(TextAttribute.FOREGROUND, clr);
                else bat.AddAttribute(TextAttribute.FOREGROUND, it.GetAttribute(TextAttribute.FOREGROUND));

                int fontIdx = rt.GetBulletFont();
                if(fontIdx == -1) fontIdx = rt.GetFontIndex();
                PPFont bulletFont = _shape.Sheet.GetSlideShow().GetFont(fontIdx);
                bat.AddAttribute(TextAttribute.FAMILY, bulletFont.GetFontName());

                int bulletSize = rt.GetBulletSize();
                int fontSize = rt.GetFontSize();
                if(bulletSize != -1) fontSize = Math.round(fontSize*bulletSize*0.01f);
                bat.AddAttribute(TextAttribute.SIZE, new Float(fontSize));

                if(!new Font(bulletFont.GetFontName(), Font.PLAIN, 1).canDisplay(rt.GetBulletChar())){
                    bat.AddAttribute(TextAttribute.FAMILY, "Arial");
                    bat = new AttributedString("" + DEFAULT_BULLET_CHAR, bat.GetIterator().GetAttributes());
                }

                if(text.Substring(startIndex, endIndex).Length > 1){
                    el._bullet = bat;
                    el._bulletOffset = bulletOffset;
                }
            }
            lines.Add(el);
        }

        //finally Draw the text fragments
        TextElement[] elems = new TextElement[lines.Count];
        return lines.ToArray(elems);
    }
Exemplo n.º 7
0
        internal override System.Drawing.Rectangle getBounds(DrawContext context, System.Drawing.Drawing2D.Matrix transform)
        {
            #if PENDING
            System.Drawing.Rectangle r = System.Drawing.Rectangle.Empty;

            //UPGRADE_TODO: Class 'java.awt.font.FontRenderContext' was converted to 'System.Windows.Forms.Control' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073_3"'
            //UPGRADE_ISSUE: Constructor 'java.awt.font.FontRenderContext.FontRenderContext' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaawtfontFontRenderContextFontRenderContext_javaawtgeomAffineTransform_boolean_boolean_3"'
            System.Drawing.Text.TextRenderingHint frc = new FontRenderContext(transform, false, true);
            for (int i = 0; i < glyphCodes.Length; i++)
            {

                //UPGRADE_ISSUE: Class 'java.awt.font.GlyphVector' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaawtfontGlyphVector_3"'
                //UPGRADE_TODO: Method 'java.awt.Font.createGlyphVector' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1095_3"'
                GlyphVector gv = font.createGlyphVector(frc, new int[] { glyphCodes[i] });
                System.Drawing.Rectangle gr = gv.getPixelBounds(frc, positions[i * 2], positions[i * 2 + 1]);

                if (r.IsEmpty)
                    r = gr;
                else
                    r = System.Drawing.Rectangle.Union(r, gr);
            }
            if (r.IsEmpty)
                return new System.Drawing.Rectangle();

            Filter filter = context.AAFilter;

            // Compensate for the antialiasing filter
            if (filter != null)
            {
                //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1042_3"'
                //UPGRADE_NOTE: ref keyword was added to struct-type parameters. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1303_3"'
                r = addMargin(ref r, (int)System.Math.Ceiling(filter.Width), (int)System.Math.Ceiling(filter.Height));
            }
            return r;
            #endif
            return new System.Drawing.Rectangle();
        }