Esempio n. 1
0
    def parseSizeEnumValues(cls, source, values, minValue =None, maxValue =None, noneValue =None,
                            asInt =False):
        if source is None:
            return None

        source, bends = AttributeUtils.getValueAndBendCount(source)
        source = source.lower().replace(u' ', u'')

        if minValue is None:
            minValue = max(0.0, float(values[0]) - (float(values[1]) - float(values[0])))

        if maxValue is None:
            maxValue = float(values[-1]) + (float(values[-1]) - float(values[-2]))

        if source in GeneralSizeEnum.xxsmall[1]:
            p = cls.bendValue(
                values[0], bends, minValue, values[1], asInt=asInt
            )
        elif source in GeneralSizeEnum.xsmall[1]:
            p = cls.bendValue(
                values[1], bends, values[0], values[2], asInt=asInt
            )
        elif source in GeneralSizeEnum.small[1]:
            p = cls.bendValue(
                values[2], bends, values[1], values[3], asInt=asInt
            )
        elif source in GeneralSizeEnum.medium[1]:
            p = cls.bendValue(
                values[3], bends, values[2], values[4], asInt=asInt
            )
        elif source in GeneralSizeEnum.large[1]:
            p = cls.bendValue(
                values[4], bends, values[3], values[5], asInt=asInt
            )
        elif source in GeneralSizeEnum.xlarge[1]:
            p = cls.bendValue(
                values[5], bends, values[4], values[6], asInt=asInt
            )
        elif source in GeneralSizeEnum.xxlarge[1]:
            p = cls.bendValue(
                values[6], bends, values[5], maxValue
            )
        elif source in GeneralSizeEnum.none[1]:
            if bends > 0:
                p = cls.bendValue(
                    minValue, bends, minValue, values[0])
            else:
                p = noneValue
        elif source:
            p = UnitAttribute.createIfValid(source, unitType=(int if asInt else float))
        else:
            p = None

        return p
Esempio n. 2
0
    def parseScale(cls, attrs, apply =False, overrides =None, extract =False, useSizeKeys =False,
                   group =None):
        """Doc..."""

        if useSizeKeys:
            keys = TagAttributesEnum.SCALE +  TagAttributesEnum.SIZE
        else:
            keys = TagAttributesEnum.SCALE

        size = attrs.get(keys, None, overrides)

        if size:
            size, bends = AttributeUtils.getValueAndBendCount(size)

            if size.isdigit():
                size = unicode(size) + u'em'
            else:
                sizeUnit = UnitAttribute.createIfValid(size, defaultUnit='em')
                if sizeUnit:
                    size = unicode(sizeUnit.valueAndUnit)
                    attrs.styles.add('font-size', size)
                else:
                    size = AttributeUtils.getAsTShirtEnum(size)
                    if size == GeneralSizeEnum.xxsmall[0]:
                        size = unicode(AttributeUtils.bendValue(0.6, bends, 0.2, 0.8)) + u'em'
                    elif size == GeneralSizeEnum.xsmall[0]:
                        size = unicode(AttributeUtils.bendValue(0.8, bends, 0.6, 1.0)) + u'em'
                    elif size == GeneralSizeEnum.small[0]:
                        size = unicode(AttributeUtils.bendValue(1.0, bends, 0.8, 1.2)) + u'em'
                    elif size == GeneralSizeEnum.medium[0]:
                        size = unicode(AttributeUtils.bendValue(1.2, bends, 1.0, 1.5)) + u'em'
                    elif size == GeneralSizeEnum.large[0]:
                        size = unicode(AttributeUtils.bendValue(1.5, bends, 1.2, 1.8)) + u'em'
                    elif size == GeneralSizeEnum.xlarge[0]:
                        size = unicode(AttributeUtils.bendValue(1.8, bends, 1.5, 2.2)) + u'em'
                    elif size == GeneralSizeEnum.xxlarge[0]:
                        size = unicode(AttributeUtils.bendValue(2.2, bends, 1.8, 3.0)) + u'em'
                    else:
                        size = None

            if size and apply:
                attrs.styles.add('font-size', size, group)

        if extract:
            attrs.remove(keys)

        return size
Esempio n. 3
0
    def parseBorder(cls, attrs, apply =False, overrides =None, extract =False, group =None,
                    defaultColor =None):
        keys = TagAttributesEnum.BORDER

        borderColor = None
        borderSize  = None
        borderStyle = None

        useBorder = attrs.getAsBool(keys, None, overrides, True)
        if useBorder is None:
            border = attrs.get(keys, None, overrides)
            if not border:
                useBorder = False
            else:
                useBorder = True

                if not isinstance(border, list):
                    border = [border]

                for item in border:
                    if borderSize is None:
                        unitItem = UnitAttribute.createIfValid(item, 'px')
                        if unitItem:
                            borderSize = unitItem.valueAndUnit
                            continue

                    if borderStyle is None:
                        found =False
                        for lineType in Reflection.getReflectionList(LineTypesEnum):
                            if item in lineType[1]:
                                borderStyle = lineType[0]
                                found       = True
                                break
                        if found:
                            continue

                    if borderColor is None:
                        color = attrs.convertToColorValue(item, None)
                        if color:
                            borderColor = color

        if extract:
            attrs.remove(keys)

        if not useBorder:
            return None

        if borderColor is None:
            if defaultColor is None:
                borderColor = attrs.backColors.borderColor.web
            elif isinstance(defaultColor, ColorValue):
                borderColor = defaultColor.web
            else:
                borderColor = defaultColor
        else:
            borderColor = borderColor.web

        border = u' '.join([
            borderSize if borderSize else '1px',
            borderStyle if borderStyle else 'solid',
            borderColor
        ])

        if apply:
            attrs.styles.add('border', border, group)

        return border