Beispiel #1
0
def CMY_to_CMYK(cobj, *args, **kwargs):
    """
    Converts from CMY to CMYK.

    NOTE: CMYK and CMY values range from 0.0 to 1.0
    """
    var_k = 1.0
    if cobj.cmy_c < var_k:
        var_k = cobj.cmy_c
    if cobj.cmy_m < var_k:
        var_k = cobj.cmy_m
    if cobj.cmy_y < var_k:
        var_k = cobj.cmy_y

    if var_k == 1:
        cmyk_c = 0.0
        cmyk_m = 0.0
        cmyk_y = 0.0
    else:
        cmyk_c = (cobj.cmy_c - var_k) / (1.0 - var_k)
        cmyk_m = (cobj.cmy_m - var_k) / (1.0 - var_k)
        cmyk_y = (cobj.cmy_y - var_k) / (1.0 - var_k)
    cmyk_k = var_k

    return CMYKColor(cmyk_c, cmyk_m, cmyk_y, cmyk_k)
Beispiel #2
0
def openSwatch_CDPAL(file: str) -> ColourSwatch:
    """ Open a CorelDraw .PAL into a colour swatch """
    with open(file) as fileData:
        if fileData.readlines()[0].strip() == "JASC-PAL":
            return openSwatch_PSPPAL(file)
    with open(file) as fileData:
        colours = []
        for line in fileData.readlines():
            parts = split(line)
            colours.append(
                Colour(
                    parts[0],
                    colour=CMYKColor(*[float(col) / 100
                                       for col in parts[1:5]])))
    return getSwatchFromFileName(file, colours)
Beispiel #3
0
def openSwatch_ACBL(file: str) -> ColourSwatch:
    """ Open a .ACBL into a colour swatch """
    with open(file) as fileData:
        xmlrep = parse(fileData).getroot()
        cType = xmlrep[1][0].attrib["ColorSpace"]
        colours = []
        for colour in xmlrep[2]:
            cName = colour.attrib["N"]
            cRawColour = [float(col) for col in colour[0].text.split(None)]
            if cType == "CMYK":
                cColour = CMYKColor(*cRawColour)
            elif cType == "RGB":
                cColour = sRGBColor(*cRawColour)
            else:
                cColour = LabColor(*cRawColour)
            colours.append(Colour(cName, cColour))
    return getSwatchFromFileName(file, colours)
Beispiel #4
0
def openSwatch_XML(file: str) -> ColourSwatch:
    """ Open a .XML into a colour swatch """
    with open(file) as fileData:
        xmlrep = parse(fileData).getroot()
        colours = []
        for colour in xmlrep:
            cName = colour.attrib["NAME"]
            col = colour.attrib["RGB"][
                1:] if "RGB" in colour.attrib else colour.attrib["CMYK"][1:]
            cColour = sRGBColor(int(col[0:2], 16), int(col[2:4], 16),
                                int(col[4:6], 16),
                                True) if "RGB" in colour.attrib else CMYKColor(
                                    int(col[0:2], 16) / 255,
                                    int(col[2:4], 16) / 255,
                                    int(col[4:6], 16) / 255,
                                    int(col[6:8], 16) / 255)
            colours.append(Colour(cName, cColour))
    return ColourSwatch(xmlrep.attrib["Name"], colours)
Beispiel #5
0
def read_jsonline(fname):
    colors = []
    with open(fname) as f:
        for line in f.readlines():
            row = json.loads(line)
            c, m, y, k = [ float(row[s])/100.0 for s in ['c', 'm', 'y', 'k'] ]
            cmyk_color = CMYKColor(c, m, y, k)
            lab_color = convert_color(cmyk_color, LabColor)
            hsv_color = convert_color(cmyk_color, HSVColor)
            hue_key, value_key = hsv_keys(hsv_color.hsv_h, hsv_color.hsv_s, hsv_color.hsv_v)
            r, g, b = [ int(row[s]) for s in ['r', 'g', 'b'] ]
            rgb = '#{0:02x}{1:02x}{2:02x}'.format(r, g, b)
            color = NamedColor(row['identifier'], [ row['name'] ],
                lab_color, rgb, hue_key, value_key)
            colors.append(color)
    if ORDER_BY_VALUE:
        return sorted(colors, key = lambda x: x.value_key)
    else:
        return sorted(colors, key = lambda x: x.hue_key)
Beispiel #6
0
def openSwatch_SKP(file: str) -> ColourSwatch:
    """ Open a .SKP into a colour swatch """
    with open(file) as fileData:
        xmlrep = parse(fileData).getroot()
        cType = xmlrep[0].attrib["type"]
        colours = []
        for colour in xmlrep[1:]:
            cName = colour.attrib["name"]
            if cType == "CMYK":
                cColour = CMYKColor(float(colour.attrib["c"]),
                                    float(colour.attrib["m"]),
                                    float(colour.attrib["y"]),
                                    float(colour.attrib["k"]))
            else:
                cColour = sRGBColor(float(colour.attrib["r"]),
                                    float(colour.attrib["g"]),
                                    float(colour.attrib["b"]))
            colours.append(Colour(cName, cColour))
    return ColourSwatch(xmlrep[0].attrib["name"], colours)
Beispiel #7
0
def openSwatch_ASE(file: str) -> ColourSwatch:
    """ Open an .ase into a list of colour swatches """
    project = swatch.parse(file)
    swatches = []
    for swtch in project:
        colours = []
        for colour in swtch["swatches"]:
            if colour["data"]["mode"] == "LAB":
                col = LabColor(*colour["data"]["values"])
            elif colour["data"]["mode"] == "RGB":
                col = sRGBColor(*colour["data"]["values"])
            elif colour["data"]["mode"] == "CMYK":
                col = CMYKColor(*colour["data"]["values"])
            else:
                col = sRGBColor(colour["data"]["values"][0],
                                colour["data"]["values"][0],
                                colour["data"]["values"][0])
            colours.append(Colour(colour["name"], colour=col))
        swatches.append(ColourSwatch(swtch["name"], colours))
    return swatches
Beispiel #8
0
#for i in range(len(g)):
#    print (gdpcolor[i]*100,g[i])
zupssgdpp = {
    data["zupanije"][g[i]]["code"]: gdpcolor[i]
    for i in range(len(g))
}

#pprint(zupssgdpp)

for i in range(len(stylecss)):

    #if stylecss[i].prelude[0].value in sthrk:
    #stylecss[i].prelude[0].value=sthrk[stylecss[i].prelude[0].value]
    #print(stylecss[i].content[10])
    if "HR03" in stylecss[i].prelude[0].value:
        cmik = CMYKColor(1, 0.5, 0,
                         1 * zupssgdpp[stylecss[i].prelude[0].value[0:5]])
        hexana = convert_color(cmik, sRGBColor).get_rgb_hex().upper().replace(
            "#", "")
        stylecss[i].content[10].value = hexana
        #0080FF
    if "HR04" in stylecss[i].prelude[0].value:
        cmik = CMYKColor(0, 0.5, 1,
                         1 * zupssgdpp[stylecss[i].prelude[0].value[0:5]])
        hexana = convert_color(cmik, sRGBColor).get_rgb_hex().upper().replace(
            "#", "")
        stylecss[i].content[10].value = hexana
        #FF8000
    #print(i)

#for i in range(len(stylecss)):
#	print(stylecss[i].prelude[1].value)
Beispiel #9
0
 def setUp(self):
     self.color = CMYKColor(0.385, 0.000, 0.750, 0.216)
Beispiel #10
0
 def test_conversion_to_cmyk(self):
     cmyk = convert_color(self.color, CMYKColor)
     self.assertColorMatch(cmyk, CMYKColor(0.385, 0.000, 0.750, 0.216))
Beispiel #11
0
for i in gdp:
    gdpcolor.append(round((i - min(gdp)) / (max(gdp) - min(gdp)) * 0.70, 3))
# for i in range(len(g)):
#    print (gdpcolor[i]*100,g[i])
zupssgdpp = {
    data["zupanije"][g[i]]["code"]: gdpcolor[i]
    for i in range(len(g))
}

# pprint(zupssgdpp)

for i in stylecss:

    if "HR03" in i.selectorText:

        cmik = CMYKColor(1, 0.5, 0, 1 * zupssgdpp[i.selectorText[1:6]])
        hexana = convert_color(
            cmik, sRGBColor).get_rgb_hex().upper()  # .replace("#", "")

        i.style['fill'] = hexana

    elif "HR04" in i.selectorText:

        cmik = CMYKColor(0, 0.5, 1, 1 * zupssgdpp[i.selectorText[1:6]])
        hexana = convert_color(
            cmik, sRGBColor).get_rgb_hex().upper()  # .replace("#", "")

        i.style['fill'] = hexana

doc.getElementsByTagName(
    "style")[0].firstChild.nodeValue = stylecss.cssText.decode('utf-8')