/** * Tries to convert generic terms to more specific value types. Currently, colors (TermColor) and * rectangles (TermRect) are supported. * @param term the term to be converted * @return the corresponding more specific term type or {@code null} when nothing was found. */ private Term<?> findSpecificType(Term<?> term) { TermColor colorTerm = null; TermRect rectTerm = null; if (term instanceof TermIdent) { //idents - try to convert colors colorTerm = tf.createColor((TermIdent) term); } else if (term instanceof TermFunction) { // rgba(0,0,0) colorTerm = tf.createColor((TermFunction) term); if (colorTerm == null) rectTerm = tf.createRect((TermFunction) term); } //replace with more specific value if (colorTerm != null) { log.debug("term color is OK - creating - " + colorTerm.toString()); return colorTerm; } else if (rectTerm != null) { log.debug("term rect is OK - creating - " + rectTerm.toString()); return rectTerm; } else return null; }
private static TermColor createTermColor(String color) { TermFactory tf = CSSFactory.getTermFactory(); if (color.startsWith("rgba")) { color = color.replaceAll("rgba|\\)|\\(", ""); String[] params = color.split(","); int[] colorValues = new int[params.length]; for (int i = 0; i < params.length; i++) colorValues[i] = Integer.parseInt(params[i]); TermColor termColor = tf.createColor(0, 0, 0); termColor.setValue(new Color(colorValues[0], colorValues[1], colorValues[2], colorValues[3])); return termColor; } else return tf.createColor(color); }
/** * Creates a style definition used for the body element. * @return The body style definition. */ protected NodeData createBodyStyle() { NodeData ret = createBlockStyle(); TermFactory tf = CSSFactory.getTermFactory(); ret.push(createDeclaration("background-color", tf.createColor(255, 255, 255))); return ret; }
funct_args_stack.peek().term = tf.createColor(ctx.HASH().getText()); if (funct_args_stack.peek().term == null) { declaration_stack.peek().invalid = true;
terms_stack.peek().term = tf.createColor(ctx.HASH().getText()); if (terms_stack.peek().term == null) { declaration_stack.peek().invalid = true;
} else if (ctx.HASH() != null) { log.debug("VP - hash"); terms_stack.peek().term = tf.createColor(ctx.HASH().getText()); if (terms_stack.peek().term == null) { declaration_stack.peek().invalid = true; TermRect rectTerm = null; if (term instanceof TermIdent) { //idents - try to convert colors colorTerm = tf.createColor((TermIdent) term); } else if (term instanceof TermFunction) { // rgba(0,0,0) colorTerm = tf.createColor((TermFunction) term); if (colorTerm == null) rectTerm = tf.createRect((TermFunction) term);
} else if (ctx.HASH() != null) { log.debug("VP - hash"); terms_stack.peek().term = tf.createColor(ctx.HASH().getText()); if (terms_stack.peek().term == null) { declaration_stack.peek().invalid = true;
@Override public Term<?> getSpecifiedValue(String name) { Term<?> ret = getValue(name, true); if (ret == null) ret = css.getDefaultValue(name); if (ret != null) { if (ret instanceof TermColor && ((TermColor) ret).getKeyword() == Keyword.CURRENT_COLOR) { //clone the value fot setting the current color final TermFactory tf = CSSFactory.getTermFactory(); ret = tf.createColor(tf.createIdent("currentColor")); //set the current color value TermColor cvalue = getValue(TermColor.class, "color", true); if (cvalue == null) cvalue = (TermColor) css.getDefaultValue("color"); ((TermColor) ret).setValue(cvalue.getValue()); } } return ret; }
@Override public Term<?> getSpecifiedValue(String name) { Term<?> ret = getValue(name, true); if (ret == null) ret = css.getDefaultValue(name); if (ret != null) { if (ret instanceof TermColor && ((TermColor) ret).getKeyword() == Keyword.CURRENT_COLOR) { //clone the value fot setting the current color final TermFactory tf = CSSFactory.getTermFactory(); ret = tf.createColor(tf.createIdent("currentColor")); //set the current color value TermColor cvalue = getValue(TermColor.class, "color", true); if (cvalue == null) cvalue = (TermColor) css.getDefaultValue("color"); ((TermColor) ret).setValue(cvalue.getValue()); } } return ret; }
((terms_scope)terms_stack.peek()).term = tf.createColor(extractText(h)); if(((terms_scope)terms_stack.peek()).term==null) ((declaration_scope)declaration_stack.peek()).invalid = true; TermColor colorTerm = null; if(term instanceof TermIdent) { colorTerm = tf.createColor((TermIdent)term); if (colorTerm != null) term = colorTerm; colorTerm = tf.createColor((TermFunction)term); if(colorTerm != null) term = colorTerm;
terms_stack.peek().term = tf.createColor(extractText(h)); if(terms_stack.peek().term==null) declaration_stack.peek().invalid = true; cz.vutbr.web.css.TermColor colorTerm = null; if(term instanceof cz.vutbr.web.css.TermIdent) { colorTerm = tf.createColor((cz.vutbr.web.css.TermIdent)term); if (colorTerm != null) term = colorTerm; colorTerm = tf.createColor((cz.vutbr.web.css.TermFunction)term); if(colorTerm != null) term = colorTerm;
ret.push(createDeclaration("border-width", tf.createLength(1f, Unit.px))); ret.push(createDeclaration("border-style", tf.createIdent("solid"))); ret.push(createDeclaration("border-color", tf.createColor(0, 0, 255))); ret.push(createDeclaration("margin", tf.createLength(0.5f, Unit.em)));
ret.push(createDeclaration("border-style", tf.createIdent("solid"))); String color = colorString(getGraphicsState().getStrokingColor()); ret.push(createDeclaration("border-color", tf.createColor(color))); ret.push(createDeclaration("background-color", tf.createColor(color)));
protected NodeData createLineStyle(float x1, float y1, float x2, float y2) { HtmlDivLine line = new HtmlDivLine(x1, y1, x2, y2); String bside = line.getBorderSide(); NodeData ret = CSSFactory.createNodeData(); TermFactory tf = CSSFactory.getTermFactory(); ret.push(createDeclaration("position", tf.createIdent("absolute"))); ret.push(createDeclaration("position", tf.createIdent("absolute"))); ret.push(createDeclaration("left", tf.createLength(line.getLeft(), unit))); ret.push(createDeclaration("top", tf.createLength(line.getTop(), unit))); ret.push(createDeclaration("width", tf.createLength(line.getWidth(), unit))); ret.push(createDeclaration("height", tf.createLength((float) line.getHeight(), unit))); ret.push(createDeclaration(bside + "-width", tf.createLength(line.getLineStrokeWidth(), unit))); ret.push(createDeclaration(bside + "-style", tf.createIdent("solid"))); String color = colorString(getGraphicsState().getStrokingColor()); ret.push(createDeclaration(bside + "-color", tf.createColor(color))); if (line.getAngleDegrees() != 0) { TermFunction rotate = tf.createFunction(); rotate.setFunctionName("rotate").add(tf.createAngle(String.valueOf(line.getAngleDegrees()), Unit.deg, 1)); ret.push(createDeclaration("transform", rotate)); } return ret; }