예제 #1
0
def _convert_emote(name, suffix, raw_emote):
    css = raw_emote.css.copy()

    for (prop, expected_value) in [("display", "block"), ("float", "left")]:
        if prop not in css:
            print("WARNING: %r is missing %r property" % (bplib.combine_name_pair(name, suffix), prop))
        else:
            if css[prop] != expected_value:
                print("WARNING: %r has unexpected value %r for property %r (expected %r)" % (
                    bplib.combine_name_pair(name, suffix), css[prop], prop, expected_value))

            del css[prop]

    width = bplib.css.as_size(css.pop("width"))
    height = bplib.css.as_size(css.pop("height"))
    size = (width, height)
    image_url = bplib.css.as_url(css.pop("background-image"))

    if "background-position" in css:
        offset = bplib.css.as_position(css.pop("background-position"), width, height)
    else:
        offset = (0, 0)

    for p in ("background-repeat", "clear"):
        # Commonly added useless properties that we want to ignore
        if p in css:
            del css[p]

    for p in css:
        print("WARNING: emote %r has unknown extra property %r (%r)" % (bplib.combine_name_pair(name, suffix), p, css[p]))

    return bplib.objects.NormalEmote(name, suffix, css, image_url, size, offset)
예제 #2
0
파일: extract.py 프로젝트: nano23823/bpm
def _convert_emote(name, suffix, block):
    css = block.css.copy()

    for (prop, expected_value) in [("float", "left")]:
        if prop not in css:
            print("WARNING: %r is missing %r property" %
                  (bplib.combine_name_pair(name, suffix), prop))
        else:
            if css[prop] != expected_value:
                print(
                    "WARNING: %r has unexpected value %r for property %r (expected %r)"
                    % (bplib.combine_name_pair(
                        name, suffix), css[prop], prop, expected_value))

            del css[prop]

    width = bplib.css.as_size(css.pop("width"))
    height = bplib.css.as_size(css.pop("height"))
    size = (width, height)

    # TODO: Handle this better. I think CSS dictates that the last one present
    # wins out, but we don't have that information.
    images = []
    if "background-image" in css:
        images.append(bplib.css.as_url(css.pop("background-image")))
    if "background" in css:
        # Ignore all but the url() bit we're looking for. Properly parsing the
        # entire declaration would be a fair bit of work.
        parts = css.pop("background").split()
        for p in parts:
            if p.startswith("url("):
                images.append(bplib.css.as_url(p))
                break
    if len(images) != 1:
        print(
            "WARNING: %r has multiple background images: using first of (%r)" %
            (bplib.combine_name_pair(name, suffix), images))
    image_url = images[0]

    if "background-position" in css:
        offset = bplib.css.as_position(css.pop("background-position"), width,
                                       height)
    else:
        offset = (0, 0)

    for p in ("background-repeat", "clear", "display"):
        # Commonly added useless properties that we want to ignore
        if p in css:
            del css[p]

    for p in css:
        if p not in IGNORED_PROPERTIES:
            print("WARNING: emote %r has unknown extra property %r (%r)" %
                  (bplib.combine_name_pair(name, suffix), p, css[p]))

    return bplib.objects.NormalVariant(name, suffix, image_url, size, offset,
                                       css)
예제 #3
0
파일: extract.py 프로젝트: killjoy1221/bpm
def _convert_emote(name, suffix, block):
    css = block.css.copy()

    for (prop, expected_value) in [("float", "left")]:
        if prop not in css:
            print("WARNING: %r is missing %r property" % (bplib.combine_name_pair(name, suffix), prop))
        else:
            if css[prop] != expected_value:
                print("WARNING: %r has unexpected value %r for property %r (expected %r)" % (
                    bplib.combine_name_pair(name, suffix), css[prop], prop, expected_value))

            del css[prop]

    width = bplib.css.as_size(css.pop("width"))
    height = bplib.css.as_size(css.pop("height"))
    size = (width, height)

    # TODO: Handle this better. I think CSS dictates that the last one present
    # wins out, but we don't have that information.
    images = []
    if "background-image" in css:
        images.append(bplib.css.as_url(css.pop("background-image")))
    if "background" in css:
        # Ignore all but the url() bit we're looking for. Properly parsing the
        # entire declaration would be a fair bit of work.
        parts = css.pop("background").split()
        for p in parts:
            if p.startswith("url("):
                images.append(bplib.css.as_url(p))
                break
    if len(images) != 1:
        print("WARNING: %r has multiple background images: using first of (%r)" % (bplib.combine_name_pair(name, suffix), images))
    image_url = images[0]

    if "background-position" in css:
        offset = bplib.css.as_position(css.pop("background-position"), width, height)
    else:
        offset = (0, 0)

    for p in ("background-repeat", "clear", "display"):
        # Commonly added useless properties that we want to ignore
        if p in css:
            del css[p]

    for p in css:
        if p not in IGNORED_PROPERTIES:
            print("WARNING: emote %r has unknown extra property %r (%r)" % (bplib.combine_name_pair(name, suffix), p, css[p]))

    return bplib.objects.NormalVariant(name, suffix, image_url, size, offset, css)