예제 #1
0
    def test_get_css_style02(self):
        doc = window.document
        root = doc.create_element('svg')
        doc.append_child(root)
        style = root.create_sub_element('style')
        style.text = '''
@media (min-height: 680px) and (orientation: landscape) {
    #heading {
        font-size: 24px;
        font-weight: bold;
    }
    #caption {
        font-size: 12px;
    }
}
        '''
        text = root.create_sub_element('text')
        text.id = 'heading'

        root.attributes.update({
            'width': '1280',
            'height': '679',
            'viewBox': '0 0 1280 679',
        })
        css_rules = get_css_rules(text)
        css_style, css_style_important = get_css_style(text, css_rules)
        self.assertIsNone(css_style.get('font-size'))
        self.assertIsNone(css_style.get('font-weight'))
        self.assertEqual(0, len(css_style_important))

        css_style = text.get_computed_style()
        self.assertEqual(Font.default_font_size, css_style.get('font-size'))
        self.assertEqual(Font.default_font_weight,
                         css_style.get('font-weight'))

        root.attributes.update({
            'width': '1280',
            'height': '680',
            'viewBox': '0 0 1280 680',
        })
        css_rules = get_css_rules(text)
        css_style, css_style_important = get_css_style(text, css_rules)
        self.assertEqual('24px', css_style.get('font-size'))
        self.assertEqual('bold', css_style.get('font-weight'))
        self.assertEqual(0, len(css_style_important))

        css_style = text.get_computed_style()
        self.assertEqual(24, css_style.get('font-size'))
        self.assertEqual(700, css_style.get('font-weight'))

        # SVG-UA stylesheet
        css_rules = get_css_rules(style)
        css_style, css_style_important = get_css_style(style, css_rules)
        self.assertEqual('none', css_style.get('display'))
        self.assertEqual('none', css_style_important.get('display'))

        css_style = style.get_computed_style()
        self.assertEqual('none', css_style.get('display'))
예제 #2
0
    def test_get_css_style04(self):
        parser = SVGParser()
        svg = '''
<svg width="5cm" height="4cm" viewBox="0 0 500 400"
     xmlns="http://www.w3.org/2000/svg">
  <style type="text/css">
    @import url(svg/style8.css);
    @media screen { /* rule (1) */
      /* hide navigation controls when printing */
      #navigation { display: none }
      @media (max-width: 12cm) { /* rule (2) */
        /* keep notes in flow when printing to narrow pages */
        .note { float: none }
      }
    }
    @media screen and (min-width: 35em),
           print and (min-width: 40em) {
      #section_navigation { float: left; width: 10em; }
    }
    .Border { fill:none; stroke:blue; stroke-width:1 }
    .Connect { fill:none; stroke:#888888; stroke-width:2 }
    .SamplePath { fill:none; stroke:red; stroke-width:5 }
    .EndPoint { fill:none; stroke:#888888; stroke-width:2 }
    .CtlPoint { fill:#888888; stroke:none }
    .AutoCtlPoint { fill:none; stroke:blue; stroke-width:4 }
    .Label { font-size:22; font-family:Verdana }
  </style>
  <text id="heading" x="-280" y="-270">
    SVG demonstration</text>
  <rect class="Border" x="1" y="1" width="498" height="398" id="rect01" />
  <polyline class="Connect" points="100,200 100,100" id="polyline01" />
  <path class="SamplePath" d="M100,200 C100,100 250,100 250,200
                                       S400,300 400,200" id="path01" />
  <circle class="EndPoint" cx="100" cy="200" r="10" id="circle01" />
  <text class="Label" x="25" y="70" id="text01">
    M100,200 C100,100 250,100 250,200</text>
</svg>
        '''
        root = parser.fromstring(svg)
        rect = root.get_element_by_id('rect01')
        css_rules = get_css_rules(rect)
        css_style, css_style_important = get_css_style(rect, css_rules)
        self.assertEqual(4, len(css_style))
        self.assertEqual(0, len(css_style_important))

        css_style = rect.get_computed_style()
        self.assertEqual('none', css_style.get('fill'))
        self.assertEqual('blue', css_style.get('stroke'))
        self.assertEqual(1, css_style.get('stroke-width'))

        text = root.get_element_by_id('heading')
        css_style = text.get_computed_style()
        self.assertEqual(24,
                         css_style.get('font-size'),
                         msg='http server may not be working.')
        self.assertEqual(700, css_style.get('font-weight'))
예제 #3
0
    def test_get_css_style01(self):
        # 'style' element
        # See also: svg/style8.css
        parser = SVGParser()
        root = parser.create_element('svg')
        style = root.create_sub_element('style')
        style.text = '@import url(svg/style8.css);'
        text = root.create_sub_element('text')
        text.id = 'heading'

        css_rules = get_css_rules(text)
        css_style, css_style_important = get_css_style(text, css_rules)
        self.assertEqual('24px',
                         css_style.get('font-size'),
                         msg='http server may not be working.')
        self.assertEqual('bold', css_style.get('font-weight'))
        self.assertEqual(0, len(css_style_important))

        css_style = text.get_computed_style()
        self.assertEqual(24, css_style.get('font-size'))
        self.assertEqual(700, css_style.get('font-weight'))