batik css 解析器中 CSSEngine class 的用途是什么

What is the purpose of CSSEngine class in batik css parser

我正在评估 batik css 解析器以将其与我们的产品集成。为了最好地使用它,我想了解它 classes 代表什么。我无法理解 org.apache.batik.css.engine.CSSEngine class 的目的。这个class有什么用?

CSSEngine class 有一个函数 parseStyleSheet,它 returns 一个 StyleSheet 对象。此 StyleSheet 对象实际上是 css 的 dom 表示。

StyleSheet ss = cssEngine.parseStyleSheet(new ParsedURL("file:///"+filename),"max-width: 800px");

您可以通过扩展 CSSEngine class 来创建自己的 css 引擎 class。

  public class MyCSSEngine extends CSSEngine{

         public MyCSSEngine (ExtendedParser parser) {

        super(null, null, parser, MY_VALUE_MANAGERS, SVGCSSEngine.SVG_SHORTHAND_MANAGERS, null, null, "style",
                  null,
                  "class",
                  true,
                  null,
                  new MyCSSContext());
        // TODO Auto-generated constructor stub
    }
}

通过扩展 org.apache.batik.css.engine.CSSContext 创建 MyCSSContext。 来到 MY_VALUE_MANAGERS 这很重要。价值经理可以像

public static final ValueManager[] MY_VALUE_MANAGERS = {
    new AlignmentBaselineManager(),
    new BaselineShiftManager(),
    new ClipManager(),
    new ClipPathManager(),
    new ClipRuleManager(),

    new ColorManager(),
    new ColorInterpolationManager(),
    new ColorInterpolationFiltersManager(),
    new ColorProfileManager(),
    new ColorRenderingManager()
}

它基本上是在解析时注册你感兴趣的属性。(它远不止于此)。

您也可以使用 org.apache.batik.css.engine.SVGCSSEngine.SVG_VALUE_MANAGERS,但实现自己的价值管理器让您能够处理自己的自定义 css 属性 就像

-my-own-color:mufunc(10,23,45)