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);
}
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);
}
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;
}
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));
}
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();
}
Aggregations