public void debug(String propertyName, CSSValue value) { short valueType = value.getCssValueType(); switch (valueType) { case CSSValue.CSS_CUSTOM: log.warn("valueType CUSTOM for " + propertyName + " - NOT IMPLEMENTED "); break; case CSSValue.CSS_INHERIT: log.warn("valueType INHERIT for " + propertyName + " - NOT IMPLEMENTED "); break; case CSSValue.CSS_PRIMITIVE_VALUE: log.debug("valueType PRIMITIVE for " + propertyName ); CSSPrimitiveValue cssPrimitiveValue = (CSSPrimitiveValue)value; log.debug("PrimitiveType: " + cssPrimitiveValue.getPrimitiveType() ); break; case CSSValue.CSS_VALUE_LIST: log.debug("valueType LIST for " + propertyName ); CSSValueList cssValueList = (CSSValueList)value; break; default: log.error("Unexpected valueType " + valueType + " for " + propertyName ); return; } }
public Shading(CSSValue value) { CTShd shd = Context.getWmlObjectFactory().createCTShd(); // PrimitiveType 25 -> RGBCOLOR short ignored = 1; CSSPrimitiveValue cssPrimitiveValue = (CSSPrimitiveValue)value; float fRed = cssPrimitiveValue.getRGBColorValue().getRed().getFloatValue(ignored); float fGreen = cssPrimitiveValue.getRGBColorValue().getGreen().getFloatValue(ignored); float fBlue = cssPrimitiveValue.getRGBColorValue().getBlue().getFloatValue(ignored); shd.setFill(UnitsOfMeasurement.rgbTripleToHex(fRed, fGreen, fBlue) ); this.setObject( shd ); }
private static boolean isBold(CSSValue value) { String val = value.getCssText().toLowerCase(); if (val.equals("bold") || val.equals("bolder")) { return true; } try { int weight = Integer.parseInt(val); return (weight > 400); } catch (NumberFormatException err) { return false; } }
float fVal = cssPrimitiveValue.getFloatValue(ignored); // unit type ignored in cssparser short type = cssPrimitiveValue.getPrimitiveType(); if (CSSPrimitiveValue.CSS_IN == type) { twip = UnitsOfMeasurement.inchToTwip(fVal); twip = twipFromPercentage(fVal); } else if (CSSPrimitiveValue.CSS_IDENT == type) { if (value.getCssText().equals("normal")) { log.error("TODO: handle value: " + value.getCssText()); return;
public SpaceBefore(CSSValue value) { debug(CSS_NAME, value); CSSPrimitiveValue cssPrimitiveValue = (CSSPrimitiveValue)value; short ignored = 1; float fVal = cssPrimitiveValue.getFloatValue(ignored); // unit type ignored in cssparser int twip; short type = cssPrimitiveValue.getPrimitiveType(); if (CSSPrimitiveValue.CSS_IN == type) { twip = UnitsOfMeasurement.inchToTwip(fVal); } else if (CSSPrimitiveValue.CSS_MM == type) { twip = UnitsOfMeasurement.mmToTwip(fVal); } else { log.error("No support for unit " + type); twip = 0; } this.setObject(BigInteger.valueOf(twip) ); }
fRed = cssPrimitiveValue.getRGBColorValue().getRed() .getFloatValue(ignored); fGreen = cssPrimitiveValue.getRGBColorValue().getGreen() .getFloatValue(ignored); fBlue = cssPrimitiveValue.getRGBColorValue().getBlue() .getFloatValue(ignored); shd.setFill(UnitsOfMeasurement.rgbTripleToHex(fRed, fGreen, fBlue));
/** * Now used to create fill property for paragraph only */ public static Property createPropertyFromCssNameForPPr(String name, CSSValue value) { try { if (name.equals(PShading.CSS_NAME )) { // background color if(value.getCssText().toLowerCase().equals("transparent")){ return null; } if(simpleRGBCheck(value.getCssText())){ return new PShading(value); } } } catch (java.lang.UnsupportedOperationException uoe) { // TODO: consider whether it is right to catch this, // or whether calling code should handle a docx4j exception wrapping this log.error("Can't create property from: " + name + ":" + value.getCssText() ); return null; } log.debug("How to handle: " + name + "?"); return null; }
public static int getTwip(CSSPrimitiveValue cssPrimitiveValue) { float fVal = cssPrimitiveValue.getFloatValue(ignored); // unit type ignored in cssparser log.debug("margin-left: " + fVal); if (fVal==0f) { short type = cssPrimitiveValue.getPrimitiveType();
public Underline(CSSValue value) { //debug(CSS_NAME, value); U u = Context.getWmlObjectFactory().createU(); if (value.getCssText().toLowerCase().equals("underline") || value.getCssText().toLowerCase().equals("[underline]")) { u.setVal(UnderlineEnumeration.SINGLE); // } else if (value.getCssText().toLowerCase().equals("underline")) { // u.setVal(UnderlineEnumeration.NONE); } else { log.error("How to handle " + CSS_NAME + " " + value.getCssText().toLowerCase()); } this.setObject( u ); }
public Strike(CSSValue value) { BooleanDefaultTrue bdt = Context.getWmlObjectFactory().createBooleanDefaultTrue(); if (!(value.getCssText().toLowerCase().equals("line-through") || value.getCssText().toLowerCase().equals("[line-through]"))) { bdt.setVal(Boolean.FALSE); } this.setObject( bdt ); }
public TextAlignmentVertical(CSSValue value) { debug(CSS_NAME, value); TextAlignment textAlignment = Context.getWmlObjectFactory().createPPrBaseTextAlignment(); if (value.getCssText().toLowerCase().equals("top")) { textAlignment.setVal("top"); } else if (value.getCssText().toLowerCase().equals("middle")) { textAlignment.setVal("center"); } else if (value.getCssText().toLowerCase().equals("baseline")) { textAlignment.setVal("auto"); } else { log.warn("How to handle vertical-align: " + value.getCssText()); } this.setObject( textAlignment ); }
public VerticalAlignment(CSSValue value) { CTVerticalAlignRun vAlign = Context.getWmlObjectFactory().createCTVerticalAlignRun(); if (value.getCssText().toLowerCase().equals("top")) { vAlign.setVal(STVerticalAlignRun.SUPERSCRIPT); this.setObject( vAlign ); } else if (value.getCssText().toLowerCase().equals("super")) { vAlign.setVal(STVerticalAlignRun.SUPERSCRIPT); this.setObject( vAlign ); } else if (value.getCssText().toLowerCase().equals("bottom") || value.getCssText().toLowerCase().equals("sub")) { vAlign.setVal(STVerticalAlignRun.SUBSCRIPT); this.setObject( vAlign ); } else { log.warn("What to do with value: " + value.getCssText()); } }
public Justification(CSSValue value) { debug(CSS_NAME, value); Jc jc = Context.getWmlObjectFactory().createJc(); if (value.getCssText().toLowerCase().equals("left")) { jc.setVal(JcEnumeration.LEFT); } else if (value.getCssText().toLowerCase().equals("center")) { jc.setVal(JcEnumeration.CENTER); } else if (value.getCssText().toLowerCase().equals("right")) { jc.setVal(JcEnumeration.RIGHT); } else if (value.getCssText().toLowerCase().equals("justify")) { jc.setVal(JcEnumeration.BOTH); } else { log.warn("How to handle justification: " + value.getCssText()); } this.setObject( jc ); }
public TextDir(CSSValue value) { debug(CSS_NAME, value); TextDirection textDirection = Context.getWmlObjectFactory().createTextDirection(); if (value.getCssText().toLowerCase().equals("rotate(0deg)")) { textDirection.setVal(DEFAULT_LEFT_TO_RIGHT); } else if (value.getCssText().toLowerCase().equals("rotate(270deg)")) { textDirection.setVal("btLr"); } else if (value.getCssText().toLowerCase().equals("rotate(90deg)")) { textDirection.setVal("tbRl"); } else { log.warn("How to handle transform: " + value.getCssText()); textDirection.setVal(DEFAULT_LEFT_TO_RIGHT); } this.setObject( textDirection ); }
public TextAlignmentVertical(CSSValue value) { debug(CSS_NAME, value); CTVerticalJc textAlignment = Context.getWmlObjectFactory().createCTVerticalJc(); if (value.getCssText().toLowerCase().equals("top")) { textAlignment.setVal(STVerticalJc.TOP); } else if (value.getCssText().toLowerCase().equals("middle")) { textAlignment.setVal(STVerticalJc.CENTER); } else if (value.getCssText().toLowerCase().equals("bottom")) { textAlignment.setVal(STVerticalJc.BOTTOM); } else { log.warn("How to handle vertical-align: " + value.getCssText()); // eg baseline // Default to top or center.. textAlignment.setVal(STVerticalJc.CENTER); } this.setObject( textAlignment ); }
public Italics(CSSValue value) { BooleanDefaultTrue bdt = Context.getWmlObjectFactory().createBooleanDefaultTrue(); if (!value.getCssText().toLowerCase().equals("italic")) { bdt.setVal(Boolean.FALSE); } this.setObject( bdt ); }
public HighlightColor(CSSValue value) { Highlight shd = Context.getWmlObjectFactory().createHighlight(); shd.setVal(value.getCssText()); this.setObject( shd ); }
public TextDirection(CSSValue value) { if (value.getCssText().toLowerCase().equals("rtl")) { this.setObject( Context.getWmlObjectFactory().createBooleanDefaultTrue() ); } else { BooleanDefaultTrue bdt = Context.getWmlObjectFactory().createBooleanDefaultTrue(); bdt.setVal(Boolean.FALSE); } }
public PageBreakBefore(CSSValue value) { debug(CSS_NAME, value); if (value.getCssText().toLowerCase().equals("always")) { this.setObject( Context.getWmlObjectFactory().createBooleanDefaultTrue() ); } else { BooleanDefaultTrue bdt = Context.getWmlObjectFactory().createBooleanDefaultTrue(); bdt.setVal(Boolean.FALSE); } }
public KeepNext(CSSValue value) { debug(CSS_NAME, value); if (value.getCssText().toLowerCase().equals("avoid")) { this.setObject( Context.getWmlObjectFactory().createBooleanDefaultTrue() ); } else { BooleanDefaultTrue bdt = Context.getWmlObjectFactory().createBooleanDefaultTrue(); bdt.setVal(Boolean.FALSE); } }