示例#1
0
    def _renderImpl(self, **kwargs):
        a = self.attrs

        LayoutAttributeParser.parseScale(a, True, kwargs)
        LayoutAttributeParser.parseAlignment(a, True, kwargs)
        LayoutAttributeParser.parsePadding(a, True, kwargs, group=a.styleGroup, defaultValue=GeneralSizeEnum.xsmall[0])

        color = a.getAsColorValue(TagAttributesEnum.COLOR, ArgsUtils.get("colorDef", None, kwargs), kwargs)

        if not ArgsUtils.get("skipBorder", False, kwargs):
            LayoutAttributeParser.parseBorder(
                a,
                True,
                kwargs,
                group=a.styleGroup,
                defaultColor=ArgsUtils.get("borderColorDef", color.shiftColors[1] if color else None, kwargs),
            )

        # -------------------------------------------------------------------------------------------
        # BACKGROUND COLOR
        if not ArgsUtils.get("skipBackground", False, kwargs):
            if isinstance(color, ColorValue):
                a.styles.add("background-color", color.web, a.styleGroup)
            elif a.explicitAccent or a.themeChanged:
                self.useBackground()

        a.classes.add("sfml-push", a.styleGroup)
示例#2
0
    def _renderImpl(self, **kwargs):
        a = self.attrs

        LayoutAttributeParser.parseScale(a, True)
        LayoutAttributeParser.parseAlignment(a, True)

        self._addColorToGroup(a.styleGroup)

        gutter = a.getAsBool(
            TagAttributesEnum.GUTTER,
            None,
            kwargs,
            allowFailure=True
        )
        if gutter:
            gutter = GeneralSizeEnum.small[0]
        else:
            gutter = a.get(
                TagAttributesEnum.GUTTER,
                None,
                kwargs
            )

        maxW = a.get(
            TagAttributesEnum.MAX_WIDE + TagAttributesEnum.SIZE,
            GeneralSizeEnum.medium[0],
            kwargs
        )

        maxW = AttributeUtils.parseSizeEnumValues(
            maxW,
            [48, 64, 80, 92, 102, 160],
            minValue=24,
            maxValue=240,
            asInt=True
        )
        if isinstance(maxW, UnitAttribute):
            maxW.setDefaultUnit(u'')
            if not maxW.unit:
                maxW = u'~' + unicode(maxW.value)
            else:
                maxW = maxW.valueAndUnit
        elif maxW:
            maxW = u'~' + unicode(maxW)

        if maxW:
            a.vdata.add('maxw', maxW)

        if gutter:
            gutter = AttributeUtils.parseSizeEnumValues(
                gutter,
                [0.25, 0.5, 1.0, 1.5, 2.25, 3.0, 4.0],
                minValue=0.0,
                maxValue=5.0,
            )

            if isinstance(gutter, UnitAttribute):
                gutter.setDefaultUnit(u'em')
                gutter = gutter.valueAndUnit
            elif gutter:
                gutter = unicode(gutter) + u'em'

            if gutter:
                a.styles.add('padding', u'0 ' + unicode(gutter))
示例#3
0
    def _renderImpl(self, **kwargs):
        a = self.attrs

        LayoutAttributeParser.parseScale(a, True, kwargs)
        LayoutAttributeParser.parseAlignment(a, True, kwargs)
        LayoutAttributeParser.parsePadding(
            a, True, kwargs, group=a.styleGroup, defaultValue=GeneralSizeEnum.xsmall[0])

        color = a.getAsColorValue(
            TagAttributesEnum.COLOR,
            ArgsUtils.get('colorDef', None, kwargs),
            kwargs)

        if not ArgsUtils.get('skipBorder', False, kwargs):
            LayoutAttributeParser.parseBorder(
                a, True, kwargs,
                group=a.styleGroup,
                defaultColor=ArgsUtils.get(
                    'borderColorDef', color.shiftColors[1] if color else None, kwargs) )

        inline = a.getAsBool(
            TagAttributesEnum.INLINE,
            ArgsUtils.get('inlineDef', None, kwargs),
            kwargs)

        roundness = a.getAsEnumerated(
            TagAttributesEnum.ROUNDNESS,
            GeneralSizeEnum,
            ArgsUtils.get('roundnessDef', GeneralSizeEnum.none, kwargs),
            kwargs)

        #-------------------------------------------------------------------------------------------
        # BACKGROUND COLOR
        if not ArgsUtils.get('skipBackground', False, kwargs):
            if isinstance(color, ColorValue):
                a.styles.add('background-color', color.web, a.styleGroup)
            elif a.explicitAccent or a.themeChanged:
                self.useBackground()

        #-------------------------------------------------------------------------------------------
        # ROUNDNESS
        if roundness == 'xxs':
            r = '0.13em'
        elif roundness == 'xs':
            r = '0.25em'
        elif roundness == 's':
            r = '0.5em'
        elif roundness == 'm':
            r = '0.75em'
        elif roundness == 'l':
            r = '1.0em'
        elif roundness == 'xl':
            r = '1.25em'
        elif roundness == 'xxl':
            r = '1.5em'
        else:
            r = None

        if r:
            a.styles.add('border-radius', r, a.styleGroup)

        if inline:
            a.styles.add('display', 'inline-block')

        a.classes.add('v-gvml-push', a.styleGroup)
示例#4
0
    def _renderImpl(self, **kwargs):
        a = self.attrs

        result = InsertAttributeParser.parseText(self.attrs)
        self.attrs.render['text'] = u'' if not result else result

        self._addColorToGroup(a.styleGroup)
        LayoutAttributeParser.parseScale(a, True, kwargs, useSizeKeys=True)

        if LayoutAttributeParser.parseAlignment(a, True, kwargs) is not None:
            self._renderTemplate = 'markup/divBase.mako'

        bold = a.getAsBool(TagAttributesEnum.BOLD, None)

        italic = a.getAsBool(TagAttributesEnum.ITALIC, None )

        font = a.getAsEnumerated(
            TagAttributesEnum.FONT,
            FontFamilyKeywordEnum,
            None)

        fontFamily = getattr(FontFamilyEnum, font, None) if font else None

        lineSpacing = a.getAsEnumerated(
            TagAttributesEnum.LINE_SPACING + TagAttributesEnum.SPACING,
            GeneralSizeEnum,
            None,
            allowFailure=True)

        if lineSpacing is None:
            lineSpacing = a.getAsUnit(
                TagAttributesEnum.LINE_SPACING + TagAttributesEnum.SPACING,
                None)

        letterSpacing = a.getAsEnumerated(
            TagAttributesEnum.LETTER_SPACING,
            GeneralSizeEnum,
            None,
            allowFailure=True)

        if letterSpacing is None:
            letterSpacing = a.getAsUnit(
                TagAttributesEnum.LETTER_SPACING,
                None)

        wordSpacing = a.getAsEnumerated(
            TagAttributesEnum.WORD_SPACING,
            GeneralSizeEnum,
            None,
            allowFailure=True
        )
        if wordSpacing is None:
            wordSpacing = a.getAsUnit(
                TagAttributesEnum.WORD_SPACING,
                None
            )

        if fontFamily:
            a.styles.add('font-family', fontFamily, a.styleGroup)

        if isinstance(lineSpacing, basestring):
            if lineSpacing == GeneralSizeEnum.xxsmall[0]:
                lineSpacing = '0.6'
            elif lineSpacing == GeneralSizeEnum.xsmall[0]:
                lineSpacing = '0.8'
            elif lineSpacing == GeneralSizeEnum.small[0]:
                lineSpacing = '1.1'
            elif lineSpacing == GeneralSizeEnum.medium[0]:
                lineSpacing = '1.2'
            elif lineSpacing == GeneralSizeEnum.large[0]:
                lineSpacing = '1.5'
            elif lineSpacing == GeneralSizeEnum.xlarge[0]:
                lineSpacing = '2.0'
            elif lineSpacing == GeneralSizeEnum.xxlarge[0]:
                lineSpacing = '2.5'
            else:
                lineSpacing = None
        elif lineSpacing:
            lineSpacing = lineSpacing.value

        if lineSpacing:
            a.styles.add('line-height', lineSpacing, a.styleGroup)

        if isinstance(letterSpacing, basestring):
            if letterSpacing == GeneralSizeEnum.xxsmall[0]:
                letterSpacing = '-2px'
            elif letterSpacing == GeneralSizeEnum.xsmall[0]:
                letterSpacing = '-1px'
            elif letterSpacing == GeneralSizeEnum.small[0]:
                letterSpacing = '0'
            elif letterSpacing == GeneralSizeEnum.medium[0]:
                letterSpacing = '1px'
            elif letterSpacing == GeneralSizeEnum.large[0]:
                letterSpacing = '2px'
            elif letterSpacing == GeneralSizeEnum.xlarge[0]:
                letterSpacing = '3px'
            elif letterSpacing == GeneralSizeEnum.xxlarge[0]:
                letterSpacing = '4px'
            else:
                letterSpacing = None
        elif letterSpacing:
            letterSpacing = letterSpacing.valueAndUnit

        if letterSpacing:
            a.styles.add('letter-spacing', letterSpacing, a.styleGroup)

        if isinstance(wordSpacing, basestring):
            if wordSpacing == GeneralSizeEnum.xxsmall[0]:
                wordSpacing = '-2px'
            elif wordSpacing == GeneralSizeEnum.xsmall[0]:
                wordSpacing = '-1px'
            elif wordSpacing == GeneralSizeEnum.small[0]:
                wordSpacing = '0'
            elif wordSpacing == GeneralSizeEnum.medium[0]:
                wordSpacing = '1px'
            elif wordSpacing == GeneralSizeEnum.large[0]:
                wordSpacing = '2px'
            elif wordSpacing == GeneralSizeEnum.xlarge[0]:
                wordSpacing = '3px'
            elif wordSpacing == GeneralSizeEnum.xxlarge[0]:
                wordSpacing = '4px'
            else:
                wordSpacing = None
        elif wordSpacing:
            wordSpacing = wordSpacing.valueAndUnit

        if wordSpacing:
            a.styles.add('word-spacing', wordSpacing, a.styleGroup)

        if isinstance(bold, bool):
            if bold:
                a.classes.add('sfml-b', a.styleGroup)
            else:
                a.styles.add('font-weight', 'normal', a.styleGroup)

        if isinstance(italic, bool):
            if italic:
                a.classes.add('sfml-i', a.styleGroup)
            else:
                a.styles.add('font-style', 'normal', a.styleGroup)