Skip to content

Commit ce041fd

Browse files
committed
moving string functions into python, py27 and py32 now really work the same
1 parent c5216d7 commit ce041fd

File tree

2 files changed

+25
-67
lines changed

2 files changed

+25
-67
lines changed

PIL/ImageCms.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ def _set(self, profile, filename=None):
153153
self.profile = profile
154154
self.filename = filename
155155
if profile:
156-
self.product_name = profile.product_name
157-
self.product_info = profile.product_info
156+
self.product_name = None #profile.product_name
157+
self.product_info = None #profile.product_info
158158
else:
159159
self.product_name = None
160160
self.product_info = None
@@ -599,12 +599,19 @@ def getProfileName(profile):
599599
# add an extra newline to preserve pyCMS compatibility
600600
if not isinstance(profile, ImageCmsProfile):
601601
profile = ImageCmsProfile(profile)
602-
## print ("get profile name")
603-
## print ("\n".join([profile.profile.product_model,
604-
## profile.profile.product_description,
605-
## profile.profile.product_manufacturer,
606-
## profile.profile.product_copyright]))
607-
return profile.profile.product_name + "\n"
602+
# do it in python, not c.
603+
# // name was "%s - %s" (model, manufacturer) || Description ,
604+
# // but if the Model and Manufacturer were the same or the model
605+
# // was long, Just the model, in 1.x
606+
model = profile.profile.product_model
607+
manufacturer = profile.profile.product_manufacturer
608+
609+
if not (model or manufacturer):
610+
return profile.profile.product_description+"\n"
611+
if not manufacturer or len(model) > 30:
612+
return model + "\n"
613+
return "%s - %s\n" % (model, manufacturer)
614+
608615
except (AttributeError, IOError, TypeError, ValueError) as v:
609616
raise PyCMSError(v)
610617

@@ -632,7 +639,16 @@ def getProfileInfo(profile):
632639
if not isinstance(profile, ImageCmsProfile):
633640
profile = ImageCmsProfile(profile)
634641
# add an extra newline to preserve pyCMS compatibility
635-
return profile.product_info + "\n"
642+
# Python, not C. the white point bits weren't working well, so skipping.
643+
# // info was description \r\n\r\n copyright \r\n\r\n K007 tag \r\n\r\n whitepoint
644+
description = profile.profile.product_description
645+
cpright = profile.profile.product_copyright
646+
arr = []
647+
for elt in (description, cpright):
648+
if elt:
649+
arr.append(elt)
650+
return "\r\n\r\n".join(arr)+"\r\n\r\n"
651+
636652
except (AttributeError, IOError, TypeError, ValueError) as v:
637653
raise PyCMSError(v)
638654

_imagingcms.c

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -524,69 +524,13 @@ _profile_getattr(CmsProfileObject* self, cmsInfoType field)
524524
return PyUnicode_FromString("");
525525
}
526526

527-
static PyObject*
528-
cms_profile_getattr_product_name(CmsProfileObject* self, void* closure)
529-
{
530-
// name was "%s - %s" (model, manufacturer) || Description ,
531-
// but if the Model and Manufacturer were the same or the model
532-
// was long, Just the model, in 1.x
533-
PyObject *model = _profile_getattr(self, cmsInfoModel);
534-
PyObject *manufacturer = _profile_getattr(self, cmsInfoManufacturer);
535-
PyObject *result;
536-
537-
if (!PyUnicode_GetSize(model) && !PyUnicode_GetSize(manufacturer)){
538-
return _profile_getattr(self, cmsInfoDescription);
539-
}
540-
if (!PyUnicode_GetSize(manufacturer) || PyUnicode_GetSize(model)> 30){
541-
return model;
542-
}
543-
result = PyUnicode_Concat(model,
544-
PyUnicode_FromString(" - "));
545-
result = PyUnicode_Concat(result,_profile_getattr(self, cmsInfoManufacturer));
546-
return result;
547-
}
548-
549527
static PyObject*
550528
cms_profile_getattr_product_desc(CmsProfileObject* self, void* closure)
551529
{
552530
// description was Description != 'Copyright' || or "%s - %s" (manufacturer, model) in 1.x
553531
return _profile_getattr(self, cmsInfoDescription);
554532
}
555533

556-
void _info_concat(PyObject **ret, PyObject *elt){
557-
if (PyUnicode_GetSize(elt)){
558-
*ret = PyUnicode_Concat(*ret, elt);
559-
*ret = PyUnicode_Concat(*ret, PyUnicode_FromString("\r\n\r\n"));
560-
}
561-
}
562-
563-
static PyObject*
564-
cms_profile_getattr_product_info(CmsProfileObject* self, void* closure)
565-
{
566-
// info was description \r\n\r\n copyright \r\n\r\n K007 tag \r\n\r\n whitepoint
567-
PyObject *description = _profile_getattr(self, cmsInfoDescription);
568-
PyObject *copyright = _profile_getattr(self, cmsInfoCopyright);
569-
PyObject *ret = PyUnicode_FromString("");
570-
571-
_info_concat(&ret, description);
572-
_info_concat(&ret, copyright);
573-
574-
if (cmsIsTag(self->profile, cmsSigMediaWhitePointTag)){
575-
cmsCIEXYZ *WhitePt;
576-
cmsCIExyY xyyWhitePt;
577-
cmsFloat64Number tempK;
578-
579-
WhitePt = (cmsCIEXYZ *) cmsReadTag(self->profile, cmsSigMediaWhitePointTag);
580-
cmsXYZ2xyY(&xyyWhitePt, WhitePt);
581-
if (cmsTempFromWhitePoint(&tempK, &xyyWhitePt)){
582-
char tempstr[10];
583-
snprintf(tempstr, 10, "%5.0f", tempK);
584-
_info_concat(&ret, PyUnicode_FromFormat("White Point: %sK", tempstr));
585-
}
586-
}
587-
return ret;
588-
}
589-
590534
/* use these four for the individual fields.
591535
*/
592536
static PyObject*
@@ -633,9 +577,7 @@ cms_profile_getattr_color_space(CmsProfileObject* self, void* closure)
633577

634578
/* FIXME: add more properties (creation_datetime etc) */
635579
static struct PyGetSetDef cms_profile_getsetters[] = {
636-
{ "product_name", (getter) cms_profile_getattr_product_name },
637580
{ "product_desc", (getter) cms_profile_getattr_product_desc },
638-
{ "product_info", (getter) cms_profile_getattr_product_info },
639581
{ "product_description", (getter) cms_profile_getattr_product_description },
640582
{ "product_manufacturer", (getter) cms_profile_getattr_product_manufacturer },
641583
{ "product_model", (getter) cms_profile_getattr_product_model },

0 commit comments

Comments
 (0)