コード例 #1
0
ファイル: PShading.java プロジェクト: BobFleischman/docx4j
  public PShading(CSSValue value) {

    CTShd shd = Context.getWmlObjectFactory().createCTShd();

    // PrimitiveType 25 -> RGBCOLOR
    short ignored = 1;

    float fRed;
    float fGreen;
    float fBlue;

    CSSPrimitiveValue cssPrimitiveValue = (CSSPrimitiveValue) value;
    try {
      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));

    } catch (UnsupportedOperationException e) {

      try {
        Class<?> xhtmlImporterClass =
            Class.forName("org.docx4j.convert.in.xhtml.FSColorToHexString");
        Method rgbToHexMethod = xhtmlImporterClass.getMethod("rgbToHex", CSSPrimitiveValue.class);
        shd.setFill((String) rgbToHexMethod.invoke(null, cssPrimitiveValue));
      } catch (Exception e2) {
        log.error("docx4j-XHTMLImport jar not found. Please add this to your classpath.");
        log.error(e2.getMessage(), e2);
        throw e; // same as before
      }
    }

    this.setObject(shd);
  }
コード例 #2
0
 /**
  * Return the key of the CSSPrimitiveValue <code>value</code> which is used to cache Resource into
  * {@link IResourcesRegistry}.
  *
  * @param value
  * @return
  */
 public static String getCSSPrimitiveValueKey(CSSPrimitiveValue value) {
   switch (value.getPrimitiveType()) {
     case CSSPrimitiveValue.CSS_IDENT:
     case CSSPrimitiveValue.CSS_URI:
       String s = value.getStringValue();
       // Test if s is Color Name
       if (CSS2ColorHelper.isColorName(s)) {
         RGBColor rgbColor = CSS2ColorHelper.getRGBColor(s);
         if (rgbColor != null) {
           return getCSSRGBColorKey(rgbColor);
         }
       }
       return value.getStringValue();
     case CSSPrimitiveValue.CSS_RGBCOLOR:
       RGBColor rgbColor = value.getRGBColorValue();
       return getCSSRGBColorKey(rgbColor);
   }
   return null;
 }