mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 01:46:18 +03:00
moving string functions into python, py27 and py32 now really work the same
This commit is contained in:
parent
c5216d79c2
commit
ce041fd199
|
@ -153,8 +153,8 @@ class ImageCmsProfile:
|
|||
self.profile = profile
|
||||
self.filename = filename
|
||||
if profile:
|
||||
self.product_name = profile.product_name
|
||||
self.product_info = profile.product_info
|
||||
self.product_name = None #profile.product_name
|
||||
self.product_info = None #profile.product_info
|
||||
else:
|
||||
self.product_name = None
|
||||
self.product_info = None
|
||||
|
@ -599,12 +599,19 @@ def getProfileName(profile):
|
|||
# add an extra newline to preserve pyCMS compatibility
|
||||
if not isinstance(profile, ImageCmsProfile):
|
||||
profile = ImageCmsProfile(profile)
|
||||
## print ("get profile name")
|
||||
## print ("\n".join([profile.profile.product_model,
|
||||
## profile.profile.product_description,
|
||||
## profile.profile.product_manufacturer,
|
||||
## profile.profile.product_copyright]))
|
||||
return profile.profile.product_name + "\n"
|
||||
# do it in python, not c.
|
||||
# // name was "%s - %s" (model, manufacturer) || Description ,
|
||||
# // but if the Model and Manufacturer were the same or the model
|
||||
# // was long, Just the model, in 1.x
|
||||
model = profile.profile.product_model
|
||||
manufacturer = profile.profile.product_manufacturer
|
||||
|
||||
if not (model or manufacturer):
|
||||
return profile.profile.product_description+"\n"
|
||||
if not manufacturer or len(model) > 30:
|
||||
return model + "\n"
|
||||
return "%s - %s\n" % (model, manufacturer)
|
||||
|
||||
except (AttributeError, IOError, TypeError, ValueError) as v:
|
||||
raise PyCMSError(v)
|
||||
|
||||
|
@ -632,7 +639,16 @@ def getProfileInfo(profile):
|
|||
if not isinstance(profile, ImageCmsProfile):
|
||||
profile = ImageCmsProfile(profile)
|
||||
# add an extra newline to preserve pyCMS compatibility
|
||||
return profile.product_info + "\n"
|
||||
# Python, not C. the white point bits weren't working well, so skipping.
|
||||
# // info was description \r\n\r\n copyright \r\n\r\n K007 tag \r\n\r\n whitepoint
|
||||
description = profile.profile.product_description
|
||||
cpright = profile.profile.product_copyright
|
||||
arr = []
|
||||
for elt in (description, cpright):
|
||||
if elt:
|
||||
arr.append(elt)
|
||||
return "\r\n\r\n".join(arr)+"\r\n\r\n"
|
||||
|
||||
except (AttributeError, IOError, TypeError, ValueError) as v:
|
||||
raise PyCMSError(v)
|
||||
|
||||
|
|
|
@ -524,28 +524,6 @@ _profile_getattr(CmsProfileObject* self, cmsInfoType field)
|
|||
return PyUnicode_FromString("");
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
cms_profile_getattr_product_name(CmsProfileObject* self, void* closure)
|
||||
{
|
||||
// name was "%s - %s" (model, manufacturer) || Description ,
|
||||
// but if the Model and Manufacturer were the same or the model
|
||||
// was long, Just the model, in 1.x
|
||||
PyObject *model = _profile_getattr(self, cmsInfoModel);
|
||||
PyObject *manufacturer = _profile_getattr(self, cmsInfoManufacturer);
|
||||
PyObject *result;
|
||||
|
||||
if (!PyUnicode_GetSize(model) && !PyUnicode_GetSize(manufacturer)){
|
||||
return _profile_getattr(self, cmsInfoDescription);
|
||||
}
|
||||
if (!PyUnicode_GetSize(manufacturer) || PyUnicode_GetSize(model)> 30){
|
||||
return model;
|
||||
}
|
||||
result = PyUnicode_Concat(model,
|
||||
PyUnicode_FromString(" - "));
|
||||
result = PyUnicode_Concat(result,_profile_getattr(self, cmsInfoManufacturer));
|
||||
return result;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
cms_profile_getattr_product_desc(CmsProfileObject* self, void* closure)
|
||||
{
|
||||
|
@ -553,40 +531,6 @@ cms_profile_getattr_product_desc(CmsProfileObject* self, void* closure)
|
|||
return _profile_getattr(self, cmsInfoDescription);
|
||||
}
|
||||
|
||||
void _info_concat(PyObject **ret, PyObject *elt){
|
||||
if (PyUnicode_GetSize(elt)){
|
||||
*ret = PyUnicode_Concat(*ret, elt);
|
||||
*ret = PyUnicode_Concat(*ret, PyUnicode_FromString("\r\n\r\n"));
|
||||
}
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
cms_profile_getattr_product_info(CmsProfileObject* self, void* closure)
|
||||
{
|
||||
// info was description \r\n\r\n copyright \r\n\r\n K007 tag \r\n\r\n whitepoint
|
||||
PyObject *description = _profile_getattr(self, cmsInfoDescription);
|
||||
PyObject *copyright = _profile_getattr(self, cmsInfoCopyright);
|
||||
PyObject *ret = PyUnicode_FromString("");
|
||||
|
||||
_info_concat(&ret, description);
|
||||
_info_concat(&ret, copyright);
|
||||
|
||||
if (cmsIsTag(self->profile, cmsSigMediaWhitePointTag)){
|
||||
cmsCIEXYZ *WhitePt;
|
||||
cmsCIExyY xyyWhitePt;
|
||||
cmsFloat64Number tempK;
|
||||
|
||||
WhitePt = (cmsCIEXYZ *) cmsReadTag(self->profile, cmsSigMediaWhitePointTag);
|
||||
cmsXYZ2xyY(&xyyWhitePt, WhitePt);
|
||||
if (cmsTempFromWhitePoint(&tempK, &xyyWhitePt)){
|
||||
char tempstr[10];
|
||||
snprintf(tempstr, 10, "%5.0f", tempK);
|
||||
_info_concat(&ret, PyUnicode_FromFormat("White Point: %sK", tempstr));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* use these four for the individual fields.
|
||||
*/
|
||||
static PyObject*
|
||||
|
@ -633,9 +577,7 @@ cms_profile_getattr_color_space(CmsProfileObject* self, void* closure)
|
|||
|
||||
/* FIXME: add more properties (creation_datetime etc) */
|
||||
static struct PyGetSetDef cms_profile_getsetters[] = {
|
||||
{ "product_name", (getter) cms_profile_getattr_product_name },
|
||||
{ "product_desc", (getter) cms_profile_getattr_product_desc },
|
||||
{ "product_info", (getter) cms_profile_getattr_product_info },
|
||||
{ "product_description", (getter) cms_profile_getattr_product_description },
|
||||
{ "product_manufacturer", (getter) cms_profile_getattr_product_manufacturer },
|
||||
{ "product_model", (getter) cms_profile_getattr_product_model },
|
||||
|
|
Loading…
Reference in New Issue
Block a user