Search in sources :

Example 1 with FontKey

use of org.loboevolution.laf.FontKey in project LoboEvolution by LoboEvolution.

the class CanvasRenderingImpl method setFont.

/**
 * {@inheritDoc}
 */
@Override
public void setFont(String fontSpec) {
    FontKey key = FontValues.getDefaultFontKey();
    key.setFontStyle(LAFType.ITALIC.getValue());
    key.setFontVariant(CSSValues.SMALL_CAPS.getValue());
    key.setFontWeight(LAFType.BOLD.getValue());
    final String[] tokens = HtmlValues.splitCssValue(fontSpec);
    String token = null;
    final int length = tokens.length;
    int i;
    for (i = 0; i < length; i++) {
        token = tokens[i];
        if (FontValues.isFontStyle(token)) {
            key.setFontStyle(token);
            continue;
        }
        if (FontValues.isFontVariant(token)) {
            key.setFontVariant(token);
            continue;
        }
        if (FontValues.isFontWeight(token)) {
            key.setFontWeight(token);
            continue;
        }
        break;
    }
    if (token != null) {
        final int slashIdx = token.indexOf('/');
        final String fontSizeText = slashIdx == -1 ? token : token.substring(0, slashIdx);
        int errorValue = Float.valueOf(new LAFSettings().getInstance().getFontSize()).intValue();
        HTMLDocumentImpl doc = (HTMLDocumentImpl) this.canvas.getDocumentNode();
        key.setFontSize(HtmlValues.getPixelSize(fontSizeText, null, doc.getDefaultView(), errorValue));
        if (++i < length) {
            final StringBuilder fontFamilyBuff = new StringBuilder();
            do {
                token = tokens[i];
                fontFamilyBuff.append(token);
                fontFamilyBuff.append(' ');
            } while (++i < length);
            key.setFontFamily(fontFamilyBuff.toString());
        }
    }
    this.font = FontFactory.getInstance().getFont(key);
}
Also used : HTMLDocumentImpl(org.loboevolution.html.dom.domimpl.HTMLDocumentImpl) FontKey(org.loboevolution.laf.FontKey) LAFSettings(com.loboevolution.store.laf.LAFSettings) Paint(java.awt.Paint)

Example 2 with FontKey

use of org.loboevolution.laf.FontKey in project LoboEvolution by LoboEvolution.

the class RSSDescriptionElementImpl method draw.

/**
 * {@inheritDoc}
 */
@Override
public void draw(Graphics2D graphics, int y) {
    String text = getText();
    FontKey key = FontValues.getDefaultFontKey();
    key.setFontVariant(CSSValues.SMALL_CAPS.getValue());
    Font font = FontFactory.getInstance().getFont(key);
    graphics.setFont(font);
    graphics.drawString(text, 10, y);
    String firstPart = text;
    while (graphics.getFontMetrics().stringWidth(firstPart) > 600) {
        firstPart = firstPart.substring(0, firstPart.length() - 1);
    }
    String secondPart = text.substring(firstPart.length());
    graphics.drawString(firstPart, 10, y);
    graphics.drawString(secondPart, 10, y + 20);
}
Also used : FontKey(org.loboevolution.laf.FontKey) Font(java.awt.Font)

Example 3 with FontKey

use of org.loboevolution.laf.FontKey in project LoboEvolution by LoboEvolution.

the class StyleSheetRenderState method getFont.

/**
 * {@inheritDoc}
 */
@Override
public Font getFont() {
    AbstractCSSProperties style = this.getCssProperties();
    RenderState prs = this.prevRenderState;
    FontKey key = FontValues.getDefaultFontKey();
    if (this.iFont != null) {
        return this.iFont;
    }
    if (style == null) {
        if (prs != null) {
            this.iFont = prs.getFont();
            return this.iFont;
        }
        this.iFont = FONT_FACTORY.getFont(key);
        return this.iFont;
    }
    Font f = FONT_FACTORY.getFont(FontValues.getFontKey(key, element, style, prs));
    this.iFont = f;
    return f;
}
Also used : FontKey(org.loboevolution.laf.FontKey)

Example 4 with FontKey

use of org.loboevolution.laf.FontKey in project LoboEvolution by LoboEvolution.

the class SmallRenderState method getFont.

@Override
public Font getFont() {
    final AbstractCSSProperties props = element.getCurrentStyle();
    final String fontSize = props == null ? null : props.getFontSize();
    FontKey key = FontValues.getDefaultFontKey();
    final String fSize = Strings.isNotBlank(fontSize) ? fontSize : CSSValues.SMALLER.getValue();
    key.setFontSize(FontValues.getFontSize(fSize, element.getDocumentNode().getDefaultView(), prevRenderState));
    return FontFactory.getInstance().getFont(FontValues.getFontKey(key, element, props, prevRenderState));
}
Also used : FontKey(org.loboevolution.laf.FontKey) AbstractCSSProperties(org.loboevolution.html.style.AbstractCSSProperties)

Example 5 with FontKey

use of org.loboevolution.laf.FontKey in project LoboEvolution by LoboEvolution.

the class TableCellRenderState method getFont.

@Override
public Font getFont() {
    if ("TH".equals(element.getNodeName())) {
        final CSS3Properties props = element.getCurrentStyle();
        final String fontSize = props == null ? null : props.getFontSize();
        final String fSize = Strings.isNotBlank(fontSize) ? fontSize : "1.2rem";
        FontKey key = FontValues.getDefaultFontKey();
        key.setFontWeight(CSSValues.BOLD.getValue());
        key.setFontSize(FontValues.getFontSize(fSize, element.getDocumentNode().getDefaultView(), prevRenderState));
        return FontFactory.getInstance().getFont(FontValues.getFontKey(key, element, props, prevRenderState));
    }
    return super.getFont();
}
Also used : FontKey(org.loboevolution.laf.FontKey) CSS3Properties(org.loboevolution.html.node.css.CSS3Properties)

Aggregations

FontKey (org.loboevolution.laf.FontKey)9 Font (java.awt.Font)2 CSS3Properties (org.loboevolution.html.node.css.CSS3Properties)2 AbstractCSSProperties (org.loboevolution.html.style.AbstractCSSProperties)2 LAFSettings (com.loboevolution.store.laf.LAFSettings)1 Paint (java.awt.Paint)1 HTMLDocumentImpl (org.loboevolution.html.dom.domimpl.HTMLDocumentImpl)1