Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# https://www.microsoft.com/typography/otspec/recom.htm
versionMajor = getAttrWithFallback(font.info, "versionMajor")
versionMinor = getAttrWithFallback(font.info, "versionMinor")
fullFontRevision = float("%d.%03d" % (versionMajor, versionMinor))
head.fontRevision = round(fullFontRevision, 3)
if head.fontRevision != fullFontRevision:
logger.warning(
"Minor version in %s has too many digits and won't fit into "
"the head table's fontRevision field; rounded to %s.",
fullFontRevision, head.fontRevision)
# upm
head.unitsPerEm = getAttrWithFallback(font.info, "unitsPerEm")
# times
head.created = dateStringToTimeValue(getAttrWithFallback(font.info, "openTypeHeadCreated")) - mac_epoch_diff
head.modified = dateStringToTimeValue(dateStringForNow()) - mac_epoch_diff
# bounding box
xMin, yMin, xMax, yMax = self.fontBoundingBox
head.xMin = xMin
head.yMin = yMin
head.xMax = xMax
head.yMax = yMax
# style mapping
styleMapStyleName = getAttrWithFallback(font.info, "styleMapStyleName")
macStyle = []
if styleMapStyleName == "bold":
macStyle = [0]
elif styleMapStyleName == "bold italic":
macStyle = [0, 1]
versionMajor = getAttrWithFallback(font.info, "versionMajor")
versionMinor = getAttrWithFallback(font.info, "versionMinor")
fullFontRevision = float("%d.%03d" % (versionMajor, versionMinor))
head.fontRevision = round(fullFontRevision, 3)
if head.fontRevision != fullFontRevision:
logger.warning(
"Minor version in %s has too many digits and won't fit into "
"the head table's fontRevision field; rounded to %s.",
fullFontRevision, head.fontRevision)
# upm
head.unitsPerEm = getAttrWithFallback(font.info, "unitsPerEm")
# times
head.created = dateStringToTimeValue(getAttrWithFallback(font.info, "openTypeHeadCreated")) - mac_epoch_diff
head.modified = dateStringToTimeValue(dateStringForNow()) - mac_epoch_diff
# bounding box
xMin, yMin, xMax, yMax = self.fontBoundingBox
head.xMin = xMin
head.yMin = yMin
head.xMax = xMax
head.yMax = yMax
# style mapping
styleMapStyleName = getAttrWithFallback(font.info, "styleMapStyleName")
macStyle = []
if styleMapStyleName == "bold":
macStyle = [0]
elif styleMapStyleName == "bold italic":
macStyle = [0, 1]
elif styleMapStyleName == "italic":
"Minor version in %s has too many digits and won't fit into "
"the head table's fontRevision field; rounded to %s.",
fullFontRevision, head.fontRevision)
# upm
head.unitsPerEm = round(getAttrWithFallback(font.info, "unitsPerEm"))
# times
head.created = dateStringToTimeValue(getAttrWithFallback(font.info, "openTypeHeadCreated")) - mac_epoch_diff
source_date_epoch = os.environ.get("SOURCE_DATE_EPOCH")
if self.modifiedTime is not None:
head.modified = dateStringToTimeValue(self.modifiedTime) - mac_epoch_diff
elif source_date_epoch is not None:
head.modified = int(source_date_epoch) - mac_epoch_diff
else:
head.modified = dateStringToTimeValue(dateStringForNow()) - mac_epoch_diff
# bounding box
xMin, yMin, xMax, yMax = self.fontBoundingBox
head.xMin = round(xMin)
head.yMin = round(yMin)
head.xMax = round(xMax)
head.yMax = round(yMax)
# style mapping
styleMapStyleName = getAttrWithFallback(font.info, "styleMapStyleName")
macStyle = []
if styleMapStyleName == "bold":
macStyle = [0]
elif styleMapStyleName == "bold italic":
macStyle = [0, 1]
elif styleMapStyleName == "italic":
fullFontRevision = float("%d.%03d" % (versionMajor, versionMinor))
head.fontRevision = round(fullFontRevision, 3)
if head.fontRevision != fullFontRevision:
logger.warning(
"Minor version in %s has too many digits and won't fit into "
"the head table's fontRevision field; rounded to %s.",
fullFontRevision, head.fontRevision)
# upm
head.unitsPerEm = round(getAttrWithFallback(font.info, "unitsPerEm"))
# times
head.created = dateStringToTimeValue(getAttrWithFallback(font.info, "openTypeHeadCreated")) - mac_epoch_diff
source_date_epoch = os.environ.get("SOURCE_DATE_EPOCH")
if self.modifiedTime is not None:
head.modified = dateStringToTimeValue(self.modifiedTime) - mac_epoch_diff
elif source_date_epoch is not None:
head.modified = int(source_date_epoch) - mac_epoch_diff
else:
head.modified = dateStringToTimeValue(dateStringForNow()) - mac_epoch_diff
# bounding box
xMin, yMin, xMax, yMax = self.fontBoundingBox
head.xMin = round(xMin)
head.yMin = round(yMin)
head.xMax = round(xMax)
head.yMax = round(yMax)
# style mapping
styleMapStyleName = getAttrWithFallback(font.info, "styleMapStyleName")
macStyle = []
if styleMapStyleName == "bold":
# https://www.microsoft.com/typography/otspec/recom.htm
versionMajor = getAttrWithFallback(font.info, "versionMajor")
versionMinor = getAttrWithFallback(font.info, "versionMinor")
fullFontRevision = float("%d.%03d" % (versionMajor, versionMinor))
head.fontRevision = round(fullFontRevision, 3)
if head.fontRevision != fullFontRevision:
logger.warning(
"Minor version in %s has too many digits and won't fit into "
"the head table's fontRevision field; rounded to %s.",
fullFontRevision, head.fontRevision)
# upm
head.unitsPerEm = round(getAttrWithFallback(font.info, "unitsPerEm"))
# times
head.created = dateStringToTimeValue(getAttrWithFallback(font.info, "openTypeHeadCreated")) - mac_epoch_diff
source_date_epoch = os.environ.get("SOURCE_DATE_EPOCH")
if self.modifiedTime is not None:
head.modified = dateStringToTimeValue(self.modifiedTime) - mac_epoch_diff
elif source_date_epoch is not None:
head.modified = int(source_date_epoch) - mac_epoch_diff
else:
head.modified = dateStringToTimeValue(dateStringForNow()) - mac_epoch_diff
# bounding box
xMin, yMin, xMax, yMax = self.fontBoundingBox
head.xMin = round(xMin)
head.yMin = round(yMin)
head.xMax = round(xMax)
head.yMax = round(yMax)
# style mapping
# limit minor version to 3 digits as recommended in OpenType spec:
# https://www.microsoft.com/typography/otspec/recom.htm
versionMajor = getAttrWithFallback(font.info, "versionMajor")
versionMinor = getAttrWithFallback(font.info, "versionMinor")
fullFontRevision = float("%d.%03d" % (versionMajor, versionMinor))
head.fontRevision = round(fullFontRevision, 3)
if head.fontRevision != fullFontRevision:
print("Minor version in %s has too many digits and won't fit into "
"the head table's fontRevision field; rounded to %s." %
(fullFontRevision, head.fontRevision))
# upm
head.unitsPerEm = getAttrWithFallback(font.info, "unitsPerEm")
# times
head.created = dateStringToTimeValue(getAttrWithFallback(font.info, "openTypeHeadCreated")) - mac_epoch_diff
head.modified = dateStringToTimeValue(dateStringForNow()) - mac_epoch_diff
# bounding box
xMin, yMin, xMax, yMax = self.fontBoundingBox
head.xMin = xMin
head.yMin = yMin
head.xMax = xMax
head.yMax = yMax
# style mapping
styleMapStyleName = getAttrWithFallback(font.info, "styleMapStyleName")
macStyle = []
if styleMapStyleName == "bold":
macStyle = [0]
elif styleMapStyleName == "bold italic":
macStyle = [0, 1]