Package org.apache.flex.forks.batik.gvt.font

Examples of org.apache.flex.forks.batik.gvt.font.GVTFont


            boolean[] fontAssigned = new boolean[aciLength];

            if (as == null)
                as = new AttributedString(aci);

            GVTFont defaultFont = null;
            int numSet=0;
            int firstUnset=start;
            boolean firstUnsetSet;
            for (int i = 0; i < resolvedFontFamilies.size(); i++) {
                // assign this font to all characters it can display if it has
                // not already been assigned
                int currentIndex = firstUnset;
                firstUnsetSet = false;
                aci.setIndex(currentIndex);

                GVTFontFamily ff;
                ff = ((GVTFontFamily)resolvedFontFamilies.get(i));
                GVTFont font = ff.deriveFont(fontSize, aci);
                if (defaultFont == null)
                    defaultFont = font;

                while (currentIndex < end) {
                    int displayUpToIndex = font.canDisplayUpTo
                        (aci, currentIndex, end);

                    Object altGlyphElement = aci.getAttributes().get(ALT_GLYPH_HANDLER);
                    if ( altGlyphElement != null ){
                        //found all the glyph to be displayed
                        //consider the font matching done
                        displayUpToIndex = -1;
                    }

                    if (displayUpToIndex == -1) {
                        // Can handle the whole thing...
                        displayUpToIndex = end;
                    }

                    if (displayUpToIndex <= currentIndex) {
                        if (!firstUnsetSet) {
                            firstUnset = currentIndex;
                            firstUnsetSet = true;
                        }
                        // couldn't display the current char
                        currentIndex++;
                    } else {
                        // could display some text, so for each
                        // char it can display, if char not already
                        // assigned a font, assign this font to it
                        int runStart = -1;
                        for (int j = currentIndex; j < displayUpToIndex; j++) {
                            if (fontAssigned[j - start]) {
                                if (runStart != -1) {
            // System.out.println("Font 1: " + font);
                                    as.addAttribute(GVT_FONT, font,
                                                    runStart-begin, j-begin);
                                    runStart=-1;
                                }
                            } else {
                                if (runStart == -1)
                                    runStart = j;
                            }
                            fontAssigned[j - start] = true;
                            numSet++;
                        }
                        if (runStart != -1) {
          // System.out.println("Font 2: " + font);
                            as.addAttribute(GVT_FONT, font,
                                            runStart-begin,
                                            displayUpToIndex-begin);
                        }

                        // set currentIndex to be one after the char
                        // that couldn't display
                        currentIndex = displayUpToIndex+1;
                    }
                }

                if (numSet == aciLength) // all chars have font set;
                    break;
            }

            // assign the first font to any chars haven't alreay been assigned
            int           runStart = -1;
            GVTFontFamily prevFF   = null;
            GVTFont       prevF    = defaultFont;
            for (int i = 0; i < aciLength; i++) {
                if (fontAssigned[i]) {
                    if (runStart != -1) {
      // System.out.println("Font 3: " + prevF);
                        as.addAttribute(GVT_FONT, prevF,
View Full Code Here


        aciIdx = aci.getBeginIndex();
        int aciEnd = aci.getEndIndex();
        char ch = aci.setIndex(aciIdx);
       
        int aciWordStart = aciIdx;
        GVTFont gvtFont = (GVTFont)aci.getAttribute(GVT_FONT);
        float lineHeight = ((Float)aci.getAttribute(LINE_HEIGHT)).floatValue();
        int runLimit = aci.getRunLimit(szAtts);
        WordInfo prevWI = null;
        float   [] lastAdvAdj = new float  [numGlyphs];
        float   [] advAdj     = new float  [numGlyphs];
        boolean [] hideLast   = new boolean[numGlyphs];
        boolean [] hide       = new boolean[numGlyphs];
        boolean [] space      = new boolean[numGlyphs];
        float   [] glyphPos = gv.getGlyphPositions(0, numGlyphs+1, null);
        for (int i=0; i<numGlyphs; i++) {
            char pch = ch;
            ch = aci.setIndex(aciIdx);
            Integer integer = (Integer)aci.getAttribute(WORD_LIMIT);
            WordInfo theWI = cWordMap[integer.intValue()-numWords];
            if (theWI.getFlowLine() == null)
                theWI.setFlowLine(aci.getAttribute(FLOW_LINE_BREAK));

            if (prevWI == null) {
                prevWI = theWI;
            } else if (prevWI != theWI) {
                GVTLineMetrics lm = gvtFont.getLineMetrics
                    (aci, aciWordStart, aciIdx, frc);
                prevWI.addLineMetrics(gvtFont, lm);
                prevWI.addLineHeight(lineHeight);
                aciWordStart = aciIdx;
                prevWI = theWI;
            }

            int chCnt = gv.getCharacterCount(i,i);
            if (chCnt == 1) {
                char nch;
                float kern;
                switch(ch) {
                case SOFT_HYPHEN:
                    hideLast[i] = true;
                    nch = aci.next(); aci.previous();
                    kern = gvtFont.getHKern(pch, nch);
                    advAdj[i] = -(glyphPos[2*i+2]-glyphPos[2*i]+kern);
                    break;
                case ZERO_WIDTH_JOINER:
                    hide[i] = true;
                    break;
                case ZERO_WIDTH_SPACE:
                    hide[i] = true;
                    break;
                case SPACE:
                    space[i] = true;
                    nch = aci.next(); aci.previous();
                    kern = gvtFont.getHKern(pch, nch);
                    lastAdvAdj[i] = -(glyphPos[2*i+2]-glyphPos[2*i]+kern);
                default:
                }
            }

            aciIdx += chCnt;
            if ((aciIdx > runLimit) && (aciIdx < aciEnd)) {
                // Possible font size/style change so record current
                // line metrics and start fresh.
                GVTLineMetrics lm = gvtFont.getLineMetrics
                    (aci,aciWordStart, runLimit, frc);
                prevWI.addLineMetrics(gvtFont, lm);
                prevWI.addLineHeight(lineHeight);
                prevWI = null;
                aciWordStart = aciIdx;
                aci.setIndex(aciIdx);
                gvtFont = (GVTFont)aci.getAttribute(GVT_FONT);
                Float f = (Float)aci.getAttribute(LINE_HEIGHT);
                lineHeight = f.floatValue();
                runLimit = aci.getRunLimit(szAtts);
            }
        }
        GVTLineMetrics lm = gvtFont.getLineMetrics
            (aci,aciWordStart, runLimit, frc);
        prevWI.addLineMetrics(gvtFont, lm);
        prevWI.addLineHeight(lineHeight);

        int [] wordGlyphCounts = new int[words];
View Full Code Here

     *
     * @return The GVTFont to use.
     */
    protected GVTFont getFont() {
        aci.first();
        GVTFont gvtFont = (GVTFont)aci.getAttributes().get(GVT_FONT);

        if (gvtFont != null)
            return gvtFont;

        // shouldn't get here
View Full Code Here

        Point2D lastCharAdvance
            = new Point2D.Double(advance.getX() - (gv.getGlyphPosition(numGlyphs-1).getX() - x),
                                 advance.getY() - (gv.getGlyphPosition(numGlyphs-1).getY() - y));

        try {
            GVTFont font = gv.getFont();
            // do letter spacing first
            if ((numGlyphs > 1) && (doLetterSpacing || !autoKern)) {
                for (int i=1; i<=numGlyphs; ++i) {
                    Point2D gpos = gv.getGlyphPosition(i);
                    int     currCode;
                    currCode = (i == numGlyphs)?-1:gv.getGlyphCode(i);
                    dx = (float)gpos.getX()-(float)prevPos.getX();
                    dy = (float)gpos.getY()-(float)prevPos.getY();
                    if (autoKern) {
                        if (vertical) dy += letterSpacingVal;
                        else          dx += letterSpacingVal;
                    } else {
                        // apply explicit kerning adjustments,
                        // removing any auto-kern values
                        if (vertical) {
                            float vKern = 0;
                            if (currCode != -1)
                                vKern = font.getVKern(prevCode, currCode);
                            dy += kernVal - vKern + letterSpacingVal;
                        } else {
                            float hKern = 0;
                            if (currCode != -1)
                                hKern = font.getHKern(prevCode, currCode);
                            dx += kernVal - hKern + letterSpacingVal;
                        }
                    }
                    x += dx;
                    y += dy;
View Full Code Here

                    ((UnresolvedFontFamily)fontFamily);
            }
            if (fontFamily == null) continue;
           
           
            GVTFont font = fontFamily.deriveFont(fontSize, fontAttrs);
            GVTLineMetrics lm = font.getLineMetrics("", frc);
            this.ascent = lm.getAscent();
            this.descent = lm.getDescent();
            break;
        }
        if (ascent == -1) {
View Full Code Here

        if (fsFloat != null)
            fontSize = fsFloat.floatValue();

        Iterator i = fontList.iterator();
        while (i.hasNext()) {
            GVTFont font = (GVTFont)i.next();
            GVTLineMetrics lm = font.getLineMetrics("", frc);
            this.ascent = lm.getAscent();
            this.descent = lm.getDescent();
            break;
        }
        if (ascent == -1) {
View Full Code Here

        aciIdx = aci.getBeginIndex();
        int aciEnd = aci.getEndIndex();
        char ch = aci.setIndex(aciIdx);

        int aciWordStart = aciIdx;
        GVTFont gvtFont = (GVTFont)aci.getAttribute(GVT_FONT);
        float lineHeight = 1.0f;
        Float lineHeightFloat = (Float)aci.getAttribute(LINE_HEIGHT);
        if (lineHeightFloat != null)
            lineHeight = lineHeightFloat.floatValue();
        int runLimit = aci.getRunLimit(szAtts);
        WordInfo prevWI = null;
        float   [] lastAdvAdj = new float  [numGlyphs];
        float   [] advAdj     = new float  [numGlyphs];
        boolean [] hideLast   = new boolean[numGlyphs];
        boolean [] hide       = new boolean[numGlyphs];
        boolean [] space      = new boolean[numGlyphs];
        float   [] glyphPos = gv.getGlyphPositions(0, numGlyphs+1, null);
        for (int i=0; i<numGlyphs; i++) {
            char pch = ch;
            ch = aci.setIndex(aciIdx);
            Integer integer = (Integer)aci.getAttribute(WORD_LIMIT);
            WordInfo theWI = cWordMap[integer.intValue()-numWords];
            if (theWI.getFlowLine() == null)
                theWI.setFlowLine(aci.getAttribute(FLOW_LINE_BREAK));

            if (prevWI == null) {
                prevWI = theWI;
            } else if (prevWI != theWI) {
                GVTLineMetrics lm = gvtFont.getLineMetrics
                    (aci, aciWordStart, aciIdx, frc);
                prevWI.addLineMetrics(gvtFont, lm);
                prevWI.addLineHeight(lineHeight);
                aciWordStart = aciIdx;
                prevWI = theWI;
            }

            int chCnt = gv.getCharacterCount(i,i);
            if (chCnt == 1) {
                char nch;
                float kern;
                switch(ch) {
                case SOFT_HYPHEN:
                    hideLast[i] = true;
                    nch = aci.next(); aci.previous();
                    kern = gvtFont.getHKern(pch, nch);
                    advAdj[i] = -(glyphPos[2*i+2]-glyphPos[2*i]+kern);
                    break;
                case ZERO_WIDTH_JOINER:
                    hide[i] = true;
                    break;
                case ZERO_WIDTH_SPACE:
                    hide[i] = true;
                    break;
                case SPACE:
                    space[i] = true;
                    nch = aci.next(); aci.previous();
                    kern = gvtFont.getHKern(pch, nch);
                    lastAdvAdj[i] = -(glyphPos[2*i+2]-glyphPos[2*i]+kern);
                default:
                }
            }

            aciIdx += chCnt;
            if ((aciIdx > runLimit) && (aciIdx < aciEnd)) {
                // Possible font size/style change so record current
                // line metrics and start fresh.
                GVTLineMetrics lm = gvtFont.getLineMetrics
                    (aci,aciWordStart, runLimit, frc);
                prevWI.addLineMetrics(gvtFont, lm);
                prevWI.addLineHeight(lineHeight);
                prevWI = null;
                aciWordStart = aciIdx;
                aci.setIndex(aciIdx);
                gvtFont = (GVTFont)aci.getAttribute(GVT_FONT);
                Float f = (Float)aci.getAttribute(LINE_HEIGHT);
                lineHeight = f.floatValue();
                runLimit = aci.getRunLimit(szAtts);
            }
        }
        GVTLineMetrics lm = gvtFont.getLineMetrics
            (aci,aciWordStart, runLimit, frc);
        prevWI.addLineMetrics(gvtFont, lm);
        prevWI.addLineHeight(lineHeight);

        int [] wordGlyphCounts = new int[words];
View Full Code Here

     *
     * @return The GVTFont to use.
     */
    protected GVTFont getFont() {
        aci.first();
        GVTFont gvtFont = (GVTFont)aci.getAttribute(GVT_FONT);

        if (gvtFont != null)
            return gvtFont;

        // shouldn't get here
View Full Code Here

        Point2D lastCharAdvance
            = new Point2D.Double(advance.getX() - (gv.getGlyphPosition(numGlyphs-1).getX() - x),
                                 advance.getY() - (gv.getGlyphPosition(numGlyphs-1).getY() - y));

        try {
            GVTFont font = gv.getFont();
            // do letter spacing first
            if ((numGlyphs > 1) && (doLetterSpacing || !autoKern)) {
                for (int i=1; i<=numGlyphs; ++i) {
                    Point2D gpos = gv.getGlyphPosition(i);
                    int     currCode;
                    currCode = (i == numGlyphs)?-1:gv.getGlyphCode(i);
                    dx = (float)gpos.getX()-(float)prevPos.getX();
                    dy = (float)gpos.getY()-(float)prevPos.getY();
                    if (autoKern) {
                        if (vertical) dy += letterSpacingVal;
                        else          dx += letterSpacingVal;
                    } else {
                        // apply explicit kerning adjustments,
                        // removing any auto-kern values
                        if (vertical) {
                            float vKern = 0;
                            if (currCode != -1)
                                vKern = font.getVKern(prevCode, currCode);
                            dy += kernVal - vKern + letterSpacingVal;
                        } else {
                            float hKern = 0;
                            if (currCode != -1)
                                hKern = font.getHKern(prevCode, currCode);
                            dx += kernVal - hKern + letterSpacingVal;
                        }
                    }
                    x += dx;
                    y += dy;
View Full Code Here

            boolean[] fontAssigned = new boolean[aciLength];

            if (as == null)
                as = new AttributedString(aci);

            GVTFont defaultFont = null;
            int numSet=0;
            int firstUnset=start;
            boolean firstUnsetSet;
            for (int i = 0; i < fonts.size(); i++) {
                // assign this font to all characters it can display if it has
                // not already been assigned
                int currentIndex = firstUnset;
                firstUnsetSet = false;
                aci.setIndex(currentIndex);

                GVTFont font = (GVTFont)fonts.get(i);
                if (defaultFont == null)
                    defaultFont = font;

                while (currentIndex < end) {
                    int displayUpToIndex = font.canDisplayUpTo
                        (aci, currentIndex, end);

                    Object altGlyphElement;
                    altGlyphElement = aci.getAttribute(ALT_GLYPH_HANDLER);
                    if ( altGlyphElement != null ){
                        //found all the glyph to be displayed
                        //consider the font matching done
                        displayUpToIndex = -1;
                    }

                    if (displayUpToIndex == -1) {
                        // Can handle the whole thing...
                        displayUpToIndex = end;
                    }

                    if (displayUpToIndex <= currentIndex) {
                        if (!firstUnsetSet) {
                            firstUnset = currentIndex;
                            firstUnsetSet = true;
                        }
                        // couldn't display the current char
                        currentIndex++;
                    } else {
                        // could display some text, so for each
                        // char it can display, if char not already
                        // assigned a font, assign this font to it
                        int runStart = -1;
                        for (int j = currentIndex; j < displayUpToIndex; j++) {
                            if (fontAssigned[j - start]) {
                                if (runStart != -1) {
                                    // System.out.println("Font 1: " + font);
                                    as.addAttribute(GVT_FONT, font,
                                                    runStart-begin, j-begin);
                                    runStart=-1;
                                }
                            } else {
                                if (runStart == -1)
                                    runStart = j;
                            }
                            fontAssigned[j - start] = true;
                            numSet++;
                        }
                        if (runStart != -1) {
                            // System.out.println("Font 2: " + font);
                            as.addAttribute(GVT_FONT, font,
                                            runStart-begin,
                                            displayUpToIndex-begin);
                        }

                        // set currentIndex to be one after the char
                        // that couldn't display
                        currentIndex = displayUpToIndex+1;
                    }
                }

                if (numSet == aciLength) // all chars have font set;
                    break;
            }

            // assign the first font to any chars haven't alreay been assigned
            int           runStart = -1;
            GVTFontFamily prevFF   = null;
            GVTFont       prevF    = defaultFont;
            for (int i = 0; i < aciLength; i++) {
                if (fontAssigned[i]) {
                    if (runStart != -1) {
                        // System.out.println("Font 3: " + prevF);
                        as.addAttribute(GVT_FONT, prevF,
View Full Code Here

TOP

Related Classes of org.apache.flex.forks.batik.gvt.font.GVTFont

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.