Exemplo n.º 1
0
    void onToken(char token) {
        // 4,5:  font-family:
        // 6,7:  font-weight:
        // 8,9:  font-style:
        //10,11: src:
        //   10   11    12   13
        //   src   :   url    (
        //CRLog::trace("state==%d: %c ", _state, token);
        switch (token) {
        case ':':
            if (_state < 2) {
                _state = 0;
            } else if (_state == 4 || _state == 6 || _state == 8 || _state == 10) {
                _state++;
            } else if (_state != 3) {
                _state = 2;
            }
            break;
        case ';':
            if (_state < 2) {
                _state = 0;
            } else if (_state != 3) {
                _state = 2;
            }
            break;
        case '{':
            if (_state == 1) {
                _state = 2; // inside @font {
                _face.clear();
                _italic = false;
                _bold = false;
                _url.clear();
            } else
                _state = 3; // inside other {
            break;
        case '}':
            if (_state == 2) {
                if (!_url.empty()) {
//                    CRLog::trace("@font { face: %s; bold: %s; italic: %s; url: %s", _face.c_str(), _bold ? "yes" : "no",
//                                 _italic ? "yes" : "no", LCSTR(_url));
                    _fontList.add(_url, _face, _bold, _italic);
                }
            }
            _state = 0;
            break;
        case '(':
            if (_state == 12) {
                _state = 13;
            } else {
                if (_state > 3)
                    _state = 2;
            }
            break;
        }
    }
Exemplo n.º 2
0
/// extract @import filename from beginning of CSS
bool LVProcessStyleSheetImport( const char * &str, lString8 & import_file )
{
    const char * p = str;
    import_file.clear();
    skip_spaces( p );
    if ( *p !='@' )
        return false;
    p++;
    if (strncmp(p, "import", 6) != 0)
        return false;
    p+=6;
    skip_spaces( p );
    bool in_url = false;
    char quote_ch = 0;
    if ( !strncmp(p, "url", 3) ) {
        p+=3;
        skip_spaces( p );
        if ( *p != '(' )
            return false;
        p++;
        skip_spaces( p );
        in_url = true;
    }
    if ( *p == '\'' || *p=='\"' )
        quote_ch = *p++;
    while (*p) {
        if ( quote_ch && *p==quote_ch ) {
            p++;
            break;
        }
        if ( !quote_ch ) {
            if ( in_url && *p==')' ) {
                break;
            }
            if ( *p==' ' || *p=='\t' || *p=='\r' || *p=='\n' )
                break;
        }
        import_file << *p++;
    }
    skip_spaces( p );
    if ( in_url ) {
        if ( *p!=')' )
            return false;
        p++;
    }
    if ( import_file.empty() )
        return false;
    str = p;
    return true;
}
Exemplo n.º 3
0
 void onQuotedText(lString8 & token) {
     //CRLog::trace("state==%d: \"%s\"", _state, token.c_str());
     if (_state == 11 || _state == 13) {
         if (!token.empty()) {
             _url = LVCombinePaths(_basePath, Utf8ToUnicode(token));
         }
         _state = 2;
     } else if (_state == 5) {
         if (!token.empty()) {
             _face = token;
         }
         _state = 2;
     }
     token.clear();
 }
Exemplo n.º 4
0
 void onToken(lString8 & token) {
     if (token.empty())
         return;
     lString8 t = token;
     token.clear();
     //CRLog::trace("state==%d: %s", _state, t.c_str());
     if (t == "@font-face") {
         if (_state == 0)
             _state = 1; // right after @font
         return;
     }
     if (_state == 1)
         _state = 0;
     if (_state == 2) {
         if (t == "font-family")
             _state = 4;
         else if (t == "font-weight")
             _state = 6;
         else if (t == "font-style")
             _state = 8;
         else if (t == "src")
             _state = 10;
     } else if (_state == 5) {
         _face = t;
         _state = 2;
     } else if (_state == 7) {
         if (t == "bold")
             _bold = true;
         _state = 2;
     } else if (_state == 9) {
         if (t == "italic")
             _italic = true;
         _state = 2;
     } else if (_state == 11) {
         if (t == "url")
             _state = 12;
         else
             _state = 2;
     }
 }