changeset 510:2bc3d207f5ad

start implementing StyleEngine::apply
author Johannes Hofmann <Johannes.Hofmann@gmx.de>
date Wed, 29 Oct 2008 19:30:50 +0100
parents fd2454cd0120
children 1d7a68d6ceb5
files src/css.hh src/styleengine.cc
diffstat 2 files changed, 28 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/css.hh	Wed Oct 29 19:03:43 2008 +0100
+++ b/src/css.hh	Wed Oct 29 19:30:50 2008 +0100
@@ -19,6 +19,7 @@
          dw::core::style::TextDecoration textDecoration;
          dw::core::style::WhiteSpace whiteSpace;
          const char *name; /* used for font family */
+         int size;
       } Value;
 
       typedef enum {
--- a/src/styleengine.cc	Wed Oct 29 19:03:43 2008 +0100
+++ b/src/styleengine.cc	Wed Oct 29 19:30:50 2008 +0100
@@ -12,6 +12,8 @@
 #include <stdio.h>
 #include "styleengine.hh"
 
+using namespace dw::core::style;
+
 StyleEngine::StyleEngine (dw::core::Layout *layout) {
    stack = new lout::misc::SimpleVector <Node> (1);
    cssContext = new CssContext ();
@@ -52,36 +54,53 @@
    stack->setSize (stack->size () - 1);
 }
 
-void StyleEngine::apply (dw::core::style::StyleAttrs *attr,
-   CssPropertyList *props) {
+void StyleEngine::apply (StyleAttrs *attrs, CssPropertyList *props) {
+   FontAttrs fontAttrs = *attrs->font;
 
    for (int i = 0; i < props->size (); i++) {
       CssProperty *p = props->getRef (i);
       
       switch (p->name) {
-
+         /* \todo missing cases */
+         case CssProperty::CSS_PROPERTY_BACKGROUND_COLOR:
+            attrs->backgroundColor =
+               Color::createSimple (layout, p->value.color);
+            break; 
+         case CssProperty::CSS_PROPERTY_BORDER_BOTTOM_COLOR:
+            attrs->borderColor.bottom =
+              Color::createSimple (layout, p->value.color);
+            break; 
+         case CssProperty::CSS_PROPERTY_BORDER_BOTTOM_STYLE:
+            attrs->borderStyle.bottom = p->value.borderStyle;
+            break;
+         case CssProperty::CSS_PROPERTY_FONT_FAMILY:
+            fontAttrs.name = p->value.name;
+            break;
+         case CssProperty::CSS_PROPERTY_FONT_SIZE:
+            fontAttrs.size = p->value.size;
+            break;
 
          default:
             break;
       }
    }
+
+   attrs->font = Font::create (layout, &fontAttrs);
 }
 
-dw::core::style::Style * StyleEngine::style0 () {
+Style * StyleEngine::style0 () {
    CssPropertyList props;
    CssPropertyList *tagStyleProps = CssPropertyList::parse (
       stack->getRef (stack->size () - 1)->styleAttribute);
 
-   dw::core::style::StyleAttrs attrs =
-      *stack->getRef (stack->size () - 1)->style;
+   StyleAttrs attrs = *stack->getRef (stack->size () - 1)->style;
 
    cssContext->apply (&props, this, tagStyleProps,
       stack->getRef (stack->size () - 1)->nonCssProperties);
 
    apply (&attrs, &props);
 
-   stack->getRef (stack->size () - 1)->style =
-      dw::core::style::Style::create (layout, &attrs);
+   stack->getRef (stack->size () - 1)->style = Style::create (layout, &attrs);
    
    return NULL;
 }