renamed several items to use camelCase

git-svn-id: svn://svn.code.sf.net/p/fonttools/code/trunk@220 4cde692c-a291-49d1-8350-778aa11640f8
This commit is contained in:
jvr 2002-05-12 17:14:50 +00:00
parent ce1d50aca8
commit ea9dfa9fb2
4 changed files with 28 additions and 28 deletions

View File

@ -42,7 +42,7 @@ Dumping 'prep' table...
"""
#
# $Id: __init__.py,v 1.24 2002-05-11 21:18:12 jvr Exp $
# $Id: __init__.py,v 1.25 2002-05-12 17:14:50 jvr Exp $
#
import os
@ -62,7 +62,7 @@ class TTFont:
"""
def __init__(self, file=None, res_name_or_index=None,
sfntVersion="\000\001\000\000", checkchecksums=0,
sfntVersion="\000\001\000\000", checkChecksums=0,
verbose=0, recalcBBoxes=1):
"""The constructor can be called with a few different arguments.
@ -75,7 +75,7 @@ class TTFont:
or a suitcase. (If it's a suitcase, only the first 'sfnt' resource
will be read!)
The 'checkchecksums' argument is used to specify how sfnt
The 'checkChecksums' argument is used to specify how sfnt
checksums are treated upon reading a file from disk:
0: don't check (default)
1: check, print warnings if a wrong checksum is found (default)
@ -121,7 +121,7 @@ class TTFont:
file = open(file, "rb")
else:
pass # assume "file" is a readable file object
self.reader = sfnt.SFNTReader(file, checkchecksums)
self.reader = sfnt.SFNTReader(file, checkChecksums)
self.sfntVersion = self.reader.sfntVersion
def close(self):

View File

@ -18,9 +18,9 @@ import os
class SFNTReader:
def __init__(self, file, checkchecksums=1):
def __init__(self, file, checkChecksums=1):
self.file = file
self.checkchecksums = checkchecksums
self.checkChecksums = checkChecksums
data = self.file.read(sfntDirectorySize)
if len(data) <> sfntDirectorySize:
from fontTools import ttLib
@ -32,7 +32,7 @@ class SFNTReader:
self.tables = {}
for i in range(self.numTables):
entry = SFNTDirectoryEntry()
entry.fromfile(self.file)
entry.fromFile(self.file)
if entry.length > 0:
self.tables[entry.tag] = entry
else:
@ -53,13 +53,13 @@ class SFNTReader:
entry = self.tables[tag]
self.file.seek(entry.offset)
data = self.file.read(entry.length)
if self.checkchecksums:
if self.checkChecksums:
if tag == 'head':
# Beh: we have to special-case the 'head' table.
checksum = calcchecksum(data[:8] + '\0\0\0\0' + data[12:])
checksum = calcChecksum(data[:8] + '\0\0\0\0' + data[12:])
else:
checksum = calcchecksum(data)
if self.checkchecksums > 1:
checksum = calcChecksum(data)
if self.checkChecksums > 1:
# Be obnoxious, and barf when it's wrong
assert checksum == entry.checksum, "bad checksum for '%s' table" % tag
elif checksum <> entry.checkSum:
@ -80,7 +80,7 @@ class SFNTWriter:
self.file = file
self.numTables = numTables
self.sfntVersion = sfntVersion
self.searchRange, self.entrySelector, self.rangeShift = getsearchrange(numTables)
self.searchRange, self.entrySelector, self.rangeShift = getSearchRange(numTables)
self.nextTableOffset = sfntDirectorySize + numTables * sfntDirectoryEntrySize
# clear out directory area
self.file.seek(self.nextTableOffset)
@ -110,9 +110,9 @@ class SFNTWriter:
self.file.write('\0' * (self.nextTableOffset - self.file.tell()))
if tag == 'head':
entry.checkSum = calcchecksum(data[:8] + '\0\0\0\0' + data[12:])
entry.checkSum = calcChecksum(data[:8] + '\0\0\0\0' + data[12:])
else:
entry.checkSum = calcchecksum(data)
entry.checkSum = calcChecksum(data)
self.tables[tag] = entry
def close(self, closeStream=1):
@ -129,14 +129,14 @@ class SFNTWriter:
self.file.seek(sfntDirectorySize)
for tag, entry in tables:
directory = directory + entry.tostring()
self.calcmasterchecksum(directory)
directory = directory + entry.toString()
self.calcMasterChecksum(directory)
self.file.seek(0)
self.file.write(directory)
if closeStream:
self.file.close()
def calcmasterchecksum(self, directory):
def calcMasterChecksum(self, directory):
# calculate checkSumAdjustment
tags = self.tables.keys()
checksums = Numeric.zeros(len(tags)+1)
@ -146,7 +146,7 @@ class SFNTWriter:
directory_end = sfntDirectorySize + len(self.tables) * sfntDirectoryEntrySize
assert directory_end == len(directory)
checksums[-1] = calcchecksum(directory)
checksums[-1] = calcChecksum(directory)
checksum = Numeric.add.reduce(checksums)
# BiboAfba!
checksumadjustment = Numeric.array(0xb1b0afba) - checksum
@ -180,14 +180,14 @@ sfntDirectoryEntrySize = sstruct.calcsize(sfntDirectoryEntryFormat)
class SFNTDirectoryEntry:
def fromfile(self, file):
def fromFile(self, file):
sstruct.unpack(sfntDirectoryEntryFormat,
file.read(sfntDirectoryEntrySize), self)
def fromstring(self, str):
def fromString(self, str):
sstruct.unpack(sfntDirectoryEntryFormat, str, self)
def tostring(self):
def toString(self):
return sstruct.pack(sfntDirectoryEntryFormat, self)
def __repr__(self):
@ -197,7 +197,7 @@ class SFNTDirectoryEntry:
return "<SFNTDirectoryEntry at %x>" % id(self)
def calcchecksum(data, start=0):
def calcChecksum(data, start=0):
"""Calculate the checksum for an arbitrary block of data.
Optionally takes a 'start' argument, which allows you to
calculate a checksum in chunks by feeding it a previous
@ -216,7 +216,7 @@ def calcchecksum(data, start=0):
return Numeric.add.reduce(a)
def maxpoweroftwo(x):
def maxPowerOfTwo(x):
"""Return the highest exponent of two, so that
(2 ** exponent) <= x
"""
@ -227,13 +227,13 @@ def maxpoweroftwo(x):
return max(exponent - 1, 0)
def getsearchrange(n):
def getSearchRange(n):
"""Calculate searchRange, entrySelector, rangeShift for the
sfnt directory. 'n' is the number of tables.
"""
# This stuff needs to be stored in the file, because?
import math
exponent = maxpoweroftwo(n)
exponent = maxPowerOfTwo(n)
searchRange = (2 ** exponent) * 16
entrySelector = exponent
rangeShift = n * 16 - searchRange

View File

@ -227,7 +227,7 @@ class cmap_format_4(CmapSubtable):
self.cmap = cmap
def compile(self, ttFont):
from fontTools.ttLib.sfnt import maxpoweroftwo
from fontTools.ttLib.sfnt import maxPowerOfTwo
codes = self.cmap.items()
codes.sort()
@ -270,7 +270,7 @@ class cmap_format_4(CmapSubtable):
# Insane.
segCount = len(endCode)
segCountX2 = segCount * 2
maxexponent = maxpoweroftwo(segCount)
maxexponent = maxPowerOfTwo(segCount)
searchRange = 2 * (2 ** maxexponent)
entrySelector = maxexponent
rangeShift = 2 * segCount - searchRange

View File

@ -96,7 +96,7 @@ class KernTable_format_0:
def compile(self, ttFont):
nPairs = len(self.kernTable)
entrySelector = sfnt.maxpoweroftwo(nPairs)
entrySelector = sfnt.maxPowerOfTwo(nPairs)
searchRange = (2 ** entrySelector) * 6
rangeShift = (nPairs - (2 ** entrySelector)) * 6
data = struct.pack(">HHHH", nPairs, searchRange, entrySelector, rangeShift)