private String checkForFormat(Term<?> term) { if (term instanceof TermFunction && term.getOperator() == Operator.SPACE) { final TermFunction fn = (TermFunction) term; if (fn.getFunctionName().equalsIgnoreCase("format") && fn.size() == 1 && fn.get(0) instanceof TermString) { return ((TermString) fn.get(0)).getValue(); } else return null; } else return null; }
protected boolean prependMinus(Term<?> term) { boolean merged = false; if (term instanceof TermFloatValue) { // includes TermAngle, TermLength, etc. TermFloatValue floatT = (TermFloatValue) term; floatT.setValue(-1 * floatT.getValue()); merged = true; } else if (term instanceof TermIdent) { TermIdent ident = (TermIdent) term; ident.setValue("-" + ident.getValue()); merged = true; } else if (term instanceof TermFunction) { TermFunction func = (TermFunction) term; func.setFunctionName("-" + func.getFunctionName()); merged = true; } return merged; }
@Override public TermRect createRect(TermFunction function) { if (function.getFunctionName().equalsIgnoreCase("rect")) { List<Term<?>> args = function.getValues(true); //try the rect(0 0 0 0) syntax if (args == null || args.size() != 4) args = function.getSeparatedValues(CSSFactory.getTermFactory().createOperator(','), true); //try the rect(0, 0, 0, 0) syntax if (args.size() == 4) { //check the argument count and types for (int i = 0; i < 4; i++) { Term<?> val = args.get(i); if (val instanceof TermIdent) { if (((TermIdent) val).getValue().equalsIgnoreCase("auto")) //replace 'auto' with null args.set(i, null); } else if (!(val instanceof TermLength)) { return null; } } return createRect((TermLength) args.get(0), (TermLength) args.get(1), (TermLength) args.get(2), (TermLength) args.get(3)); } else { return null; } } else { return null; } }
@SuppressWarnings("unused") private boolean processClip(Declaration d, Map<String, CSSProperty> properties, Map<String, Term<?>> values) { if (d.size() != 1) return false; Term<?> term = d.get(0); if (term instanceof TermIdent) { final Set<Clip> allowedClips = EnumSet.allOf(Clip.class); Clip clip = genericPropertyRaw(Clip.class, allowedClips, (TermIdent) term); if (clip != null) { properties.put("clip-top", clip); properties.put("clip-right", clip); properties.put("clip-bottom", clip); properties.put("clip-left", clip); return true; } return false; } else if (term instanceof TermFunction) { TermFunction termf = (TermFunction) term; // this is possibly valid rect() function if ("rect".equals(termf.getFunctionName()) && termf.size() == 4) { Repeater clip = new ClipRepeater(); clip.assignTerms(termf.getValue().toArray(new Term<?>[0])); return clip.repeat(properties, values); } } return false; }
function.setFunctionName(fname); if (terms_stack.peek().unary == -1) //if started with minus, add the minus to the function name function.setFunctionName('-' + function.getFunctionName()); if (t != null) function.setValue(t); terms_stack.peek().term = function;
if (t instanceof TermFunction && validFuncNames.contains(((TermFunction) t) .getFunctionName().toLowerCase())) list.add(t); else
fn.setFunctionName(name); fn.setValue(args); if (!fn.isValid())
List<Term<?>> args = func.getSeparatedValues(CSSFactory.getTermFactory().createOperator(','), false); if (args != null) if ((COLOR_RGB_NAME.equals(func.getFunctionName()) && args.size() == COLOR_PARAMS_COUNT) || COLOR_RGBA_NAME.equals(func.getFunctionName()) && args.size() == COLOR_PARAMS_COUNT + 1) { else if ((COLOR_HSL_NAME.equals(func.getFunctionName()) && args.size() == COLOR_PARAMS_COUNT) || COLOR_HSLA_NAME.equals(func.getFunctionName()) && args.size() == COLOR_PARAMS_COUNT + 1) {
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; }
function.setFunctionName(extractText(f)); if (((terms_scope)terms_stack.peek()).unary == -1) //if started with minus, add the minus to the function name function.setFunctionName('-' + function.getFunctionName()); if (t != null) function.setValue(t); ((terms_scope)terms_stack.peek()).term = function;
else if (t instanceof TermFunction && validFuncNames.contains(((TermFunction) t) .getFunctionName().toLowerCase())) list.add(t); else
List<Term<?>> args = func.getSeparatedValues(CSSFactory.getTermFactory().createOperator(','), false); if (args != null) if ((COLOR_RGB_NAME.equals(func.getFunctionName()) && args.size() == COLOR_PARAMS_COUNT) || COLOR_RGBA_NAME.equals(func.getFunctionName()) && args.size() == COLOR_PARAMS_COUNT + 1) { else if ((COLOR_HSL_NAME.equals(func.getFunctionName()) && args.size() == COLOR_PARAMS_COUNT) || COLOR_HSLA_NAME.equals(func.getFunctionName()) && args.size() == COLOR_PARAMS_COUNT + 1) {
private String checkForFormat(Term<?> term) { if (term instanceof TermFunction && term.getOperator() == Operator.SPACE) { final TermFunction fn = (TermFunction) term; if (fn.getFunctionName().equalsIgnoreCase("format") && fn.size() == 1 && fn.get(0) instanceof TermString) { return ((TermString) fn.get(0)).getValue(); } else return null; } else return null; }
function.setFunctionName(extractText(f)); if (terms_stack.peek().unary == -1) //if started with minus, add the minus to the function name function.setFunctionName('-' + function.getFunctionName()); if (t != null) function.setValue(t); terms_stack.peek().term = function;
if (fnterm instanceof TermFunction) { ((TermFunction) fnterm).setFunctionName('-' + ((TermFunction) fnterm).getFunctionName()); terms_stack.peek().term = fnterm; } else {
else if (t instanceof TermFunction && validFuncNames.contains(((TermFunction) t) .getFunctionName().toLowerCase())) list.add(t); else
@Override public TermRect createRect(TermFunction function) { if (function.getFunctionName().equalsIgnoreCase("rect")) { List<Term<?>> args = function.getValues(true); //try the rect(0 0 0 0) syntax if (args == null || args.size() != 4) args = function.getSeparatedValues(CSSFactory.getTermFactory().createOperator(','), true); //try the rect(0, 0, 0, 0) syntax if (args.size() == 4) { //check the argument count and types for (int i = 0; i < 4; i++) { Term<?> val = args.get(i); if (val instanceof TermIdent) { if (((TermIdent) val).getValue().equalsIgnoreCase("auto")) //replace 'auto' with null args.set(i, null); } else if (!(val instanceof TermLength)) { return null; } } return createRect((TermLength) args.get(0), (TermLength) args.get(1), (TermLength) args.get(2), (TermLength) args.get(3)); } else { return null; } } else { return null; } }
if ((COLOR_RGB_NAME.equals(func.getFunctionName()) && func.size() == COLOR_PARAMS_COUNT) || COLOR_RGBA_NAME.equals(func.getFunctionName()) && func.size() == COLOR_PARAMS_COUNT + 1) { Term<?> term = func.get(i); if (func.size() > COLOR_PARAMS_COUNT) Term<?> term = func.get(COLOR_PARAMS_COUNT); if (term instanceof TermNumber || term instanceof TermInteger) { float alpha = getFloatValue(term); else if ((COLOR_HSL_NAME.equals(func.getFunctionName()) && func.size() == COLOR_PARAMS_COUNT) || COLOR_HSLA_NAME.equals(func.getFunctionName()) && func.size() == COLOR_PARAMS_COUNT + 1) { Term<?> hterm = func.get(0); if (hterm instanceof TermNumber || hterm instanceof TermInteger) { h = getFloatValue(hterm); Term<?> sterm = func.get(1); if (sterm instanceof TermPercent) { int is = ((TermPercent) sterm).getValue().intValue(); Term<?> lterm = func.get(2); if (lterm instanceof TermPercent) { int il = ((TermPercent) lterm).getValue().intValue(); if (func.size() > COLOR_PARAMS_COUNT) Term<?> term = func.get(COLOR_PARAMS_COUNT);
else if (t instanceof TermFunction && validFuncNames.contains(((TermFunction) t) .getFunctionName().toLowerCase())) list.add(t); else
if ((COLOR_RGB_NAME.equals(func.getFunctionName()) && func.size() == COLOR_PARAMS_COUNT) || COLOR_RGBA_NAME.equals(func.getFunctionName()) && func.size() == COLOR_PARAMS_COUNT + 1) { Term<?> term = func.get(i); if (func.size() > COLOR_PARAMS_COUNT) Term<?> term = func.get(COLOR_PARAMS_COUNT); if (term instanceof TermNumber || term instanceof TermInteger) { float alpha = getFloatValue(term); else if ((COLOR_HSL_NAME.equals(func.getFunctionName()) && func.size() == COLOR_PARAMS_COUNT) || COLOR_HSLA_NAME.equals(func.getFunctionName()) && func.size() == COLOR_PARAMS_COUNT + 1) { Term<?> hterm = func.get(0); if (hterm instanceof TermNumber || hterm instanceof TermInteger) { h = getFloatValue(hterm); Term<?> sterm = func.get(1); if (sterm instanceof TermPercent) { int is = ((TermPercent) sterm).getValue().intValue(); Term<?> lterm = func.get(2); if (lterm instanceof TermPercent) { int il = ((TermPercent) lterm).getValue().intValue(); if (func.size() > COLOR_PARAMS_COUNT) Term<?> term = func.get(COLOR_PARAMS_COUNT);