#******************************************************************************
# TTFontFile class                                                             
#                                                                              
# This class is based on The ReportLab Open Source PDF library                 
# written in Python - http://www.reportlab.com/software/opensource/            
# together with ideas from the OpenOffice source code and others.              
#                                                                              
# Version:  1.04                                                               
# Date:     2011-09-18                                                         
# Author:   Ian Back <ianb@bpm1.com>                                           
# License:  LGPL                                                               
# Copyright (c) Ian Back, 2010                                                 
# Ported to Python 2.7 by Mariano Reingart (reingart@gmail.com) on 2012        
# This header must be retained in any redistribution or                        
# modification of the file.                                                    
#                                                                              
#******************************************************************************

from __future__ import with_statement

from struct import pack, unpack, unpack_from
import re
import warnings
from .php import die, substr, str_repeat, str_pad, strlen, count
from .py3k import b, ord


# Define the value used in the "head" table of a created TTF file
# 0x74727565 "true" for Mac
# 0x00010000 for Windows
# Either seems to work for a font embedded in a PDF file
# when read by Adobe Reader on a Windows PC(!)
_TTF_MAC_HEADER = False


# TrueType Font Glyph operators
GF_WORDS = (1 << 0)
GF_SCALE = (1 << 3)
GF_MORE  = (1 << 5)
GF_XYSCALE  = (1 << 6)
GF_TWOBYTWO = (1 << 7)


def sub32(x, y):
    xlo = x[1]
    xhi = x[0]
    ylo = y[1]
    yhi = y[0]
    if (ylo > xlo):  
        xlo += 1 << 16 