LCOV - code coverage report
Current view: top level - libreoffice/sw/source/filter/html - parcss1.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 31 0.0 %
Date: 2012-12-27 Functions: 0 20 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef _PARCSS1_HXX
      21             : #define _PARCSS1_HXX
      22             : 
      23             : // Die Tokens des CSS1-Parsers
      24             : enum CSS1Token
      25             : {
      26             :     CSS1_NULL,
      27             :     CSS1_UNKOWN,
      28             : 
      29             :     CSS1_IDENT,
      30             :     CSS1_STRING,
      31             :     CSS1_NUMBER,
      32             :     CSS1_PERCENTAGE,
      33             :     CSS1_LENGTH,            // eine absolute Groesse in 1/100 MM
      34             :     CSS1_PIXLENGTH,         // eine Pixel-Groesse
      35             :     CSS1_EMS,
      36             :     CSS1_EMX,
      37             :     CSS1_HEXCOLOR,
      38             : 
      39             :     CSS1_DOT_W_WS,
      40             :     CSS1_DOT_WO_WS,
      41             :     CSS1_COLON,
      42             :     CSS1_SLASH,
      43             :     CSS1_PLUS,
      44             :     CSS1_MINUS,
      45             :     CSS1_OBRACE,
      46             :     CSS1_CBRACE,
      47             :     CSS1_SEMICOLON,
      48             :     CSS1_COMMA,
      49             :     CSS1_HASH,
      50             : 
      51             :     CSS1_IMPORT_SYM,
      52             : // Feature: PrintExt
      53             :     CSS1_PAGE_SYM,
      54             : // /Feature: PrintExt
      55             : 
      56             :     CSS1_IMPORTANT_SYM,
      57             : 
      58             :     CSS1_URL,
      59             :     CSS1_RGB
      60             : };
      61             : 
      62             : // die Zustaende des Parsers
      63             : enum CSS1ParserState
      64             : {
      65             :     CSS1_PAR_ACCEPTED = 0,
      66             :     CSS1_PAR_WORKING,
      67             :     CSS1_PAR_ERROR
      68             : };
      69             : 
      70             : enum CSS1SelectorType
      71             : {
      72             :     CSS1_SELTYPE_ELEMENT,
      73             :     CSS1_SELTYPE_ELEM_CLASS,
      74             :     CSS1_SELTYPE_CLASS,
      75             :     CSS1_SELTYPE_ID,
      76             :     CSS1_SELTYPE_PSEUDO,
      77             : // Feature: PrintExt
      78             :     CSS1_SELTYPE_PAGE
      79             : // /Feature: PrintExt
      80             : 
      81             : };
      82             : 
      83             : // Die folegende Klasse beschreibt einen Simple-Selector, also
      84             : // - einen HTML-Element-Namen
      85             : // - einen HTML-Element-Namen mit Klasse (durch '.' getrennt)
      86             : // - eine Klasse (ohne Punkt)
      87             : // - eine mit ID=xxx gesetzte ID aus einem HTML-Dokument
      88             : // oder
      89             : // - ein Pseudo-Element
      90             : //
      91             : // Die Simple-Sektoren werden in einer Liste zu vollstaendigen
      92             : // Selektoren verkettet
      93             : class CSS1Selector
      94             : {
      95             :     CSS1SelectorType eType;     // Art des Selektors
      96             :     String aSelector;           // der Selektor selbst
      97             :     CSS1Selector *pNext;        // die naechste Komponente
      98             : 
      99             : public:
     100             : 
     101           0 :     CSS1Selector( CSS1SelectorType eTyp, const String &rSel )
     102           0 :         : eType(eTyp), aSelector( rSel ), pNext( 0 )
     103           0 :     {}
     104             : 
     105             :     ~CSS1Selector();
     106             : 
     107           0 :     CSS1SelectorType GetType() const { return eType; }
     108           0 :     const String& GetString() const { return aSelector; }
     109             : 
     110           0 :     void SetNext( CSS1Selector *pNxt ) { pNext = pNxt; }
     111           0 :     const CSS1Selector *GetNext() const { return pNext; }
     112             : };
     113             : 
     114             : // Die folegende Klasse beschreibt einen Teil-Ausdruck einer
     115             : // CSS1-Deklaration sie besteht aus
     116             : //
     117             : // - dem Typ des Ausdrucks (entspricht dem Token)
     118             : // - dem eigentlichen Wert als String und ggf. double
     119             : //   der double-Wert enthaelt das Vorzeichen fuer NUMBER und LENGTH
     120             : // - und dem Operator, mit dem er mit dem *Vorganger*-Ausdruck
     121             : //   verknuepft ist.
     122             : //
     123             : struct CSS1Expression
     124             : {
     125             :     sal_Unicode cOp;        // Art der Verkuepfung mit dem Vorgaenger
     126             :     CSS1Token eType;        // der Typ des Wertes
     127             :     String aValue;          // und sein Wert als String
     128             :     double nValue;          // und als Zahl (TWIPs fuer LENGTH)
     129             :     CSS1Expression *pNext;  // die naechste Komponente
     130             : 
     131             : public:
     132             : 
     133           0 :     CSS1Expression( CSS1Token eTyp, const String &rVal,
     134             :                     double nVal, sal_Unicode cO = 0 )
     135           0 :         : cOp(cO), eType(eTyp), aValue(rVal), nValue(nVal), pNext(0)
     136           0 :     {}
     137             : 
     138             :     ~CSS1Expression();
     139             : 
     140             :     inline void Set( CSS1Token eTyp, const String &rVal, double nVal,
     141             :                      sal_Unicode cO = 0 );
     142             : 
     143           0 :     CSS1Token GetType() const { return eType; }
     144           0 :     const String& GetString() const { return aValue; }
     145           0 :     double GetNumber() const { return nValue; }
     146             :     inline sal_uInt32 GetULength() const;
     147             :     inline sal_Int32 GetSLength() const;
     148           0 :     sal_Unicode GetOp() const { return cOp; }
     149             : 
     150             : 
     151             :     sal_Bool GetURL( String& rURL ) const;
     152             :     sal_Bool GetColor( Color &rRGB ) const;
     153             : 
     154           0 :     void SetNext( CSS1Expression *pNxt ) { pNext = pNxt; }
     155           0 :     const CSS1Expression *GetNext() const { return pNext; }
     156             : };
     157             : 
     158           0 : inline void CSS1Expression::Set( CSS1Token eTyp, const String &rVal,
     159             :                                  double nVal, sal_Unicode cO )
     160             : {
     161           0 :     cOp = cO; eType = eTyp; aValue = rVal; nValue = nVal; pNext = 0;
     162           0 : }
     163             : 
     164           0 : inline sal_uInt32 CSS1Expression::GetULength() const
     165             : {
     166           0 :     return nValue < 0. ? 0UL : (sal_uInt32)(nValue + .5);
     167             : }
     168             : 
     169           0 : inline sal_Int32 CSS1Expression::GetSLength() const
     170             : {
     171           0 :     return (sal_Int32)(nValue + (nValue < 0. ? -.5 : .5 ));
     172             : }
     173             : 
     174             : // Diese Klasse parst den Inhalt eines Style-Elements oder eine Style-Option
     175             : // und bereitet ihn ein wenig auf.
     176             : //
     177             : // Das Ergebnis des Parsers wird durch die Mehtoden SelectorParsed()
     178             : // und DeclarationParsed() an abgeleitete Parser uebergeben. Bsp:
     179             : //
     180             : // H1, H2 { font-weight: bold; text-align: right }
     181             : //  |  |                    |                  |
     182             : //  |  |                    |                  DeclP( 'text-align', 'right' )
     183             : //  |  |                    DeclP( 'font-weight', 'bold' )
     184             : //  |  SelP( 'H2', sal_False )
     185             : //  SelP( 'H1', sal_True )
     186             : //
     187             : class CSS1Parser
     188             : {
     189             :     sal_Bool bWhiteSpace : 1;           // White-Space gelesen?
     190             :     sal_Bool bEOF : 1;                  // Ende des "Files" ?
     191             : 
     192             :     sal_Unicode cNextCh;                // naechstes Zeichen
     193             : 
     194             :     xub_StrLen nInPos;                  // aktuelle Position im Input-String
     195             : 
     196             :     sal_uInt32 nlLineNr;                    // akt. Zeilen Nummer
     197             :     sal_uInt32 nlLinePos;               // akt. Spalten Nummer
     198             : 
     199             :     double nValue;                  // der Wert des Tokens als Zahl
     200             : 
     201             :     CSS1ParserState eState;         // der akteulle Zustand der Parsers
     202             :     CSS1Token nToken;               // das aktuelle Token
     203             : 
     204             :     String aIn;                     // der zu parsende String
     205             :     String aToken;                  // das Token als String
     206             : 
     207             :     // Parsen vorbereiten
     208             :     void InitRead( const String& rIn );
     209             : 
     210             :     // das naechste Zeichen holen
     211             :     sal_Unicode GetNextChar();
     212             : 
     213             :     // das naechste Token holen
     214             :     CSS1Token GetNextToken();
     215             : 
     216             :     // arbeitet der Parser noch?
     217           0 :     sal_Bool IsParserWorking() const { return CSS1_PAR_WORKING == eState; }
     218             : 
     219           0 :     sal_Bool IsEOF() const { return bEOF; }
     220             : 
     221           0 :     sal_uInt32 IncLineNr() { return ++nlLineNr; }
     222           0 :     sal_uInt32 IncLinePos() { return ++nlLinePos; }
     223             :     inline sal_uInt32 SetLinePos( sal_uInt32 nlPos );           // inline unten
     224             : 
     225             :     // Parsen von Teilen der Grammatik
     226             :     void ParseRule();
     227             :     CSS1Selector *ParseSelector();
     228             :     CSS1Expression *ParseDeclaration( String& rProperty );
     229             : 
     230             : protected:
     231             : 
     232             :     void ParseStyleSheet();
     233             : 
     234             :     // Den Inhalt eines HTML-Style-Elements parsen.
     235             :     // Fuer jeden Selektor und jede Deklaration wird
     236             :     // SelectorParsed() bzw. DeclarationParsed() aufgerufen.
     237             :     sal_Bool ParseStyleSheet( const String& rIn );
     238             : 
     239             :     // Den Inhalt einer HTML-Style-Option parsen.
     240             :     // F�r jede Deklaration wird DeclarationParsed() aufgerufen.
     241             :     sal_Bool ParseStyleOption( const String& rIn );
     242             : 
     243             :     // Diese Methode wird aufgerufen, wenn ein Selektor geparsed wurde
     244             :     // Wenn 'bFirst' gesetzt ist, beginnt mit dem Selektor eine neue
     245             :     // Deklaration. Wird sal_True zurueckgegeben, wird der Selektor
     246             :     // geloscht, sonst nicht.
     247             :     // Die Implementierung dieser Methode gibt nur sal_True zuruck.
     248             :     virtual bool SelectorParsed( CSS1Selector* pSelector, bool bFirst );
     249             : 
     250             :     // Diese Methode wird fuer jede geparsete Property aufgerufen. Wird
     251             :     // sal_True zurueckgegeben wird der Selektor geloscht, sonst nicht.
     252             :     // Die Implementierung dieser Methode gibt nur sal_True zuruck.
     253             :     virtual sal_Bool DeclarationParsed( const String& rProperty,
     254             :                                     const CSS1Expression *pExpr );
     255             : 
     256             : public:
     257             : 
     258             :     CSS1Parser();
     259             :     virtual ~CSS1Parser();
     260             : 
     261             :     inline sal_uInt32   GetLineNr() const       { return nlLineNr; }
     262             :     inline sal_uInt32   GetLinePos() const      { return nlLinePos; }
     263             : };
     264             : 
     265           0 : inline sal_uInt32 CSS1Parser::SetLinePos( sal_uInt32 nlPos )
     266             : {
     267           0 :     sal_uInt32 nlOld = nlLinePos;
     268           0 :     nlLinePos = nlPos;
     269           0 :     return nlOld;
     270             : }
     271             : 
     272             : 
     273             : #endif
     274             : 
     275             : 
     276             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10