use of org.xhtmlrenderer.css.parser.PropertyValue in project servoy-client by Servoy.
the class ImageLoader method paintBackgroundImage.
private static void paintBackgroundImage(Graphics graphics, IStyleRule styleRule, IApplication application, String url, Dimension parentSize) {
int start = url.indexOf(MediaURLStreamHandler.MEDIA_URL_DEF);
if (start != -1) {
String name = url.substring(start + MediaURLStreamHandler.MEDIA_URL_DEF.length());
if (name.endsWith("')") || name.endsWith("\")"))
name = name.substring(0, name.length() - 2);
if (name.endsWith(")"))
name = name.substring(0, name.length() - 1);
Media media = application.getFlattenedSolution().getMedia(name);
if (media != null) {
byte[] imageData = media.getMediaData();
if (styleRule.hasAttribute(CSSName.BACKGROUND_SIZE.toString())) {
PropertyDeclaration declaration = ((ServoyStyleRule) styleRule).getPropertyDeclaration(CSSName.BACKGROUND_SIZE.toString());
if (declaration.getValue() instanceof PropertyValue && ((PropertyValue) declaration.getValue()).getValues() != null && ((PropertyValue) declaration.getValue()).getValues().size() == 2) {
boolean autoWidth = "auto".equals(((CSSPrimitiveValue) ((PropertyValue) declaration.getValue()).getValues().get(0)).getCssText());
boolean autoHeight = "auto".equals(((CSSPrimitiveValue) ((PropertyValue) declaration.getValue()).getValues().get(1)).getCssText());
Boolean fixedWidth = null;
if (autoWidth && !autoHeight) {
fixedWidth = Boolean.FALSE;
} else if (autoHeight && !autoWidth) {
fixedWidth = Boolean.TRUE;
}
int width = getImageSize(parentSize.width, ((CSSPrimitiveValue) ((PropertyValue) declaration.getValue()).getValues().get(0)).getCssText());
int height = getImageSize(parentSize.height, ((CSSPrimitiveValue) ((PropertyValue) declaration.getValue()).getValues().get(1)).getCssText());
imageData = resize(imageData, width, height, autoWidth || autoHeight, fixedWidth);
}
}
Image image = ImageLoader.getBufferedImage(imageData, -1, -1, false);
int offsetWidth = 0;
int offsetHeight = 0;
int imageWidth = image.getWidth(null);
int imageHeight = image.getHeight(null);
if (styleRule.hasAttribute(CSSName.BACKGROUND_POSITION.toString())) {
PropertyDeclaration declaration = ((ServoyStyleRule) styleRule).getPropertyDeclaration(CSSName.BACKGROUND_POSITION.toString());
if (declaration.getValue() instanceof PropertyValue && ((PropertyValue) declaration.getValue()).getValues() != null && ((PropertyValue) declaration.getValue()).getValues().size() == 2) {
offsetWidth = getImagePosition(parentSize.width, imageWidth, ((CSSPrimitiveValue) ((PropertyValue) declaration.getValue()).getValues().get(0)).getCssText());
offsetHeight = getImagePosition(parentSize.height, imageHeight, ((CSSPrimitiveValue) ((PropertyValue) declaration.getValue()).getValues().get(1)).getCssText());
}
}
boolean hRepeat = true;
boolean vRepeat = true;
if (styleRule.hasAttribute(CSSName.BACKGROUND_REPEAT.toString())) {
String repeat = styleRule.getValue(CSSName.BACKGROUND_REPEAT.toString());
hRepeat = false;
vRepeat = false;
if ("repeat".equals(repeat) || "repeat-x".equals(repeat))
hRepeat = true;
if ("repeat".equals(repeat) || "repeat-y".equals(repeat))
vRepeat = true;
}
if (hRepeat) {
offsetWidth = adjustRepeatCoordinate(offsetWidth, imageWidth);
}
if (vRepeat) {
offsetHeight = adjustRepeatCoordinate(offsetHeight, imageHeight);
}
if (!hRepeat && !vRepeat) {
graphics.drawImage(image, offsetWidth, offsetHeight, null);
} else if (hRepeat && vRepeat) {
for (int x = offsetWidth; x < parentSize.width; x += imageWidth) {
for (int y = offsetHeight; y < parentSize.height; y += imageHeight) {
graphics.drawImage(image, x, y, null);
}
}
} else if (hRepeat) {
for (int x = offsetWidth; x < parentSize.width; x += imageWidth) {
graphics.drawImage(image, x, offsetHeight, null);
}
} else if (vRepeat) {
for (int y = offsetHeight; y < parentSize.height; y += imageHeight) {
graphics.drawImage(image, offsetWidth, y, null);
}
}
}
}
}
use of org.xhtmlrenderer.css.parser.PropertyValue in project servoy-client by Servoy.
the class ServoyStyleSheet method getFont.
public Font getFont(IStyleRule a) {
if (hasFont(a)) {
// $NON-NLS-1$
String family = "SansSerif";
int size = 12;
int style = Font.PLAIN;
ServoyStyleRule rule = (ServoyStyleRule) a;
if (a.hasAttribute(CSSName.FONT_FAMILY.toString())) {
PropertyDeclaration declaration = rule.getPropertyDeclaration(CSSName.FONT_FAMILY.toString());
if (declaration != null) {
family = ((PropertyValue) declaration.getValue()).getStringArrayValue()[0];
}
}
if (a.hasAttribute(CSSName.FONT_WEIGHT.toString())) {
PropertyDeclaration declaration = rule.getPropertyDeclaration(CSSName.FONT_WEIGHT.toString());
if (declaration != null) {
if (// $NON-NLS-1$
declaration.getValue().getCssText().contains("bold") || Utils.getAsFloat(declaration.getValue().getCssText()) > 400) {
style |= Font.BOLD;
}
}
}
if (a.hasAttribute(CSSName.FONT_STYLE.toString())) {
PropertyDeclaration declaration = rule.getPropertyDeclaration(CSSName.FONT_STYLE.toString());
if (declaration != null) {
if (// $NON-NLS-1$
declaration.getValue().getCssText().contains("italic")) {
style |= Font.ITALIC;
}
}
}
if (a.hasAttribute(CSSName.FONT_SIZE.toString())) {
PropertyDeclaration declaration = rule.getPropertyDeclaration(CSSName.FONT_SIZE.toString());
if (declaration != null) {
float fontSize = ss.getLength(declaration.getValue().getCssText());
if (fontSize > 0) {
if (// $NON-NLS-1$
declaration.getValue().getCssText().endsWith("px")) {
fontSize = 4 * fontSize / 3;
}
size = Math.round(fontSize);
}
}
}
return PersistHelper.createFont(family, style, size);
}
return null;
}
Aggregations