Exemplo n.º 1
0
static void Test04()
{
    const char *simpleCss = " span\n{ color: red }\n\tp /* plain paragraph */ , p#id { }";
    CssPullParser parser(simpleCss, str::Len(simpleCss));
    const CssSelector *sel;
    const CssProperty *prop;

    bool ok = parser.NextRule();
    utassert(ok);
    prop = parser.NextProperty();
    utassert(prop && Css_Color == prop->type && IsPropVal(prop, "red"));
    prop = parser.NextProperty();
    utassert(!prop);
    sel = parser.NextSelector();
    utassert(sel && Tag_Span == sel->tag && !sel->clazz && IsSelector(sel, "span"));
    sel = parser.NextSelector();
    utassert(!sel);

    ok = parser.NextRule();
    utassert(ok);
    prop = parser.NextProperty();
    utassert(!prop);
    sel = parser.NextSelector();
    utassert(sel && Tag_P == sel->tag && !sel->clazz && IsSelector(sel, "p"));
    sel = parser.NextSelector();
    utassert(sel && Tag_NotFound == sel->tag && !sel->clazz && IsSelector(sel, "p#id"));
    sel = parser.NextSelector();
    utassert(!sel);

    ok = parser.NextRule();
    utassert(!ok);
}
Exemplo n.º 2
0
static void Test05()
{
    const char *simpleCss = "<!-- html { ignore } @ignore this; p { } -->";
    CssPullParser parser(simpleCss, str::Len(simpleCss));
    const CssSelector *sel;
    const CssProperty *prop;

    bool ok = parser.NextRule();
    utassert(ok);
    sel = parser.NextSelector();
    utassert(sel && Tag_Html == sel->tag && !sel->clazz && IsSelector(sel, "html"));
    sel = parser.NextSelector();
    utassert(!sel);
    prop = parser.NextProperty();
    utassert(!prop);

    ok = parser.NextRule();
    utassert(ok);
    sel = parser.NextSelector();
    utassert(sel && Tag_P == sel->tag && !sel->clazz && IsSelector(sel, "p"));
    sel = parser.NextSelector();
    utassert(!sel);
    prop = parser.NextProperty();
    utassert(!prop);

    ok = parser.NextRule();
    utassert(!ok);
}
Exemplo n.º 3
0
static void Test03()
{
    const char *simpleCss = "* { color: red }\np { color: blue }\n.green { color: green }\np.green { color: rgb(0,128,0) }\n";
    CssPullParser parser(simpleCss, str::Len(simpleCss));
    const CssSelector *sel = parser.NextSelector();
    utassert(!sel);
    const CssProperty *prop;

    bool ok = parser.NextRule();
    utassert(ok);
    sel = parser.NextSelector();
    utassert(sel && Tag_Any == sel->tag && !sel->clazz && IsSelector(sel, "*"));
    sel = parser.NextSelector();
    utassert(!sel);
    prop = parser.NextProperty();
    utassert(prop && Css_Color == prop->type && IsPropVal(prop, "red"));
    prop = parser.NextProperty();
    utassert(!prop);

    ok = parser.NextRule();
    utassert(ok);
    sel = parser.NextSelector();
    utassert(sel && Tag_P == sel->tag && !sel->clazz && IsSelector(sel, "p"));
    prop = parser.NextProperty();
    utassert(prop && Css_Color == prop->type && IsPropVal(prop, "blue"));
    prop = parser.NextProperty();
    utassert(!prop);

    ok = parser.NextRule();
    utassert(ok);
    sel = parser.NextSelector();
    utassert(sel && Tag_Any == sel->tag && IsSelector(sel, ".green") && str::EqNIx(sel->clazz, sel->clazzLen, "green"));
    prop = parser.NextProperty();
    utassert(prop && Css_Color == prop->type && IsPropVal(prop, "green"));
    prop = parser.NextProperty();
    utassert(!prop);

    ok = parser.NextRule();
    utassert(ok);
    sel = parser.NextSelector();
    utassert(sel && Tag_P == sel->tag && IsSelector(sel, "p.green") && str::EqNIx(sel->clazz, sel->clazzLen, "green"));
    prop = parser.NextProperty();
    utassert(prop && Css_Color == prop->type && IsPropVal(prop, "rgb(0,128,0)"));
    prop = parser.NextProperty();
    utassert(!prop);

    ok = parser.NextRule();
    utassert(!ok);
}
Exemplo n.º 4
0
Vec<PageAnnotation> *LoadFileModifications(const WCHAR *filepath)
{
    ScopedMem<WCHAR> modificationsPath(str::Join(filepath, SMX_FILE_EXT));
    size_t len;
    ScopedMem<char> data(file::ReadAll(modificationsPath, &len));
    if (!data)
        return NULL;

    CssPullParser parser(data, len);
    if (!parser.NextRule())
        return NULL;
    const CssSelector *sel = parser.NextSelector();
    if (!sel || !IsSelector(sel, "@meta") || parser.NextSelector())
        return NULL;
    const CssProperty *prop = parser.NextProperty();
    if (!prop || Css_Version != prop->type || !str::Parse(prop->s, prop->sLen, SMX_CURR_VERSION "%$"))
        return NULL;

    Vec<PageAnnotation> *list = new Vec<PageAnnotation>();
    while (parser.NextRule()) {
        sel = parser.NextSelector();
        if (!sel)
            continue;
        PageAnnotType type = IsSelector(sel, "highlight") ? Annot_Highlight :
                             IsSelector(sel, "underline") ? Annot_Underline :
                             IsSelector(sel, "strikeout") ? Annot_StrikeOut :
                             IsSelector(sel, "squiggly")  ? Annot_Squiggly  :
                             Annot_None;
        if (Annot_None == type || parser.NextSelector())
            continue;

        int pageNo = 0;
        RectT<float> rect;
        PageAnnotation::Color color;
        while ((prop = parser.NextProperty())) {
            switch (prop->type) {
            case Css_Page:
                if (!str::Parse(prop->s, prop->sLen, "%d%$", &pageNo))
                    pageNo = 0;
                break;
            case Css_Rect:
                if (!str::Parse(prop->s, prop->sLen, "%f %f %f %f%$",
                                &rect.x, &rect.y, &rect.dx, &rect.dy))
                    rect = RectT<float>();
                break;
            case Css_Color:
                int r, g, b, a;
                if (str::Parse(prop->s, prop->sLen, "#%2x%2x%2x%2x%$", &a, &r, &g, &b))
                    color = PageAnnotation::Color(r, g, b, a);
                else if (str::Parse(prop->s, prop->sLen, "#%2x%2x%2x%$", &r, &g, &b))
                    color = PageAnnotation::Color(r, g, b);
                break;
            }
        }
        if (pageNo <= 0 || rect.IsEmpty())
            continue;
        list->Append(PageAnnotation(type, pageNo, rect.Convert<double>(), color));
    }

    return list;
}