From ce108d3fea94e3b9cce73edd5dca42aec928dfc2 Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Thu, 3 Jan 2013 09:48:54 +0000 Subject: Merge in new XeTeX stuff git-svn-id: svn://tug.org/texlive/trunk@28710 c570f23f-e606-0410-a88d-b1316a301751 --- Build/source/README.config | 10 +- Build/source/texk/web2c/Makefile.am | 2 + Build/source/texk/web2c/ac/web2c.ac | 2 +- Build/source/texk/web2c/configure.ac | 5 +- Build/source/texk/web2c/xetexdir/COPYING | 36 + Build/source/texk/web2c/xetexdir/ChangeLog | 4 + .../source/texk/web2c/xetexdir/FontTableCache.cpp | 29 +- Build/source/texk/web2c/xetexdir/FontTableCache.h | 20 +- Build/source/texk/web2c/xetexdir/LICENSE.txt | 34 - Build/source/texk/web2c/xetexdir/MathTable.h | 126 ++- Build/source/texk/web2c/xetexdir/XeTeXFontInst.cpp | 175 ++-- Build/source/texk/web2c/xetexdir/XeTeXFontInst.h | 128 +-- .../texk/web2c/xetexdir/XeTeXFontInst_FT2.cpp | 129 ++- .../source/texk/web2c/xetexdir/XeTeXFontInst_FT2.h | 30 +- .../texk/web2c/xetexdir/XeTeXFontInst_Mac.cpp | 120 ++- .../source/texk/web2c/xetexdir/XeTeXFontInst_Mac.h | 26 +- Build/source/texk/web2c/xetexdir/XeTeXFontMgr.cpp | 138 +-- Build/source/texk/web2c/xetexdir/XeTeXFontMgr.h | 27 +- .../source/texk/web2c/xetexdir/XeTeXFontMgr_FC.cpp | 10 +- Build/source/texk/web2c/xetexdir/XeTeXFontMgr_FC.h | 6 +- .../source/texk/web2c/xetexdir/XeTeXFontMgr_Mac.h | 6 +- .../source/texk/web2c/xetexdir/XeTeXFontMgr_Mac.mm | 6 +- Build/source/texk/web2c/xetexdir/XeTeXGrLayout.cpp | 175 ---- Build/source/texk/web2c/xetexdir/XeTeXGrLayout.h | 201 ----- .../texk/web2c/xetexdir/XeTeXLayoutInterface.cpp | 981 +++++++++------------ .../texk/web2c/xetexdir/XeTeXLayoutInterface.h | 58 +- .../texk/web2c/xetexdir/XeTeXOTLayoutEngine.cpp | 378 -------- .../texk/web2c/xetexdir/XeTeXOTLayoutEngine.h | 74 -- Build/source/texk/web2c/xetexdir/XeTeXOTMath.cpp | 298 +++++-- Build/source/texk/web2c/xetexdir/XeTeXOTMath.h | 7 +- Build/source/texk/web2c/xetexdir/XeTeX_ext.c | 816 +++++++---------- Build/source/texk/web2c/xetexdir/XeTeX_ext.h | 48 +- Build/source/texk/web2c/xetexdir/XeTeX_mac.c | 30 +- Build/source/texk/web2c/xetexdir/XeTeX_pic.c | 6 +- Build/source/texk/web2c/xetexdir/XeTeXswap.h | 8 +- Build/source/texk/web2c/xetexdir/am/xetex.am | 32 +- Build/source/texk/web2c/xetexdir/appleGlyphNames.c | 6 +- Build/source/texk/web2c/xetexdir/bmpimage.c | 5 +- Build/source/texk/web2c/xetexdir/bmpimage.h | 7 +- Build/source/texk/web2c/xetexdir/cmaps.cpp | 242 ----- Build/source/texk/web2c/xetexdir/cmaps.h | 114 --- Build/source/texk/web2c/xetexdir/hz.cpp | 6 +- Build/source/texk/web2c/xetexdir/jpegimage.c | 44 +- Build/source/texk/web2c/xetexdir/jpegimage.h | 7 +- Build/source/texk/web2c/xetexdir/mfileio.c | 126 --- Build/source/texk/web2c/xetexdir/mfileio.h | 61 -- Build/source/texk/web2c/xetexdir/numbers.c | 227 ----- Build/source/texk/web2c/xetexdir/numbers.h | 78 -- Build/source/texk/web2c/xetexdir/pdfimage.cpp | 6 +- Build/source/texk/web2c/xetexdir/pdfimage.h | 6 +- Build/source/texk/web2c/xetexdir/pngimage.c | 5 +- Build/source/texk/web2c/xetexdir/pngimage.h | 7 +- Build/source/texk/web2c/xetexdir/sfnt.h | 306 ++----- Build/source/texk/web2c/xetexdir/tex.ch0 | 8 - Build/source/texk/web2c/xetexdir/trans.c | 6 +- Build/source/texk/web2c/xetexdir/trans.h | 6 +- .../texk/web2c/xetexdir/unicode-char-prep.pl | 6 +- Build/source/texk/web2c/xetexdir/xetex.ch | 19 +- Build/source/texk/web2c/xetexdir/xetex.defines | 11 +- Build/source/texk/web2c/xetexdir/xetex.h | 22 +- Build/source/texk/web2c/xetexdir/xetex.web | 591 ++++++------- Build/source/texk/web2c/xetexdir/xetexextra.h | 8 +- 62 files changed, 2017 insertions(+), 4094 deletions(-) create mode 100644 Build/source/texk/web2c/xetexdir/COPYING delete mode 100644 Build/source/texk/web2c/xetexdir/LICENSE.txt delete mode 100644 Build/source/texk/web2c/xetexdir/XeTeXGrLayout.cpp delete mode 100644 Build/source/texk/web2c/xetexdir/XeTeXGrLayout.h delete mode 100644 Build/source/texk/web2c/xetexdir/XeTeXOTLayoutEngine.cpp delete mode 100644 Build/source/texk/web2c/xetexdir/XeTeXOTLayoutEngine.h delete mode 100644 Build/source/texk/web2c/xetexdir/cmaps.cpp delete mode 100644 Build/source/texk/web2c/xetexdir/cmaps.h delete mode 100644 Build/source/texk/web2c/xetexdir/mfileio.c delete mode 100644 Build/source/texk/web2c/xetexdir/mfileio.h delete mode 100644 Build/source/texk/web2c/xetexdir/numbers.c delete mode 100644 Build/source/texk/web2c/xetexdir/numbers.h diff --git a/Build/source/README.config b/Build/source/README.config index 36fb81649e4..9557c63584c 100644 --- a/Build/source/README.config +++ b/Build/source/README.config @@ -264,17 +264,11 @@ pdfTeX (and pkg-config to obtain the required flags). See information at --disable-largefile for a minor deficiency resulting from using poppler instead of TL's xpdf library. -3.5. Configure options for graphite ------------------------------------ -3.5.1. --without-graphite -Build XeTeX without graphite support. - 3.6. Configure options for the icu libraries -------------------------------------------- 3.6.1. --with-system-icu -Use installed icu headers and libraries for bibtexu (and icu-config to -obtain the required flags). However, XeTeX still requires the (modified) -icu headers and libraries from the TL tree. +Use installed icu headers and libraries for xetex and bibtexu (and icu-config to +obtain the required flags). 4. Interesting and/or important VAR=value configure arguments ============================================================= diff --git a/Build/source/texk/web2c/Makefile.am b/Build/source/texk/web2c/Makefile.am index d3b3c51e2e3..005bfbc3e7c 100644 --- a/Build/source/texk/web2c/Makefile.am +++ b/Build/source/texk/web2c/Makefile.am @@ -107,6 +107,8 @@ $(proglib): ${srcdir}/lib/*.c @ICU_RULE@ ## Rebuild libharfbuzz @HARFBUZZ_RULE@ +## Rebuild libgraphite2 +@GRAPHITE2_RULE@ # The environment for building. buildenv = TEXMFCNF=$(srcdir)/../kpathsea diff --git a/Build/source/texk/web2c/ac/web2c.ac b/Build/source/texk/web2c/ac/web2c.ac index 0a05bf8f6d0..7faa133d22a 100644 --- a/Build/source/texk/web2c/ac/web2c.ac +++ b/Build/source/texk/web2c/ac/web2c.ac @@ -41,7 +41,7 @@ m4_define([kpse_tex_progs], [dnl [[pdftex], [yes], [yes], [pdfTeX], [xpdf libpng]], [[luatex], [yes], [], [luaTeX], [poppler libpng zziplib]], [[mp], [yes], [], [MetaPost],[libpng]], -[[xetex], [yes], [yes], [XeTeX], [poppler libpng freetype2 icu-xetex teckit graphite]], +[[xetex], [yes], [yes], [XeTeX], [poppler libpng freetype2 icu teckit graphite2 harfbuzz]], ])[]dnl m4_foreach([Kpse_Prog], [kpse_tex_progs], [m4_ifset([Kpse_Prog], diff --git a/Build/source/texk/web2c/configure.ac b/Build/source/texk/web2c/configure.ac index 8ef40604b7d..34cb9fd26a5 100644 --- a/Build/source/texk/web2c/configure.ac +++ b/Build/source/texk/web2c/configure.ac @@ -135,7 +135,6 @@ KPSE_FONTCONFIG_FLAGS AS_IF([test "x$kpse_cv_have_Carbon:$kpse_cv_have_fontconfig" = xno:no], [WEB2C_DISABLE([xetex], [neither Carbon framework nor fontconfig library])]) AM_CONDITIONAL([XETEX_MACOSX], [test "x$kpse_cv_have_Carbon" = xyes]) -AM_CONDITIONAL([XETEX_GRAPHITE], [test "x$with_graphite" != xno]) dnl Generate *TEX and ALEPH conditionals. m4_foreach([Kpse_Prog], [kpse_tex_progs], @@ -274,9 +273,9 @@ KPSE_XPDF_FLAGS KPSE_ZZIPLIB_FLAGS KPSE_GRAPHITE_FLAGS KPSE_TECKIT_FLAGS -KPSE_ICU_FLAGS([icule])[]dnl required by KPSE_HARFBUZZ_FLAGS -KPSE_ICU_XETEX_FLAGS([icule]) +KPSE_ICU_FLAGS KPSE_HARFBUZZ_FLAGS +KPSE_GRAPHITE2_FLAGS # Check size of off_t (using ) KPSE_ADD_FLAGS([kpathsea]) diff --git a/Build/source/texk/web2c/xetexdir/COPYING b/Build/source/texk/web2c/xetexdir/COPYING new file mode 100644 index 00000000000..47db7a1d747 --- /dev/null +++ b/Build/source/texk/web2c/xetexdir/COPYING @@ -0,0 +1,36 @@ + The XeTeX typesetting system + (an extended version of Donald Knuth's TeX) + + The XeTeX changes/additions are + Copyright (c) 1994-2008 by SIL International + Copyright (c) 2009-2012 by Jonathan Kew + Copyright (c) 2010-2012 Han Han The Thanh + Copyright (c) 2012 by Khaled Hosny + + +For full copyright notices consult the individual files in the package. + + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE +FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of the copyright holders +shall not be used in advertising or otherwise to promote the sale, +use or other dealings in this Software without prior written +authorization from the copyright holders. diff --git a/Build/source/texk/web2c/xetexdir/ChangeLog b/Build/source/texk/web2c/xetexdir/ChangeLog index afc00c9733a..031a60e45f2 100644 --- a/Build/source/texk/web2c/xetexdir/ChangeLog +++ b/Build/source/texk/web2c/xetexdir/ChangeLog @@ -1,3 +1,7 @@ +2013-01-03 Khaled Hosny + + Merge changes from XeTeX repository. + 2012-12-16 Peter Breitenlohner * am/xetex.am (xetex_version.h): Enable silent rules. diff --git a/Build/source/texk/web2c/xetexdir/FontTableCache.cpp b/Build/source/texk/web2c/xetexdir/FontTableCache.cpp index ed84522bc8a..d8d3ed54714 100644 --- a/Build/source/texk/web2c/xetexdir/FontTableCache.cpp +++ b/Build/source/texk/web2c/xetexdir/FontTableCache.cpp @@ -1,9 +1,9 @@ /****************************************************************************\ Part of the XeTeX typesetting system - copyright (c) 1994-2008 by SIL International - copyright (c) 2009 by Jonathan Kew + Copyright (c) 1994-2008 by SIL International + Copyright (c) 2009 by Jonathan Kew - Written by Jonathan Kew + SIL Author(s): Jonathan Kew Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -39,8 +39,6 @@ authorization from the copyright holders. ********************************************************************** */ -#include "layout/LETypes.h" - #include "FontTableCache.h" #define TABLE_CACHE_INIT 5 @@ -48,9 +46,9 @@ authorization from the copyright holders. struct FontTableCacheEntry { - LETag tag; + OTTag tag; const void *table; - le_uint32 size; + uint32_t size; }; FontTableCache::FontTableCache() @@ -62,7 +60,7 @@ FontTableCache::FontTableCache() void FontTableCache::initialize() { - fTableCache = LE_NEW_ARRAY(FontTableCacheEntry, fTableCacheSize); + fTableCache = (FontTableCacheEntry *) malloc((fTableCacheSize) * sizeof(FontTableCacheEntry)); if (fTableCache == NULL) { fTableCacheSize = 0; @@ -78,13 +76,15 @@ FontTableCache::~FontTableCache() void FontTableCache::dispose() { for (int i = fTableCacheCurr - 1; i >= 0; i -= 1) { - LE_DELETE_ARRAY(fTableCache[i].table); + free((void *) (fTableCache[i].table)); } + free(fTableCache); + fTableCacheCurr = 0; } -const void *FontTableCache::find(LETag tableTag, le_uint32 *tableSize) const +const void *FontTableCache::find(OTTag tableTag, uint32_t *tableSize) const { int lo = 0, hi = fTableCacheCurr; while (lo < hi) { @@ -101,7 +101,7 @@ const void *FontTableCache::find(LETag tableTag, le_uint32 *tableSize) const } } - le_uint32 length; + uint32_t length; const void *table = readFontTable(tableTag, length); ((FontTableCache *) this)->add(tableTag, table, length); @@ -111,13 +111,12 @@ const void *FontTableCache::find(LETag tableTag, le_uint32 *tableSize) const return table; } -void FontTableCache::add(LETag tableTag, const void *table, le_uint32 length) +void FontTableCache::add(OTTag tableTag, const void *table, uint32_t length) { if (fTableCacheCurr >= fTableCacheSize) { - le_int32 newSize = fTableCacheSize + TABLE_CACHE_GROW; - - fTableCache = (FontTableCacheEntry *) LE_GROW_ARRAY(fTableCache, newSize); + int32_t newSize = fTableCacheSize + TABLE_CACHE_GROW; + fTableCache = (FontTableCacheEntry *) realloc(fTableCache, newSize * sizeof(FontTableCacheEntry)); fTableCacheSize = newSize; } diff --git a/Build/source/texk/web2c/xetexdir/FontTableCache.h b/Build/source/texk/web2c/xetexdir/FontTableCache.h index 3e19c3a4b5e..a11419e2748 100644 --- a/Build/source/texk/web2c/xetexdir/FontTableCache.h +++ b/Build/source/texk/web2c/xetexdir/FontTableCache.h @@ -1,9 +1,9 @@ /****************************************************************************\ Part of the XeTeX typesetting system - copyright (c) 1994-2008 by SIL International - copyright (c) 2009 by Jonathan Kew + Copyright (c) 1994-2008 by SIL International + Copyright (c) 2009 by Jonathan Kew - Written by Jonathan Kew + SIL Author(s): Jonathan Kew Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -43,7 +43,7 @@ authorization from the copyright holders. #define __FONTTABLECACHE_H -#include "layout/LETypes.h" +#include "XeTeX_ext.h" struct FontTableCacheEntry; @@ -54,24 +54,24 @@ public: virtual ~FontTableCache(); - const void *find(LETag tableTag, le_uint32 *tableSize = NULL) const; + const void *find(OTTag tableTag, uint32_t *tableSize = NULL) const; void flush(); protected: - virtual const void *readFontTable(LETag tableTag) const = 0; - virtual const void *readFontTable(LETag tableTag, le_uint32 &length) const = 0; + virtual const void *readFontTable(OTTag tableTag) const = 0; + virtual const void *readFontTable(OTTag tableTag, uint32_t &length) const = 0; private: void initialize(); void dispose(); - void add(LETag tableTag, const void *table, le_uint32 length); + void add(OTTag tableTag, const void *table, uint32_t length); FontTableCacheEntry *fTableCache; - le_int32 fTableCacheCurr; - le_int32 fTableCacheSize; + int32_t fTableCacheCurr; + int32_t fTableCacheSize; }; #endif diff --git a/Build/source/texk/web2c/xetexdir/LICENSE.txt b/Build/source/texk/web2c/xetexdir/LICENSE.txt deleted file mode 100644 index b2728055e43..00000000000 --- a/Build/source/texk/web2c/xetexdir/LICENSE.txt +++ /dev/null @@ -1,34 +0,0 @@ -/****************************************************************************\ - The XeTeX typesetting system - (an extended version of Donald Knuth's TeX) - - The XeTeX changes/additions are - copyright (c) 1994-2008 by SIL International - copyright (c) 2009 by Jonathan Kew - - Written by Jonathan Kew - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE -FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF -CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of the copyright holders -shall not be used in advertising or otherwise to promote the sale, -use or other dealings in this Software without prior written -authorization from the copyright holders. -\****************************************************************************/ diff --git a/Build/source/texk/web2c/xetexdir/MathTable.h b/Build/source/texk/web2c/xetexdir/MathTable.h index f0eeb7566dd..e302ee17d15 100644 --- a/Build/source/texk/web2c/xetexdir/MathTable.h +++ b/Build/source/texk/web2c/xetexdir/MathTable.h @@ -1,9 +1,10 @@ /****************************************************************************\ Part of the XeTeX typesetting system - copyright (c) 1994-2008 by SIL International - copyright (c) 2009 by Jonathan Kew + Copyright (c) 1994-2008 by SIL International + Copyright (c) 2009 by Jonathan Kew + Copyright (c) 2012 by Khaled Hosny - Written by Jonathan Kew + SIL Author(s): Jonathan Kew Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -33,25 +34,35 @@ authorization from the copyright holders. #ifndef __MATHTABLE_H__ #define __MATHTABLE_H__ -#include "layout/OpenTypeTables.h" +#ifndef ANY_NUMBER +#define ANY_NUMBER 1 +#endif + +typedef uint16_t Offset; typedef struct { - le_int16 value; - le_uint16 deviceTable; + int16_t value; + Offset deviceTable; } MathValueRecord; typedef struct { - le_uint32 version; - le_uint16 mathConstants; - le_uint16 mathGlyphInfo; - le_uint16 mathVariants; + GlyphID start; + GlyphID end; + int16_t startCoverageIndex; +} RangeRecord; + +typedef struct { + uint32_t version; + Offset mathConstants; + Offset mathGlyphInfo; + Offset mathVariants; } MathTableHeader; typedef struct { - le_uint16 scriptPercentScaleDown; - le_uint16 scriptScriptPercentScaleDown; - le_uint16 delimitedSubFormulaMinHeight; - le_uint16 displayOperatorMinHeight; + uint16_t scriptPercentScaleDown; + uint16_t scriptScriptPercentScaleDown; + uint16_t delimitedSubFormulaMinHeight; + uint16_t displayOperatorMinHeight; MathValueRecord mathLeading; MathValueRecord axisHeight; MathValueRecord accentBaseHeight; @@ -103,7 +114,7 @@ typedef struct { MathValueRecord radicalExtraAscender; MathValueRecord radicalKernBeforeDegree; MathValueRecord radicalKernAfterDegree; - le_uint16 radicalDegreeBottomRaisePercent; + uint16_t radicalDegreeBottomRaisePercent; } MathConstants; typedef enum { @@ -170,58 +181,93 @@ typedef enum { } mathConstantIndex; typedef struct { - le_uint16 minConnectorOverlap; - Offset vertGlyphCoverage; - Offset horizGlyphCoverage; - le_uint16 vertGlyphCount; - le_uint16 horizGlyphCount; - Offset vertGlyphConstruction[ANY_NUMBER]; - Offset horizGlyphConstruction[ANY_NUMBER]; + uint16_t minConnectorOverlap; + Offset vertGlyphCoverage; + Offset horizGlyphCoverage; + uint16_t vertGlyphCount; + uint16_t horizGlyphCount; + Offset vertGlyphConstruction[ANY_NUMBER]; + Offset horizGlyphConstruction[ANY_NUMBER]; } MathVariants; typedef struct { - TTGlyphID variantGlyph; - le_uint16 advanceMeasurement; + GlyphID variantGlyph; + uint16_t advanceMeasurement; } MathGlyphVariantRecord; typedef struct { - Offset glyphAssembly; - le_uint16 variantCount; + Offset glyphAssembly; + uint16_t variantCount; MathGlyphVariantRecord mathGlyphVariantRecord[ANY_NUMBER]; } MathGlyphConstruction; typedef struct { - TTGlyphID glyph; - le_uint16 startConnectorLength; - le_uint16 endConnectorLength; - le_uint16 fullAdvance; - le_uint16 partFlags; + GlyphID glyph; + uint16_t startConnectorLength; + uint16_t endConnectorLength; + uint16_t fullAdvance; + uint16_t partFlags; } GlyphPartRecord; #define fExtender 0x0001 typedef struct { MathValueRecord italicsCorrection; - le_uint16 partCount; + uint16_t partCount; GlyphPartRecord partRecords[ANY_NUMBER]; } GlyphAssembly; typedef struct { - le_uint16 mathItalicsCorrectionInfo; - le_uint16 mathTopAccentAttachment; - le_uint16 extendedShapeCoverage; - le_uint16 mathKernInfo; + Offset mathItalicsCorrectionInfo; + Offset mathTopAccentAttachment; + Offset extendedShapeCoverage; + Offset mathKernInfo; } MathGlyphInfo; typedef struct { - le_uint16 coverage; - le_uint16 italicsCorrectionCount; + Offset coverage; + uint16_t italicsCorrectionCount; MathValueRecord italicsCorrection[ANY_NUMBER]; } MathItalicsCorrectionInfo; typedef struct { - le_uint16 coverage; - le_uint16 topAccentAttachmentCount; + Offset coverage; + uint16_t topAccentAttachmentCount; MathValueRecord topAccentAttachment[ANY_NUMBER]; } MathTopAccentAttachment; +typedef struct { + Offset topRight; + Offset topLeft; + Offset bottomRight; + Offset bottomLeft; +} MathKernInfoRecord; + +typedef struct { + Offset coverage; + uint16_t kernInfoCount; + MathKernInfoRecord kernInfo[ANY_NUMBER]; +} MathKernInfo; + +typedef struct { + uint16_t heightCount; + MathValueRecord height[ANY_NUMBER]; + MathValueRecord kern[ANY_NUMBER]; +} MathKernTable; + +typedef struct { + uint16_t format; +} Coverage; + +typedef struct { + uint16_t format; + uint16_t glyphCount; + GlyphID glyphArray[ANY_NUMBER]; +} CoverageFormat1; + +typedef struct { + uint16_t format; + uint16_t rangeCount; + RangeRecord rangeArray[ANY_NUMBER]; +} CoverageFormat2; + #endif diff --git a/Build/source/texk/web2c/xetexdir/XeTeXFontInst.cpp b/Build/source/texk/web2c/xetexdir/XeTeXFontInst.cpp index 97da466ba48..2013c442e2b 100644 --- a/Build/source/texk/web2c/xetexdir/XeTeXFontInst.cpp +++ b/Build/source/texk/web2c/xetexdir/XeTeXFontInst.cpp @@ -1,9 +1,9 @@ /****************************************************************************\ Part of the XeTeX typesetting system - copyright (c) 1994-2008 by SIL International - copyright (c) 2009 by Jonathan Kew + Copyright (c) 1994-2008 by SIL International + Copyright (c) 2009 by Jonathan Kew - Written by Jonathan Kew + SIL Author(s): Jonathan Kew Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -39,13 +39,9 @@ authorization from the copyright holders. * originally based on PortableFontInstance.cpp from ICU */ - -#include "layout/LETypes.h" -#include "layout/LEFontInstance.h" -#include "layout/LESwaps.h" - #include "XeTeXFontInst.h" #include "XeTeXLayoutInterface.h" +#include "XeTeXswap.h" #ifdef XETEX_MAC #include @@ -58,23 +54,19 @@ authorization from the copyright holders. #include -XeTeXFontInst::XeTeXFontInst(float pointSize, LEErrorCode &status) +XeTeXFontInst::XeTeXFontInst(float pointSize, int &status) : fPointSize(pointSize) , fUnitsPerEM(0) , fAscent(0) , fDescent(0) - , fLeading(0) - , fXHeight(0) , fItalicAngle(0) - , fCMAPMapper(NULL) , fMetricsTable(NULL) , fNumLongMetrics(0) , fNumGlyphs(0) , fNumGlyphsInited(false) , fVertical(false) , fFilename(NULL) - , fFirstCharCode(-1) - , fLastCharCode(-1) + , hbFont(NULL) { // the concrete subclass is responsible to call initialize() } @@ -83,17 +75,10 @@ XeTeXFontInst::~XeTeXFontInst() { if (fMetricsTable != NULL) deleteTable(fMetricsTable); - - if (fCMAPMapper != NULL) - delete fCMAPMapper; } -void XeTeXFontInst::initialize(LEErrorCode &status) +void XeTeXFontInst::initialize(int &status) { - const LETag headTag = LE_HEAD_TABLE_TAG; - const LETag hheaTag = LE_HHEA_TABLE_TAG; - const LETag vheaTag = LE_VHEA_TABLE_TAG; - const LETag postTag = LE_POST_TABLE_TAG; const HEADTable *headTable = NULL; const HHEATable *dirHeadTable = NULL; const POSTTable *postTable = NULL; @@ -105,43 +90,35 @@ void XeTeXFontInst::initialize(LEErrorCode &status) } // read unitsPerEm from 'head' table - headTable = (const HEADTable *) readFontTable(headTag); + headTable = (const HEADTable *) readFontTable(kHEAD); if (headTable == NULL) { - status = LE_MISSING_FONT_TABLE_ERROR; + status = 1; goto error_exit; } - fUnitsPerEM = SWAPW(headTable->unitsPerEm); + fUnitsPerEM = SWAP(headTable->unitsPerEm); deleteTable(headTable); // we use the fact that 'hhea' and 'vhea' have the same format! - dirHeadTable = (const HHEATable *) readFontTable(fVertical ? vheaTag : hheaTag); + dirHeadTable = (const HHEATable *) readFontTable(fVertical ? kVHEA : kHHEA); if (dirHeadTable == NULL) { - status = LE_MISSING_FONT_TABLE_ERROR; + status = 1; goto error_exit; } - fAscent = yUnitsToPoints((float)(le_int16)SWAPW(dirHeadTable->ascent)); - fDescent = yUnitsToPoints((float)(le_int16)SWAPW(dirHeadTable->descent)); - fLeading = yUnitsToPoints((float)(le_int16)SWAPW(dirHeadTable->lineGap)); + fAscent = unitsToPoints((float)(int16_t)SWAP(dirHeadTable->ascent)); + fDescent = unitsToPoints((float)(int16_t)SWAP(dirHeadTable->descent)); - fNumLongMetrics = SWAPW(dirHeadTable->numOfLongHorMetrics); + fNumLongMetrics = SWAP(dirHeadTable->numOfLongHorMetrics); deleteTable(dirHeadTable); - fCMAPMapper = findUnicodeMapper(); - - if (fCMAPMapper == NULL) { - status = LE_MISSING_FONT_TABLE_ERROR; - goto error_exit; - } - - postTable = (const POSTTable *) readFontTable(postTag); + postTable = (const POSTTable *) readFontTable(kPOST); if (postTable != NULL) { - fItalicAngle = Fix2X(SWAPL(postTable->italicAngle)); + fItalicAngle = Fix2D(SWAP(UInt32(postTable->italicAngle))); deleteTable(postTable); } @@ -154,59 +131,45 @@ error_exit: void XeTeXFontInst::setLayoutDirVertical(bool vertical) { fVertical = vertical; - LEErrorCode status = LE_NO_ERROR; + int status = 0; initialize(status); } void XeTeXFontInst::deleteTable(const void *table) const { - LE_DELETE_ARRAY(table); + free((void *) table); } -const void *XeTeXFontInst::getFontTable(LETag tableTag) const +const void *XeTeXFontInst::getFontTable(OTTag tableTag) const { return FontTableCache::find(tableTag); } -const void *XeTeXFontInst::getFontTable(LETag tableTag, le_uint32 *length) const +const void *XeTeXFontInst::getFontTable(OTTag tableTag, uint32_t *length) const { return FontTableCache::find(tableTag, length); } -const void *XeTeXFontInst::readFontTable(LETag tableTag) const +const void *XeTeXFontInst::readFontTable(OTTag tableTag) const { - le_uint32 len; + uint32_t len; return readTable(tableTag, &len); } -const void *XeTeXFontInst::readFontTable(LETag tableTag, le_uint32& len) const +const void *XeTeXFontInst::readFontTable(OTTag tableTag, uint32_t& len) const { return readTable(tableTag, &len); } -CMAPMapper *XeTeXFontInst::findUnicodeMapper() -{ - LETag cmapTag = LE_CMAP_TABLE_TAG; - const CMAPTable *cmap = (CMAPTable *) readFontTable(cmapTag); - - if (cmap == NULL) { - return NULL; - } - - return CMAPMapper::createUnicodeMapper(cmap); -} - - -le_uint16 XeTeXFontInst::getNumGlyphs() const +uint16_t XeTeXFontInst::getNumGlyphs() const { if (!fNumGlyphsInited) { - LETag maxpTag = LE_MAXP_TABLE_TAG; - const MAXPTable *maxpTable = (MAXPTable *) readFontTable(maxpTag); + const MAXPTable *maxpTable = (MAXPTable *) readFontTable(kMAXP); if (maxpTable != NULL) { XeTeXFontInst *realThis = (XeTeXFontInst *) this; - realThis->fNumGlyphs = SWAPW(maxpTable->numGlyphs); + realThis->fNumGlyphs = SWAP(maxpTable->numGlyphs); deleteTable(maxpTable); realThis->fNumGlyphsInited = true; } @@ -215,47 +178,39 @@ le_uint16 XeTeXFontInst::getNumGlyphs() const return fNumGlyphs; } -void XeTeXFontInst::getGlyphAdvance(LEGlyphID glyph, LEPoint &advance) const +void XeTeXFontInst::getGlyphAdvance(GlyphID glyph, realpoint &advance) const { - TTGlyphID ttGlyph = (TTGlyphID) LE_GET_GLYPH(glyph); - if (fMetricsTable == NULL) { - // we use the fact that 'hmtx' and 'vmtx' have the same format - LETag metricsTag = fVertical ? LE_VMTX_TABLE_TAG : LE_HMTX_TABLE_TAG; XeTeXFontInst *realThis = (XeTeXFontInst *) this; - realThis->fMetricsTable = (const HMTXTable *) readFontTable(metricsTag); + // we use the fact that 'hmtx' and 'vmtx' have the same format + realThis->fMetricsTable = (const HMTXTable *) readFontTable(fVertical ? kVMTX : kHMTX); } - le_uint16 index = ttGlyph; + uint16_t index = glyph; - if (ttGlyph >= getNumGlyphs() || fMetricsTable == NULL) { - advance.fX = advance.fY = 0; + if (glyph >= getNumGlyphs() || fMetricsTable == NULL) { + advance.x = advance.y = 0; return; } - if (ttGlyph >= fNumLongMetrics) { + if (glyph >= fNumLongMetrics) { index = fNumLongMetrics - 1; } - advance.fX = xUnitsToPoints(SWAPW(fMetricsTable->hMetrics[index].advanceWidth)); - advance.fY = 0; -} - -le_bool XeTeXFontInst::getGlyphPoint(LEGlyphID glyph, le_int32 pointNumber, LEPoint &point) const -{ - return FALSE; + advance.x = unitsToPoints(SWAP(fMetricsTable->hMetrics[index].advanceWidth)); + advance.y = 0; } float -XeTeXFontInst::getGlyphWidth(LEGlyphID gid) +XeTeXFontInst::getGlyphWidth(GlyphID gid) { - LEPoint advance; + realpoint advance; getGlyphAdvance(gid, advance); - return advance.fX; + return advance.x; } void -XeTeXFontInst::getGlyphHeightDepth(LEGlyphID gid, float* ht, float* dp) +XeTeXFontInst::getGlyphHeightDepth(GlyphID gid, float* ht, float* dp) { GlyphBBox bbox; getGlyphBounds(gid, &bbox); @@ -267,9 +222,9 @@ XeTeXFontInst::getGlyphHeightDepth(LEGlyphID gid, float* ht, float* dp) } void -XeTeXFontInst::getGlyphSidebearings(LEGlyphID gid, float* lsb, float* rsb) +XeTeXFontInst::getGlyphSidebearings(GlyphID gid, float* lsb, float* rsb) { - LEPoint adv; + realpoint adv; getGlyphAdvance(gid, adv); GlyphBBox bbox; @@ -278,32 +233,32 @@ XeTeXFontInst::getGlyphSidebearings(LEGlyphID gid, float* lsb, float* rsb) if (lsb) *lsb = bbox.xMin; if (rsb) - *rsb = adv.fX - bbox.xMax; + *rsb = adv.x - bbox.xMax; } float -XeTeXFontInst::getGlyphItalCorr(LEGlyphID gid) +XeTeXFontInst::getGlyphItalCorr(GlyphID gid) { float rval = 0.0; - LEPoint adv; + realpoint adv; getGlyphAdvance(gid, adv); GlyphBBox bbox; getGlyphBounds(gid, &bbox); - if (bbox.xMax > adv.fX) - rval = bbox.xMax - adv.fX; + if (bbox.xMax > adv.x) + rval = bbox.xMax - adv.x; return rval; } -LEGlyphID +GlyphID XeTeXFontInst::mapGlyphToIndex(const char* glyphName) const /* default implementation, may be overridden (e.g. by Freetype-based XeTeXFontInst_ */ { - le_uint32 len; - const char *p = (const char*)readFontTable(LE_POST_TABLE_TAG, len); + uint32_t len; + const char *p = (const char*)readFontTable(kPOST, len); if (p != NULL) return findGlyphInPostTable(p, len, glyphName); else @@ -311,36 +266,12 @@ XeTeXFontInst::mapGlyphToIndex(const char* glyphName) const } const char* -XeTeXFontInst::getGlyphName(LEGlyphID gid, int& nameLen) +XeTeXFontInst::getGlyphName(GlyphID gid, int& nameLen) { - le_uint32 len; - const char *p = (const char*)readFontTable(LE_POST_TABLE_TAG, len); + uint32_t len; + const char *p = (const char*)readFontTable(kPOST, len); if (p != NULL) return getGlyphNamePtr(p, len, gid, &nameLen); else return NULL; } - -LEUnicode32 -XeTeXFontInst::getFirstCharCode() -{ - if (fFirstCharCode == -1) { - int ch = 0; - while (mapCharToGlyph(ch) == 0 && ch < 0x10ffff) - ++ch; - fFirstCharCode = ch; - } - return fFirstCharCode; -} - -LEUnicode32 -XeTeXFontInst::getLastCharCode() -{ - if (fLastCharCode == -1) { - int ch = 0x10ffff; - while (mapCharToGlyph(ch) == 0 && ch > 0) - --ch; - fLastCharCode = ch; - } - return fLastCharCode; -} diff --git a/Build/source/texk/web2c/xetexdir/XeTeXFontInst.h b/Build/source/texk/web2c/xetexdir/XeTeXFontInst.h index ce1ca7867a5..3c49bccc126 100644 --- a/Build/source/texk/web2c/xetexdir/XeTeXFontInst.h +++ b/Build/source/texk/web2c/xetexdir/XeTeXFontInst.h @@ -1,9 +1,9 @@ /****************************************************************************\ Part of the XeTeX typesetting system - copyright (c) 1994-2008 by SIL International - copyright (c) 2009, 2011 by Jonathan Kew + Copyright (c) 1994-2008 by SIL International + Copyright (c) 2009, 2011 by Jonathan Kew - Written by Jonathan Kew + SIL Author(s): Jonathan Kew Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -45,13 +45,9 @@ authorization from the copyright holders. #include -#include "layout/LETypes.h" -#include "layout/LEFontInstance.h" - #include "FontTableCache.h" #include "sfnt.h" -#include "cmaps.h" #include "XeTeXFontMgr.h" #include "XeTeX_ext.h" @@ -60,59 +56,49 @@ extern "C" { void *xmalloc(size_t); // from kpathsea }; -// Abstract superclass that XeTeXOTLayoutEngine uses; // create specific subclasses for each supported platform -class XeTeXFontInst : public LEFontInstance, protected FontTableCache +class XeTeXFontInst : protected FontTableCache { friend class XeTeXGrFont; protected: float fPointSize; - le_int32 fUnitsPerEM; + int32_t fUnitsPerEM; float fAscent; float fDescent; - float fLeading; float fDeviceScaleX; float fDeviceScaleY; - float fXHeight; float fItalicAngle; - CMAPMapper *fCMAPMapper; - const HMTXTable *fMetricsTable; - le_uint16 fNumLongMetrics; - le_uint16 fNumGlyphs; + uint16_t fNumLongMetrics; + uint16_t fNumGlyphs; bool fNumGlyphsInited; bool fVertical; // false = horizontal, true = vertical char *fFilename; // actually holds [filename:index], as used in xetex - int fFirstCharCode; - int fLastCharCode; - - virtual const void *readTable(LETag tag, le_uint32 *length) const = 0; + virtual const void *readTable(OTTag tag, uint32_t *length) const = 0; void deleteTable(const void *table) const; void getMetrics(); - CMAPMapper *findUnicodeMapper(); - - const void *readFontTable(LETag tableTag) const; - const void *readFontTable(LETag tableTag, le_uint32& len) const; + const void *readFontTable(OTTag tableTag) const; + const void *readFontTable(OTTag tableTag, uint32_t& len) const; public: - XeTeXFontInst(float pointSize, LEErrorCode &status); + XeTeXFontInst(float pointSize, int &status); virtual ~XeTeXFontInst(); - virtual void initialize(LEErrorCode &status); + virtual void initialize(int &status); - virtual const void *getFontTable(LETag tableTag) const; - virtual const void *getFontTable(LETag tableTag, le_uint32* length) const; + virtual const void *getFontTable(OTTag tableTag) const; + virtual const void *getFontTable(OTTag tableTag, uint32_t* length) const; virtual const char *getFilename() const { @@ -126,95 +112,61 @@ public: return fVertical; }; - virtual le_int32 getUnitsPerEM() const + virtual int32_t getUnitsPerEM() const { return fUnitsPerEM; }; - virtual le_int32 getAscent() const - { - return (le_int32)fAscent; - } - - virtual le_int32 getDescent() const - { - return (le_int32)fDescent; - } - - virtual le_int32 getLeading() const - { - return (le_int32)fLeading; - } - - virtual float getExactAscent() const + virtual float getAscent() const { return fAscent; } - virtual float getExactDescent() const + virtual float getDescent() const { return fDescent; } - virtual float getExactLeading() const - { - return fLeading; - } - - virtual LEGlyphID mapCharToGlyph(LEUnicode32 ch) const - { - return fCMAPMapper->unicodeToGlyph(ch); - } - - virtual LEGlyphID mapGlyphToIndex(const char* glyphName) const; + virtual GlyphID mapCharToGlyph(UChar32 ch) const = 0; /* must be implemented by subclass */ + virtual GlyphID mapGlyphToIndex(const char* glyphName) const; - virtual le_uint16 getNumGlyphs() const; + virtual uint16_t getNumGlyphs() const; - virtual void getGlyphAdvance(LEGlyphID glyph, LEPoint &advance) const; + virtual void getGlyphAdvance(GlyphID glyph, realpoint &advance) const; - virtual le_bool getGlyphPoint(LEGlyphID glyph, le_int32 pointNumber, LEPoint &point) const; + virtual void getGlyphBounds(GlyphID glyph, GlyphBBox *bbox) = 0; /* must be implemented by subclass */ - virtual void getGlyphBounds(LEGlyphID glyph, GlyphBBox *bbox) = 0; /* must be implemented by subclass */ + float getGlyphWidth(GlyphID glyph); + void getGlyphHeightDepth(GlyphID glyph, float *ht, float* dp); + void getGlyphSidebearings(GlyphID glyph, float* lsb, float* rsb); + float getGlyphItalCorr(GlyphID glyph); - float getGlyphWidth(LEGlyphID glyph); - void getGlyphHeightDepth(LEGlyphID glyph, float *ht, float* dp); - void getGlyphSidebearings(LEGlyphID glyph, float* lsb, float* rsb); - float getGlyphItalCorr(LEGlyphID glyph); - - virtual const char* getGlyphName(LEGlyphID gid, int& nameLen); + virtual const char* getGlyphName(GlyphID gid, int& nameLen); - virtual LEUnicode32 getFirstCharCode(); - virtual LEUnicode32 getLastCharCode(); - - float getXPixelsPerEm() const - { - return fPointSize; - }; + virtual UChar32 getFirstCharCode() = 0; /* must be implemented by subclass */ + virtual UChar32 getLastCharCode() = 0; /* must be implemented by subclass */ - float getYPixelsPerEm() const + float getPointSize() const { return fPointSize; }; - float getScaleFactorX() const - { - return 1.0; - } - - float getScaleFactorY() const - { - return 1.0; - } + float unitsToPoints(float units) const + { + return (units * fPointSize) / (float) fUnitsPerEM; + } - float getXHeight() const - { - return fXHeight; - } + float pointsToUnits(float points) const + { + return (points * (float) fUnitsPerEM) / fPointSize; + } float getItalicAngle() const { return fItalicAngle; } + + hb_font_t* hbFont; }; #endif diff --git a/Build/source/texk/web2c/xetexdir/XeTeXFontInst_FT2.cpp b/Build/source/texk/web2c/xetexdir/XeTeXFontInst_FT2.cpp index fde74d657dd..e7862e7d84f 100644 --- a/Build/source/texk/web2c/xetexdir/XeTeXFontInst_FT2.cpp +++ b/Build/source/texk/web2c/xetexdir/XeTeXFontInst_FT2.cpp @@ -1,9 +1,9 @@ /****************************************************************************\ Part of the XeTeX typesetting system - copyright (c) 1994-2008 by SIL International - copyright (c) 2009 by Jonathan Kew + Copyright (c) 1994-2008 by SIL International + Copyright (c) 2009 by Jonathan Kew - Written by Jonathan Kew + SIL Author(s): Jonathan Kew Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -48,12 +48,11 @@ authorization from the copyright holders. FT_Library gFreeTypeLibrary = 0; -XeTeXFontInst_FT2::XeTeXFontInst_FT2(const char* pathname, int index, float pointSize, LEErrorCode &status) +XeTeXFontInst_FT2::XeTeXFontInst_FT2(const char* pathname, int index, float pointSize, int &status) : XeTeXFontInst(pointSize, status) , face(0) - , fFreeTypeOnly(false) { - if (LE_FAILURE(status)) { + if (status != 0) { return; } @@ -69,7 +68,7 @@ XeTeXFontInst_FT2::XeTeXFontInst_FT2(const char* pathname, int index, float poin err = FT_New_Face(gFreeTypeLibrary, (char*)pathname, index, &face); if (err != 0) { - status = LE_FONT_FILE_NOT_FOUND_ERROR; + status = 1; return; } @@ -84,13 +83,15 @@ XeTeXFontInst_FT2::XeTeXFontInst_FT2(const char* pathname, int index, float poin strcpy(p, ".afm"); // else replace extension with .afm FT_Attach_File(face, afm); // ignore error code; AFM might not exist delete[] afm; - fFreeTypeOnly = true; } initialize(status); - if (LE_FAILURE(status)) + if (status != 0) return; + + FT_Set_Pixel_Sizes(face, pointSize, 0); + hbFont = hb_ft_font_create(face, NULL); char buf[20]; if (index > 0) @@ -107,27 +108,26 @@ XeTeXFontInst_FT2::~XeTeXFontInst_FT2() FT_Done_Face(face); face = 0; } + hb_font_destroy(hbFont); } -void XeTeXFontInst_FT2::initialize(LEErrorCode &status) +void XeTeXFontInst_FT2::initialize(int &status) { if (face == 0) { - status = LE_FONT_FILE_NOT_FOUND_ERROR; + status = 1; return; } XeTeXFontInst::initialize(status); - if (LE_FAILURE(status)) { + if (status != 0) { /* font can ONLY be used via FreeType APIs, not direct table access */ - fFreeTypeOnly = true; - status = LE_NO_ERROR; + status = 0; /* fill in fields that XeTeXFontInst::initialize failed to get for us */ fUnitsPerEM = face->units_per_EM; - fAscent = yUnitsToPoints(face->ascender); - fDescent = yUnitsToPoints(face->descender); -// fLeading = ; + fAscent = unitsToPoints(face->ascender); + fDescent = unitsToPoints(face->descender); fItalicAngle = 0; PS_FontInfoRec font_info; if (FT_Get_PS_Font_Info(face, &font_info) == 0) { @@ -139,7 +139,7 @@ void XeTeXFontInst_FT2::initialize(LEErrorCode &status) return; } -const void *XeTeXFontInst_FT2::readTable(LETag tag, le_uint32 *length) const +const void *XeTeXFontInst_FT2::readTable(OTTag tag, uint32_t *length) const { *length = 0; FT_ULong tmpLength = 0; @@ -147,11 +147,11 @@ const void *XeTeXFontInst_FT2::readTable(LETag tag, le_uint32 *length) const if (err != 0) return NULL; - void* table = LE_NEW_ARRAY(char, tmpLength); + void* table = xmalloc(tmpLength * sizeof(char)); if (table != NULL) { err = FT_Load_Sfnt_Table(face, tag, 0, (FT_Byte*)table, &tmpLength); if (err != 0) { - LE_DELETE_ARRAY(table); + free((void *) table); return NULL; } *length = tmpLength; @@ -161,7 +161,7 @@ const void *XeTeXFontInst_FT2::readTable(LETag tag, le_uint32 *length) const } void -XeTeXFontInst_FT2::getGlyphBounds(LEGlyphID gid, GlyphBBox* bbox) +XeTeXFontInst_FT2::getGlyphBounds(GlyphID gid, GlyphBBox* bbox) { bbox->xMin = bbox->yMin = bbox->xMax = bbox->yMax = 0.0; @@ -174,73 +174,52 @@ XeTeXFontInst_FT2::getGlyphBounds(LEGlyphID gid, GlyphBBox* bbox) if (err == 0) { FT_BBox ft_bbox; FT_Glyph_Get_CBox(glyph, FT_GLYPH_BBOX_UNSCALED, &ft_bbox); - bbox->xMin = ft_bbox.xMin * fPointSize / fUnitsPerEM; - bbox->yMin = ft_bbox.yMin * fPointSize / fUnitsPerEM; - bbox->xMax = ft_bbox.xMax * fPointSize / fUnitsPerEM; - bbox->yMax = ft_bbox.yMax * fPointSize / fUnitsPerEM; + bbox->xMin = unitsToPoints(ft_bbox.xMin); + bbox->yMin = unitsToPoints(ft_bbox.yMin); + bbox->xMax = unitsToPoints(ft_bbox.xMax); + bbox->yMax = unitsToPoints(ft_bbox.yMax); FT_Done_Glyph(glyph); } } -LEGlyphID -XeTeXFontInst_FT2::mapCharToGlyph(LEUnicode32 ch) const +GlyphID +XeTeXFontInst_FT2::mapCharToGlyph(UChar32 ch) const { - if (!fFreeTypeOnly) - return XeTeXFontInst::mapCharToGlyph(ch); - return FT_Get_Char_Index(face, ch); } -le_uint16 +uint16_t XeTeXFontInst_FT2::getNumGlyphs() const { return face->num_glyphs; } void -XeTeXFontInst_FT2::getGlyphAdvance(LEGlyphID glyph, LEPoint &advance) const +XeTeXFontInst_FT2::getGlyphAdvance(GlyphID glyph, realpoint &advance) const { - if (!fFreeTypeOnly) - XeTeXFontInst::getGlyphAdvance(glyph, advance); + FT_Error err = FT_Load_Glyph(face, glyph, FT_LOAD_NO_SCALE); + if (err != 0) { + advance.x = advance.y = 0; + } else { - FT_Error err = FT_Load_Glyph(face, glyph, FT_LOAD_NO_SCALE); - if (err != 0) { - advance.fX = advance.fY = 0; - } - else { - advance.fX = fVertical ? 0 : face->glyph->metrics.horiAdvance * fPointSize / fUnitsPerEM; - advance.fY = fVertical ? face->glyph->metrics.vertAdvance * fPointSize / fUnitsPerEM : 0; - } + advance.x = fVertical ? 0 : unitsToPoints(face->glyph->metrics.horiAdvance); + advance.y = fVertical ? unitsToPoints(face->glyph->metrics.vertAdvance) : 0; } } -LEGlyphID +GlyphID XeTeXFontInst_FT2::mapGlyphToIndex(const char* glyphName) const { - LEGlyphID rval = FT_Get_Name_Index(face, const_cast(glyphName)); + GlyphID rval = FT_Get_Name_Index(face, const_cast(glyphName)); if (rval == 0) rval = XeTeXFontInst::mapGlyphToIndex(glyphName); return rval; } -void -XeTeXFontInst_FT2::getKernPair(LEGlyphID leftGlyph, LEGlyphID rightGlyph, LEPoint &kern) const -{ - FT_Vector kerning; - if (FT_Get_Kerning(face, leftGlyph, rightGlyph, FT_KERNING_UNSCALED, &kerning) == 0) { - kern.fX = kerning.x; - kern.fY = kerning.y; - } - else - kern.fX = kern.fY = 0; -} - const char* -XeTeXFontInst_FT2::getGlyphName(LEGlyphID gid, int& nameLen) +XeTeXFontInst_FT2::getGlyphName(GlyphID gid, int& nameLen) { - if (!fFreeTypeOnly) - return XeTeXFontInst::getGlyphName(gid, nameLen); - else if (FT_HAS_GLYPH_NAMES(face)) { + if (FT_HAS_GLYPH_NAMES(face)) { static char buffer[256]; FT_Get_Glyph_Name(face, gid, buffer, 256); nameLen = strlen(buffer); @@ -252,30 +231,22 @@ XeTeXFontInst_FT2::getGlyphName(LEGlyphID gid, int& nameLen) } } -LEUnicode32 +UChar32 XeTeXFontInst_FT2::getFirstCharCode() { - if (!fFreeTypeOnly) - return XeTeXFontInst::getFirstCharCode(); - else { - FT_UInt gindex; - return FT_Get_First_Char(face, &gindex); - } + FT_UInt gindex; + return FT_Get_First_Char(face, &gindex); } -LEUnicode32 +UChar32 XeTeXFontInst_FT2::getLastCharCode() { - if (!fFreeTypeOnly) - return XeTeXFontInst::getLastCharCode(); - else { - FT_UInt gindex; - LEUnicode32 ch = FT_Get_First_Char(face, &gindex); - LEUnicode32 prev = ch; - while (gindex != 0) { - prev = ch; - ch = FT_Get_Next_Char(face, ch, &gindex); - } - return prev; + FT_UInt gindex; + UChar32 ch = FT_Get_First_Char(face, &gindex); + UChar32 prev = ch; + while (gindex != 0) { + prev = ch; + ch = FT_Get_Next_Char(face, ch, &gindex); } + return prev; } diff --git a/Build/source/texk/web2c/xetexdir/XeTeXFontInst_FT2.h b/Build/source/texk/web2c/xetexdir/XeTeXFontInst_FT2.h index ab1c22a417a..570b6e54670 100644 --- a/Build/source/texk/web2c/xetexdir/XeTeXFontInst_FT2.h +++ b/Build/source/texk/web2c/xetexdir/XeTeXFontInst_FT2.h @@ -1,9 +1,9 @@ /****************************************************************************\ Part of the XeTeX typesetting system - copyright (c) 1994-2008 by SIL International - copyright (c) 2009 by Jonathan Kew + Copyright (c) 1994-2008 by SIL International + Copyright (c) 2009 by Jonathan Kew - Written by Jonathan Kew + SIL Author(s): Jonathan Kew Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -50,29 +50,27 @@ class XeTeXFontInst_FT2 : public XeTeXFontInst { protected: - const void * readTable(LETag tag, le_uint32 *length) const; + const void * readTable(OTTag tag, uint32_t *length) const; FT_Face face; - bool fFreeTypeOnly; public: - XeTeXFontInst_FT2(const char* filename, int index, float pointSize, LEErrorCode &status); + XeTeXFontInst_FT2(const char* filename, int index, float pointSize, int &status); virtual ~XeTeXFontInst_FT2(); - virtual void initialize(LEErrorCode &status); + virtual void initialize(int &status); - virtual void getGlyphBounds(LEGlyphID gid, GlyphBBox* bbox); + virtual void getGlyphBounds(GlyphID gid, GlyphBBox* bbox); // overrides of XeTeXFontInst methods, in case it's not an sfnt - virtual le_uint16 getNumGlyphs() const; - virtual void getGlyphAdvance(LEGlyphID glyph, LEPoint &advance) const; - virtual LEGlyphID mapCharToGlyph(LEUnicode32 ch) const; - virtual LEGlyphID mapGlyphToIndex(const char* glyphName) const; - virtual void getKernPair(LEGlyphID leftGlyph, LEGlyphID rightGlyph, LEPoint &kern) const; - virtual const char* getGlyphName(LEGlyphID gid, int& nameLen); - virtual LEUnicode32 getFirstCharCode(); - virtual LEUnicode32 getLastCharCode(); + virtual uint16_t getNumGlyphs() const; + virtual void getGlyphAdvance(GlyphID glyph, realpoint &advance) const; + virtual GlyphID mapCharToGlyph(UChar32 ch) const; + virtual GlyphID mapGlyphToIndex(const char* glyphName) const; + virtual const char* getGlyphName(GlyphID gid, int& nameLen); + virtual UChar32 getFirstCharCode(); + virtual UChar32 getLastCharCode(); }; #endif diff --git a/Build/source/texk/web2c/xetexdir/XeTeXFontInst_Mac.cpp b/Build/source/texk/web2c/xetexdir/XeTeXFontInst_Mac.cpp index 4737c497b59..5a4c26e15d9 100644 --- a/Build/source/texk/web2c/xetexdir/XeTeXFontInst_Mac.cpp +++ b/Build/source/texk/web2c/xetexdir/XeTeXFontInst_Mac.cpp @@ -1,9 +1,9 @@ /****************************************************************************\ Part of the XeTeX typesetting system - copyright (c) 1994-2008 by SIL International - copyright (c) 2009 by Jonathan Kew + Copyright (c) 1994-2008 by SIL International + Copyright (c) 2009 by Jonathan Kew - Written by Jonathan Kew + SIL Author(s): Jonathan Kew Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -41,12 +41,14 @@ authorization from the copyright holders. #include "XeTeXFontInst_Mac.h" #include "XeTeX_ext.h" -XeTeXFontInst_Mac::XeTeXFontInst_Mac(ATSFontRef atsFont, float pointSize, LEErrorCode &status) +XeTeXFontInst_Mac::XeTeXFontInst_Mac(ATSFontRef atsFont, float pointSize, int &status) : XeTeXFontInst(pointSize, status) , fFontRef(atsFont) , fStyle(0) + , fFirstCharCode(-1) + , fLastCharCode(-1) { - if (LE_FAILURE(status)) { + if (status != 0) { return; } @@ -59,48 +61,102 @@ XeTeXFontInst_Mac::~XeTeXFontInst_Mac() ATSUDisposeStyle(fStyle); } -void XeTeXFontInst_Mac::initialize(LEErrorCode &status) +static hb_bool_t _get_glyph(hb_font_t* hbFont, void* fontData, hb_codepoint_t unicode, hb_codepoint_t variationSelector, hb_codepoint_t* glyph, void* userData) +{ + *glyph = MapCharToGlyph_AAT((ATSUStyle) fontData, unicode); + return !!glyph; +} + +static hb_position_t _get_glyph_h_advance(hb_font_t* hbFont, void* fontData, hb_codepoint_t glyph, void* userData) +{ + float width = GetGlyphWidth_AAT((ATSUStyle) fontData, glyph); + return width * 64; +} + +static hb_bool_t _get_glyph_extents(hb_font_t* hbFont, void* fontData, hb_codepoint_t glyph, hb_glyph_extents_t* extents, void* userData) +{ + GlyphBBox bbox; + GetGlyphBBox_AAT((ATSUStyle) fontData, glyph, &bbox); + extents->x_bearing = bbox.xMin; + extents->y_bearing = bbox.yMax; + extents->width = bbox.xMax - bbox.xMin; + extents->height = bbox.yMax - bbox.yMin; + + return true; +} + +static hb_font_funcs_t* _get_font_funcs() +{ + static hb_font_funcs_t* _font_funcs = 0; + _font_funcs = hb_font_funcs_create(); + hb_font_funcs_set_glyph_func(_font_funcs, _get_glyph, 0, 0); + hb_font_funcs_set_glyph_h_advance_func(_font_funcs, _get_glyph_h_advance, 0, 0); + hb_font_funcs_set_glyph_extents_func(_font_funcs, _get_glyph_extents, 0, 0); + hb_font_funcs_make_immutable(_font_funcs); + + return _font_funcs; +} + +static hb_blob_t* _get_font_table(hb_face_t* face, hb_tag_t tag, void* userData) +{ + XeTeXFontInst* font = (XeTeXFontInst*) userData; + uint32_t length; + const void *table = font->getFontTable((OTTag) tag, &length); + if (!table || !length) + return 0; + return hb_blob_create((const char*) table, length, HB_MEMORY_MODE_READONLY, NULL, NULL); +} + +void XeTeXFontInst_Mac::initialize(int &status) { if (fFontRef == 0) { - status = LE_FONT_FILE_NOT_FOUND_ERROR; + status = 1; return; } XeTeXFontInst::initialize(status); - if (status != LE_NO_ERROR) + if (status != 0) fFontRef = 0; if (ATSUCreateStyle(&fStyle) == noErr) { ATSUFontID font = FMGetFontFromATSFontRef(fFontRef); - Fixed size = X2Fix(fPointSize * 72.0 / 72.27); /* convert TeX to Quartz points */ + Fixed size = D2Fix(fPointSize * 72.0 / 72.27); /* convert TeX to Quartz points */ ATSStyleRenderingOptions options = kATSStyleNoHinting; ATSUAttributeTag tags[3] = { kATSUFontTag, kATSUSizeTag, kATSUStyleRenderingOptionsTag }; ByteCount valueSizes[3] = { sizeof(ATSUFontID), sizeof(Fixed), sizeof(ATSStyleRenderingOptions) }; ATSUAttributeValuePtr values[3] = { &font, &size, &options }; ATSUSetAttributes(fStyle, 3, tags, valueSizes, values); + + /* for HarfBuzz */ + hb_face_t* lFace = hb_face_create_for_tables(_get_font_table, this, 0); + hb_face_set_upem (lFace, fUnitsPerEM); + hbFont = hb_font_create(lFace); + hb_font_set_funcs(hbFont, _get_font_funcs(), fStyle, 0); + hb_font_set_scale(hbFont, fPointSize, fPointSize); + hb_font_set_ppem(hbFont, fPointSize, fPointSize); } else { - status = LE_FONT_FILE_NOT_FOUND_ERROR; + status = 1; fFontRef = 0; } return; } -const void *XeTeXFontInst_Mac::readTable(LETag tag, le_uint32 *length) const +const void *XeTeXFontInst_Mac::readTable(OTTag tag, uint32_t *length) const { OSStatus status = ATSFontGetTable(fFontRef, tag, 0, 0, 0, (ByteCount*)length); if (status != noErr) { *length = 0; return NULL; } - void* table = LE_NEW_ARRAY(char, *length); + void* table = xmalloc(*length * sizeof(char)); if (table != NULL) { status = ATSFontGetTable(fFontRef, tag, 0, *length, table, (ByteCount*)length); if (status != noErr) { *length = 0; - LE_DELETE_ARRAY(table); + free((void*) table); return NULL; } } @@ -108,25 +164,55 @@ const void *XeTeXFontInst_Mac::readTable(LETag tag, le_uint32 *length) const return table; } -void XeTeXFontInst_Mac::getGlyphBounds(LEGlyphID gid, GlyphBBox* bbox) +void XeTeXFontInst_Mac::getGlyphBounds(GlyphID gid, GlyphBBox* bbox) { GetGlyphBBox_AAT(fStyle, gid, bbox); } -LEGlyphID +GlyphID +XeTeXFontInst_Mac::mapCharToGlyph(UChar32 ch) const +{ + return MapCharToGlyph_AAT(fStyle, ch); +} + +GlyphID XeTeXFontInst_Mac::mapGlyphToIndex(const char* glyphName) const { - LEGlyphID rval = XeTeXFontInst::mapGlyphToIndex(glyphName); + GlyphID rval = XeTeXFontInst::mapGlyphToIndex(glyphName); if (rval) return rval; return GetGlyphIDFromCGFont(fFontRef, glyphName); } const char* -XeTeXFontInst_Mac::getGlyphName(LEGlyphID gid, int& nameLen) +XeTeXFontInst_Mac::getGlyphName(GlyphID gid, int& nameLen) { const char* rval = XeTeXFontInst::getGlyphName(gid, nameLen); if (rval) return rval; return GetGlyphNameFromCGFont(fFontRef, gid, &nameLen); } + +UChar32 +XeTeXFontInst_Mac::getFirstCharCode() +{ + if (fFirstCharCode == -1) { + int ch = 0; + while (mapCharToGlyph(ch) == 0 && ch < 0x10ffff) + ++ch; + fFirstCharCode = ch; + } + return fFirstCharCode; +} + +UChar32 +XeTeXFontInst_Mac::getLastCharCode() +{ + if (fLastCharCode == -1) { + int ch = 0x10ffff; + while (mapCharToGlyph(ch) == 0 && ch > 0) + --ch; + fLastCharCode = ch; + } + return fLastCharCode; +} diff --git a/Build/source/texk/web2c/xetexdir/XeTeXFontInst_Mac.h b/Build/source/texk/web2c/xetexdir/XeTeXFontInst_Mac.h index 5d26d417e35..e3ab7bce439 100644 --- a/Build/source/texk/web2c/xetexdir/XeTeXFontInst_Mac.h +++ b/Build/source/texk/web2c/xetexdir/XeTeXFontInst_Mac.h @@ -1,9 +1,9 @@ /****************************************************************************\ Part of the XeTeX typesetting system - copyright (c) 1994-2008 by SIL International - copyright (c) 2009 by Jonathan Kew + Copyright (c) 1994-2008 by SIL International + Copyright (c) 2009 by Jonathan Kew - Written by Jonathan Kew + SIL Author(s): Jonathan Kew Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -48,22 +48,30 @@ authorization from the copyright holders. class XeTeXFontInst_Mac : public XeTeXFontInst { protected: - const void *readTable(LETag tag, le_uint32 *length) const; + const void *readTable(OTTag tag, uint32_t *length) const; ATSFontRef fFontRef; ATSUStyle fStyle; + int fFirstCharCode; + int fLastCharCode; + public: - XeTeXFontInst_Mac(ATSFontRef atsFont, float pointSize, LEErrorCode &status); + XeTeXFontInst_Mac(ATSFontRef atsFont, float pointSize, int &status); virtual ~XeTeXFontInst_Mac(); - virtual void initialize(LEErrorCode &status); + virtual void initialize(int &status); - virtual void getGlyphBounds(LEGlyphID gid, GlyphBBox* bbox); + virtual void getGlyphBounds(GlyphID gid, GlyphBBox* bbox); + + virtual GlyphID mapCharToGlyph(UChar32 ch) const; + virtual GlyphID mapGlyphToIndex(const char* glyphName) const; + + virtual const char* getGlyphName(GlyphID gid, int& nameLen); - virtual LEGlyphID mapGlyphToIndex(const char* glyphName) const; - virtual const char* getGlyphName(LEGlyphID gid, int& nameLen); + virtual UChar32 getFirstCharCode(); + virtual UChar32 getLastCharCode(); }; #endif diff --git a/Build/source/texk/web2c/xetexdir/XeTeXFontMgr.cpp b/Build/source/texk/web2c/xetexdir/XeTeXFontMgr.cpp index 7da6829dcb2..3521a6b9b35 100644 --- a/Build/source/texk/web2c/xetexdir/XeTeXFontMgr.cpp +++ b/Build/source/texk/web2c/xetexdir/XeTeXFontMgr.cpp @@ -1,9 +1,9 @@ /****************************************************************************\ Part of the XeTeX typesetting system - copyright (c) 1994-2008 by SIL International - copyright (c) 2009-2012 by Jonathan Kew + Copyright (c) 1994-2008 by SIL International + Copyright (c) 2009-2012 by Jonathan Kew - Written by Jonathan Kew + SIL Author(s): Jonathan Kew Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -35,20 +35,10 @@ authorization from the copyright holders. #else #include "XeTeXFontMgr_FC.h" #endif - +#include "XeTeXFontInst.h" #include "XeTeXswap.h" - -#include "layout/ICUFeatures.h" -#include "layout/GlyphPositioningTables.h" - #include "sfnt.h" -#include -/* apparently M_PI isn't defined by under VC++ */ -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif - extern "C" { extern Fixed loadedfontdesignsize; } @@ -229,32 +219,14 @@ XeTeXFontMgr::findFont(const char* name, char* variant, double ptSize) varString.append("AAT"); goto skip_to_slash; } - if (strncmp(cp, "ICU", 3) == 0) { - sReqEngine = 'I'; - cp += 3; - if (varString.length() > 0 && *(varString.end() - 1) != '/') - varString.append("/"); - varString.append("ICU"); - goto skip_to_slash; - } -/* - if (strncmp(cp, "USP", 3) == 0) { - sReqEngine = 'U'; + if ((strncmp(cp, "OTF", 3) == 0) || (strncmp(cp, "ICU", 3) == 0)) { + sReqEngine = 'O'; cp += 3; if (varString.length() > 0 && *(varString.end() - 1) != '/') varString.append("/"); - varString.append("USP"); + varString.append("OTF"); goto skip_to_slash; } - if (strncmp(cp, "PAN", 3) == 0) { - sReqEngine = 'P'; - cp += 3; - if (varString.length() > 0 && *(varString.end() - 1) != '/') - varString.append("/"); - varString.append("PAN"); - goto skip_to_slash; - } -*/ if (strncmp(cp, "GR", 2) == 0) { sReqEngine = 'G'; cp += 2; @@ -450,12 +422,6 @@ XeTeXFontMgr::getNames(PlatformFontRef font, const char** psName, *styName = i->second->styleName->c_str(); } -char -XeTeXFontMgr::getReqEngine() const -{ - return sReqEngine; -} - int XeTeXFontMgr::weightAndWidthDiff(const Font* a, const Font* b) const { @@ -495,47 +461,25 @@ XeTeXFontMgr::bestMatchFromFamily(const Family* fam, int wt, int wd, int slant) } const XeTeXFontMgr::OpSizeRec* -XeTeXFontMgr::getOpSizePtr(XeTeXFont font) +XeTeXFontMgr::getOpSize(XeTeXFont font) { - const GlyphPositioningTableHeader* gposTable = (const GlyphPositioningTableHeader*)getFontTablePtr(font, LE_GPOS_TABLE_TAG); - if (gposTable != NULL) { - const FeatureListTable* featureListTable = (const FeatureListTable*)((const char*)gposTable + SWAP(gposTable->featureListOffset)); - for (int i = 0; i < SWAP(featureListTable->featureCount); ++i) { - UInt32 tag = SWAPT(featureListTable->featureRecordArray[i].featureTag); - if (tag == LE_SIZE_FEATURE_TAG) { - const FeatureTable* feature = (const FeatureTable*)((const char*)featureListTable - + SWAP(featureListTable->featureRecordArray[i].featureTableOffset)); - UInt16 offset = SWAP(feature->featureParamsOffset); - const OpSizeRec* pSizeRec; - /* if featureParamsOffset < (offset of feature from featureListTable), - then we have a correct size table; - otherwise we (presumably) have a "broken" one from the old FDK */ - for (int i = 0; i < 2; ++i) { - if (i == 0) - pSizeRec = (const OpSizeRec*)((char*)feature + offset); - else - pSizeRec = (const OpSizeRec*)((char*)featureListTable + offset); - if (SWAP(pSizeRec->designSize) == 0) - continue; // incorrect 'size' feature format - if (SWAP(pSizeRec->subFamilyID) == 0 - && SWAP(pSizeRec->nameCode) == 0 - && SWAP(pSizeRec->minSize) == 0 - && SWAP(pSizeRec->maxSize) == 0) - return pSizeRec; // feature is valid, but no 'size' range - if (SWAP(pSizeRec->designSize) < SWAP(pSizeRec->minSize)) // check values are valid - continue; // else try different interpretation - if (SWAP(pSizeRec->designSize) > SWAP(pSizeRec->maxSize)) - continue; - if (SWAP(pSizeRec->maxSize) < SWAP(pSizeRec->minSize)) - continue; - if (SWAP(pSizeRec->nameCode) < 256) - continue; - if (SWAP(pSizeRec->nameCode) > 32767) - continue; - return pSizeRec; - } - } - } + hb_font_t* hbFont = ((XeTeXFontInst*)font)->hbFont; + if (hbFont != NULL) { + hb_face_t* face = hb_font_get_face(hbFont); + OpSizeRec* pSizeRec = (OpSizeRec*) xmalloc(sizeof(OpSizeRec)); + + bool ok = hb_ot_layout_get_size_params(face, + &pSizeRec->designSize, + &pSizeRec->subFamilyID, + &pSizeRec->nameCode, + &pSizeRec->minSize, + &pSizeRec->maxSize); + + if (ok) + return pSizeRec; + + free(pSizeRec); + return NULL; } return NULL; @@ -544,9 +488,9 @@ XeTeXFontMgr::getOpSizePtr(XeTeXFont font) double XeTeXFontMgr::getDesignSize(XeTeXFont font) { - const OpSizeRec* pSizeRec = getOpSizePtr(font); + const OpSizeRec* pSizeRec = getOpSize(font); if (pSizeRec != NULL) - return SWAP(pSizeRec->designSize) / 10.0; + return pSizeRec->designSize / 10.0; else return 10.0; } @@ -556,22 +500,22 @@ XeTeXFontMgr::getOpSizeRecAndStyleFlags(Font* theFont) { XeTeXFont font = createFont(theFont->fontRef, 655360); if (font != 0) { - const OpSizeRec* pSizeRec = getOpSizePtr(font); + const OpSizeRec* pSizeRec = getOpSize(font); if (pSizeRec != NULL) { - theFont->opSizeInfo.designSize = SWAP(pSizeRec->designSize); - if (SWAP(pSizeRec->subFamilyID) == 0 - && SWAP(pSizeRec->nameCode) == 0 - && SWAP(pSizeRec->minSize) == 0 - && SWAP(pSizeRec->maxSize) == 0) + theFont->opSizeInfo.designSize = pSizeRec->designSize; + if (pSizeRec->subFamilyID == 0 + && pSizeRec->nameCode == 0 + && pSizeRec->minSize == 0 + && pSizeRec->maxSize == 0) goto done_size; // feature is valid, but no 'size' range - theFont->opSizeInfo.subFamilyID = SWAP(pSizeRec->subFamilyID); - theFont->opSizeInfo.nameCode = SWAP(pSizeRec->nameCode); - theFont->opSizeInfo.minSize = SWAP(pSizeRec->minSize); - theFont->opSizeInfo.maxSize = SWAP(pSizeRec->maxSize); + theFont->opSizeInfo.subFamilyID = pSizeRec->subFamilyID; + theFont->opSizeInfo.nameCode = pSizeRec->nameCode; + theFont->opSizeInfo.minSize = pSizeRec->minSize; + theFont->opSizeInfo.maxSize = pSizeRec->maxSize; } done_size: - const OS2TableHeader* os2Table = (const OS2TableHeader*)getFontTablePtr(font, LE_OS_2_TABLE_TAG); + const OS2TableHeader* os2Table = (const OS2TableHeader*)getFontTablePtr(font, kOS_2); if (os2Table != NULL) { theFont->weight = SWAP(os2Table->usWeightClass); theFont->width = SWAP(os2Table->usWidthClass); @@ -581,7 +525,7 @@ XeTeXFontMgr::getOpSizeRecAndStyleFlags(Font* theFont) theFont->isItalic = (sel & (1 << 0)) != 0; } - const HEADTable* headTable = (const HEADTable*)getFontTablePtr(font, LE_HEAD_TABLE_TAG); + const HEADTable* headTable = (const HEADTable*)getFontTablePtr(font, kHEAD); if (headTable != NULL) { UInt16 ms = SWAP(headTable->macStyle); if ((ms & (1 << 0)) != 0) @@ -590,9 +534,9 @@ XeTeXFontMgr::getOpSizeRecAndStyleFlags(Font* theFont) theFont->isItalic = true; } - const POSTTable* postTable = (const POSTTable*)getFontTablePtr(font, LE_POST_TABLE_TAG); + const POSTTable* postTable = (const POSTTable*)getFontTablePtr(font, kPOST); if (postTable != NULL) { - theFont->slant = (int)(1000 * (tan(Fix2X(-SWAP(UInt32(postTable->italicAngle))) * M_PI / 180.0))); + theFont->slant = (int)(1000 * (tan(Fix2D(-SWAP(UInt32(postTable->italicAngle))) * M_PI / 180.0))); } deleteFont(font); } diff --git a/Build/source/texk/web2c/xetexdir/XeTeXFontMgr.h b/Build/source/texk/web2c/xetexdir/XeTeXFontMgr.h index 8dcc2b962d8..358d540ad0b 100644 --- a/Build/source/texk/web2c/xetexdir/XeTeXFontMgr.h +++ b/Build/source/texk/web2c/xetexdir/XeTeXFontMgr.h @@ -1,9 +1,9 @@ /****************************************************************************\ Part of the XeTeX typesetting system - copyright (c) 1994-2008 by SIL International - copyright (c) 2009 by Jonathan Kew + Copyright (c) 1994-2008 by SIL International + Copyright (c) 2009 by Jonathan Kew - Written by Jonathan Kew + SIL Author(s): Jonathan Kew Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -64,14 +64,14 @@ public: PlatformFontRef findFont(const char* name, char* variant, double ptSize); // 1st arg is name as specified by user (C string, UTF-8) - // 2nd is /B/I/AAT/ICU[/USP]/S=## qualifiers + // 2nd is /B/I/AAT/OTF/ICU[/GR]/S=## qualifiers // 1. try name given as "full name" // 2. if there's a hyphen, split and try "family-style" // 3. try as PostScript name // 4. try name as family with "Regular/Plain/Normal" style // apply style qualifiers and optical sizing if present - // SIDE EFFECT: sets sReqEngine to 'A' or 'I' [or 'U'] if appropriate, + // SIDE EFFECT: sets sReqEngine to 'A' or 'O' [or 'G'] if appropriate, // else clears it to 0 // SIDE EFFECT: updates TeX variables /nameoffile/ and /namelength/, @@ -89,7 +89,10 @@ public: double getDesignSize(XeTeXFont font); - char getReqEngine() const; + char getReqEngine() const { return sReqEngine; }; + + void setReqEngine(char reqEngine) const { sReqEngine = reqEngine; }; + // return the requested rendering technology for the most recent findFont // or 0 if no specific technology was requested @@ -111,11 +114,11 @@ protected: class Family; struct OpSizeRec { - unsigned short designSize; - unsigned short subFamilyID; - unsigned short nameCode; - unsigned short minSize; - unsigned short maxSize; + unsigned int designSize; + unsigned int subFamilyID; + unsigned int nameCode; + unsigned int minSize; + unsigned int maxSize; }; class Font { @@ -189,7 +192,7 @@ protected: void prependToList(std::list* list, const char* str); void addToMaps(PlatformFontRef platformFont, const NameCollection* names); - const OpSizeRec* getOpSizePtr(XeTeXFont font); + const OpSizeRec* getOpSize(XeTeXFont font); virtual void getOpSizeRecAndStyleFlags(Font* theFont); virtual void searchForHostPlatformFonts(const std::string& name) = 0; diff --git a/Build/source/texk/web2c/xetexdir/XeTeXFontMgr_FC.cpp b/Build/source/texk/web2c/xetexdir/XeTeXFontMgr_FC.cpp index 05891879e44..f487d509d50 100644 --- a/Build/source/texk/web2c/xetexdir/XeTeXFontMgr_FC.cpp +++ b/Build/source/texk/web2c/xetexdir/XeTeXFontMgr_FC.cpp @@ -1,9 +1,9 @@ /****************************************************************************\ Part of the XeTeX typesetting system - copyright (c) 1994-2008 by SIL International - copyright (c) 2009, 2011 by Jonathan Kew + Copyright (c) 1994-2008 by SIL International + Copyright (c) 2009, 2011 by Jonathan Kew - Written by Jonathan Kew + SIL Author(s): Jonathan Kew Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -40,7 +40,7 @@ authorization from the copyright holders. #include FT_SFNT_NAMES_H #include FT_TRUETYPE_IDS_H -#include "unicode/ucnv.h" +#include #define kFontFamilyName 1 #define kFontStyleName 2 @@ -327,7 +327,7 @@ XeTeXFontMgr_FC::initialize() FcPattern* pat = FcNameParse((const FcChar8*)":outline=true"); FcObjectSet* os = FcObjectSetBuild(FC_FAMILY, FC_STYLE, FC_FILE, FC_INDEX, - FC_FULLNAME, FC_WEIGHT, FC_WIDTH, FC_SLANT, NULL); + FC_FULLNAME, FC_WEIGHT, FC_WIDTH, FC_SLANT, FC_FONTFORMAT, NULL); allFonts = FcFontList(FcConfigGetCurrent(), pat, os); FcObjectSetDestroy(os); FcPatternDestroy(pat); diff --git a/Build/source/texk/web2c/xetexdir/XeTeXFontMgr_FC.h b/Build/source/texk/web2c/xetexdir/XeTeXFontMgr_FC.h index 737eec72493..6187523027e 100644 --- a/Build/source/texk/web2c/xetexdir/XeTeXFontMgr_FC.h +++ b/Build/source/texk/web2c/xetexdir/XeTeXFontMgr_FC.h @@ -1,9 +1,9 @@ /****************************************************************************\ Part of the XeTeX typesetting system - copyright (c) 1994-2008 by SIL International - copyright (c) 2009 by Jonathan Kew + Copyright (c) 1994-2008 by SIL International + Copyright (c) 2009 by Jonathan Kew - Written by Jonathan Kew + SIL Author(s): Jonathan Kew Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/Build/source/texk/web2c/xetexdir/XeTeXFontMgr_Mac.h b/Build/source/texk/web2c/xetexdir/XeTeXFontMgr_Mac.h index cd480f46a34..7adbe97a4ee 100644 --- a/Build/source/texk/web2c/xetexdir/XeTeXFontMgr_Mac.h +++ b/Build/source/texk/web2c/xetexdir/XeTeXFontMgr_Mac.h @@ -1,9 +1,9 @@ /****************************************************************************\ Part of the XeTeX typesetting system - copyright (c) 1994-2008 by SIL International - copyright (c) 2009 by Jonathan Kew + Copyright (c) 1994-2008 by SIL International + Copyright (c) 2009 by Jonathan Kew - Written by Jonathan Kew + SIL Author(s): Jonathan Kew Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/Build/source/texk/web2c/xetexdir/XeTeXFontMgr_Mac.mm b/Build/source/texk/web2c/xetexdir/XeTeXFontMgr_Mac.mm index 5b78d75dd92..bcc122adf01 100644 --- a/Build/source/texk/web2c/xetexdir/XeTeXFontMgr_Mac.mm +++ b/Build/source/texk/web2c/xetexdir/XeTeXFontMgr_Mac.mm @@ -1,9 +1,9 @@ /****************************************************************************\ Part of the XeTeX typesetting system - copyright (c) 1994-2008 by SIL International - copyright (c) 2009 by Jonathan Kew + Copyright (c) 1994-2008 by SIL International + Copyright (c) 2009 by Jonathan Kew - Written by Jonathan Kew + SIL Author(s): Jonathan Kew Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/Build/source/texk/web2c/xetexdir/XeTeXGrLayout.cpp b/Build/source/texk/web2c/xetexdir/XeTeXGrLayout.cpp deleted file mode 100644 index 772fa6b0e3a..00000000000 --- a/Build/source/texk/web2c/xetexdir/XeTeXGrLayout.cpp +++ /dev/null @@ -1,175 +0,0 @@ -/****************************************************************************\ - Part of the XeTeX typesetting system - copyright (c) 1994-2008 by SIL International - copyright (c) 2009 by Jonathan Kew - - Written by Jonathan Kew - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE -FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF -CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of the copyright holders -shall not be used in advertising or otherwise to promote the sale, -use or other dealings in this Software without prior written -authorization from the copyright holders. -\****************************************************************************/ - -#include "XeTeX_ext.h" -#include "XeTeXswap.h" - -#include "XeTeXGrLayout.h" - - -/* XeTeXGrFont class */ - -XeTeXGrFont::XeTeXGrFont(const XeTeXFontInst* inFont, const char* name) - : Font() - , fXeTeXFont(inFont) - , fName(NULL) -{ - fName = strdup(name); - gr::Font::SetFlushMode(gr::kflushManual); -} - -XeTeXGrFont::XeTeXGrFont(const XeTeXGrFont& orig) - : Font(orig) - , fXeTeXFont(orig.fXeTeXFont) - , fName(NULL) -{ - fName = strdup(orig.fName); -} - -XeTeXGrFont::~XeTeXGrFont() -{ - delete[] fName; -} - -XeTeXGrFont * -XeTeXGrFont::copyThis() -{ - XeTeXGrFont* rval = new XeTeXGrFont(*this); - return rval; -} - -void -XeTeXGrFont::UniqueCacheInfo(std::wstring & stuFace, bool & fBold, bool & fItalic) -{ - int len = strlen(fName); - wchar_t* wname = new wchar_t[len + 1]; - mbstowcs(wname, fName, len); - stuFace.assign(wname, wcslen(wname)); - delete[] wname; - - fBold = false; - fItalic = false; -} - -const void * -XeTeXGrFont::getTable(gr::fontTableId32 tableID, size_t * pcbSize) -{ - le_uint32 length; - LETag tag = tableID; - const void *rval = fXeTeXFont->getFontTable(tag, &length); - *pcbSize = length; - return rval; -} - -void -XeTeXGrFont::getFontMetrics(float * pAscent, float * pDescent, float * pEmSquare) -{ - if (pAscent) - *pAscent = fXeTeXFont->getExactAscent(); - if (pDescent) - *pDescent = - fXeTeXFont->getExactDescent(); - if (pEmSquare) - *pEmSquare = fXeTeXFont->getXPixelsPerEm(); -} - - -/* XeTeXGrTextSource class */ - -void -XeTeXGrTextSource::setText(const UniChar* iText, size_t iLen) -{ - fTextBuffer = iText; - fTextLength = iLen; -} - -void -XeTeXGrTextSource::setFeatures(int nFeatures, const int* featureIDs, const int* featureValues) -{ - if (fFeatureSettings != NULL) - delete[] fFeatureSettings; - - fNumFeatures = nFeatures; - if (nFeatures == 0) - fFeatureSettings = NULL; - else { - gr::FeatureSetting* newFeatures = new gr::FeatureSetting[nFeatures]; - for (int i = 0; i < nFeatures; ++i) { - newFeatures[i].id = featureIDs[i]; - newFeatures[i].value = featureValues[i]; - } - fFeatureSettings = newFeatures; - } -} - -void -XeTeXGrTextSource::setFeatures(int nFeatures, const gr::FeatureSetting* features) -{ - if (fFeatureSettings != NULL) - delete[] fFeatureSettings; - - fNumFeatures = nFeatures; - if (nFeatures == 0) - fFeatureSettings = NULL; - else { - gr::FeatureSetting* newFeatures = new gr::FeatureSetting[nFeatures]; - for (int i = 0; i < nFeatures; ++i) - newFeatures[i] = features[i]; - fFeatureSettings = newFeatures; - } -} - -void -XeTeXGrTextSource::setLanguage(UInt32 iLanguage) -{ - fLanguage.rgch[0] = (iLanguage >> 24) & 0xff; - fLanguage.rgch[1] = (iLanguage >> 16) & 0xff; - fLanguage.rgch[2] = (iLanguage >> 8) & 0xff; - fLanguage.rgch[3] = iLanguage & 0xff; -} - -size_t -XeTeXGrTextSource::fetch(gr::toffset startChar, size_t n, gr::utf16* buffer) -{ - for (size_t i = 0; i < n; ++i) - buffer[i] = fTextBuffer[i]; - return n; -} - -size_t -XeTeXGrTextSource::getFontFeatures(gr::toffset charIndex, gr::FeatureSetting properties[64]) -{ - for (int i = 0; i < fNumFeatures; ++i) - properties[i] = fFeatureSettings[i]; - return fNumFeatures; -} - -const gr::isocode XeTeXGrTextSource::kUnknownLanguage = { 0, 0, 0, 0 }; diff --git a/Build/source/texk/web2c/xetexdir/XeTeXGrLayout.h b/Build/source/texk/web2c/xetexdir/XeTeXGrLayout.h deleted file mode 100644 index 9d888247ade..00000000000 --- a/Build/source/texk/web2c/xetexdir/XeTeXGrLayout.h +++ /dev/null @@ -1,201 +0,0 @@ -/****************************************************************************\ - Part of the XeTeX typesetting system - copyright (c) 1994-2008 by SIL International - copyright (c) 2009 by Jonathan Kew - - Written by Jonathan Kew - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE -FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF -CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of the copyright holders -shall not be used in advertising or otherwise to promote the sale, -use or other dealings in this Software without prior written -authorization from the copyright holders. -\****************************************************************************/ - -#ifndef __XETEX_GR_LAYOUT__ -#define __XETEX_GR_LAYOUT__ - -#include "XeTeXFontInst.h" - -#include "graphite/GrClient.h" - -#include "graphite/Font.h" -#include "graphite/Segment.h" -#include "graphite/ITextSource.h" - -class XeTeXGrFont - : public gr::Font -{ -public: - XeTeXGrFont(const XeTeXFontInst* inFont, const char* name); - XeTeXGrFont(const XeTeXGrFont& orig); - - virtual ~XeTeXGrFont(); - - /** - * Returns a copy of the recipient. Specifically needed to store the - * Font in a segment. - * @internal - * @return pointer to copy - */ - virtual XeTeXGrFont * copyThis(); - - /** - * Return wether the font is bold. - * @return true when bold - */ - virtual bool bold() { return false; } - - /** - * Return wether the font is italic. - * @return true when italic - */ - virtual bool italic() { return false; } - - /** - * Returns the font ascent. - * Value is the same as that returned by getFontMetrics() - * @return the font ascent in device co-ordinates - */ - virtual float ascent() { return fXeTeXFont->getExactAscent(); } - - /** - * Returns the font descent. - * Value is the same as that returned by getFontMetrics() - * @return the font descent in device co-ordinates - */ - virtual float descent() { return - fXeTeXFont->getExactDescent(); } - - /** - * Returns the total height of the font. - * @return font height in device co-ordinates - */ - virtual float height() { return ascent() + descent(); } - - /** - * Returns the x and y resolution of the device co-ordinate space. - */ - virtual unsigned int getDPIx() { return 72; } /* I think this is irrelevant in XeTeX */ - virtual unsigned int getDPIy() { return 72; } - - /** - * Returns a pointer to the start of a table in the font. - * If the Font class cannot easily determine the length of the table, - * it may set 0 as the length (while returning a non-NULL pointer to - * the table). This means that certain kinds of error checking cannot - * be done by the Graphite engine. - * Throws an exception if there is some other error in reading the - * table, or if the table asked for is not in the font. - * @param tableID the TTF ID of the table. - * @param pcbSize pointer to a size_t to hold the table size. - * @return address of the buffer containing the table or 0 - */ - virtual const void * getTable(gr::fontTableId32 tableID, size_t * pcbSize); - - /** - * Fetches the basic metrics of the font in device co-ordinates - * (normaly pixels). - * @param pAscent pointer to hold font ascent. - * @param pDescent pointer to hold font descent. - * @param pEmSquare pointer to hold font EM square. - */ - virtual void getFontMetrics(float * pAscent, float * pDescent = NULL, float * pEmSquare = NULL); - -protected: - virtual void UniqueCacheInfo(std::wstring & stuFace, bool & fBold, bool & fItalic); - - const XeTeXFontInst* fXeTeXFont; - const char* fName; -}; - -class XeTeXGrTextSource - : public gr::ITextSource -{ -public: - XeTeXGrTextSource(int dirLevel, const UniChar* iText = NULL, size_t iLen = 0) - : fDirLevel(dirLevel) - , fTextBuffer(iText) - , fTextLength(iLen) - , fLanguage(kUnknownLanguage) - , fNumFeatures(0) - , fFeatureSettings(NULL) - { } - - virtual ~XeTeXGrTextSource() - { } - - void setText(const UniChar* iText, size_t iLen); - - void setFeatures(int nFeatures, const int* featureIDs, const int* featureValues); - void setFeatures(int nFeatures, const gr::FeatureSetting* features); - - void setLanguage(gr::isocode iLanguage) - { fLanguage = iLanguage; } - - void setLanguage(UInt32 iLanguage); - - virtual gr::UtfType utfEncodingForm() - { return gr::kutf16; } - - virtual size_t fetch(gr::toffset startChar, size_t n, gr::utf32* buffer) - { throw; } - - virtual size_t fetch(gr::toffset startChar, size_t n, gr::utf8* buffer) - { throw; } - - virtual size_t fetch(gr::toffset startChar, size_t n, gr::utf16* buffer); - - virtual size_t getLength() - { return fTextLength; } - - virtual std::pair propertyRange(gr::toffset charIndex) - { return std::pair(0, fTextLength); } - - virtual bool sameSegment(gr::toffset firstChar, gr::toffset secondChar) - { return true; } - - virtual bool getRightToLeft(gr::toffset charIndex) - { return (fDirLevel & 1) != 0; } - - virtual unsigned int getDirectionDepth(gr::toffset charIndex) - { return fDirLevel; } - - virtual float getVerticalOffset(gr::toffset charIndex) - { return 0.0; } - - virtual gr::isocode getLanguage(gr::toffset charIndex) - { return fLanguage; } - - virtual size_t getFontFeatures(gr::toffset charIndex, gr::FeatureSetting properties[64]); - - virtual bool featureVariations() { return false; }; -protected: - int fDirLevel; - const UInt16* fTextBuffer; - size_t fTextLength; - gr::isocode fLanguage; - size_t fNumFeatures; - const gr::FeatureSetting* fFeatureSettings; - - static const gr::isocode kUnknownLanguage; -}; - -#endif /* __XETEX_GR_LAYOUT__ */ diff --git a/Build/source/texk/web2c/xetexdir/XeTeXLayoutInterface.cpp b/Build/source/texk/web2c/xetexdir/XeTeXLayoutInterface.cpp index eb566b173e4..f01b5b1699e 100644 --- a/Build/source/texk/web2c/xetexdir/XeTeXLayoutInterface.cpp +++ b/Build/source/texk/web2c/xetexdir/XeTeXLayoutInterface.cpp @@ -1,9 +1,10 @@ /****************************************************************************\ Part of the XeTeX typesetting system - copyright (c) 1994-2008 by SIL International - copyright (c) 2009-2012 by Jonathan Kew + Copyright (c) 1994-2008 by SIL International + Copyright (c) 2009-2012 by Jonathan Kew + Copyright (c) 2012 by Khaled Hosny - Written by Jonathan Kew + SIL Author(s): Jonathan Kew Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -30,58 +31,33 @@ use or other dealings in this Software without prior written authorization from the copyright holders. \****************************************************************************/ -#include "unicode/platform.h" // We need this first +#include // We need this first +#include +#include #include "XeTeXLayoutInterface.h" - -#include "XeTeXOTLayoutEngine.h" #include "XeTeXFontInst.h" #ifdef XETEX_MAC #include "XeTeXFontInst_Mac.h" #endif #include "XeTeXFontInst_FT2.h" - #include "XeTeXFontMgr.h" - #include "XeTeXswap.h" -#ifdef XETEX_GRAPHITE -#include "XeTeXGrLayout.h" -#endif - -#include "layout/ICUFeatures.h" -#include "layout/ScriptAndLanguage.h" - -#include "unicode/ubidi.h" -#include "unicode/utext.h" - -#include -/* apparently M_PI isn't defined by under VC++ */ -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif - struct XeTeXLayoutEngine_rec - /* this is used for both ICU and Graphite, because so much of the font stuff is common; - however, it is not possible to call ICU-specific things like layoutChars for a - Graphite-based engine, or Graphite functions for an ICU one! */ { - LayoutEngine* layoutEngine; XeTeXFontInst* font; PlatformFontRef fontRef; - UInt32 scriptTag; - UInt32 languageTag; - UInt32* addedFeatures; - UInt32* removedFeatures; + char* script; + char* language; + hb_feature_t* features; + char** shapers; + int nFeatures; UInt32 rgbValue; float extend; float slant; float embolden; -#ifdef XETEX_GRAPHITE - gr::Segment* grSegment; - XeTeXGrFont* grFont; - XeTeXGrTextSource* grSource; -#endif + hb_buffer_t* hbBuffer; }; /*******************************************************************/ @@ -120,17 +96,17 @@ void terminatefontmanager() XeTeXFont createFont(PlatformFontRef fontRef, Fixed pointSize) { - LEErrorCode status = LE_NO_ERROR; + int status = 0; #ifdef XETEX_MAC - XeTeXFontInst* font = new XeTeXFontInst_Mac((ATSFontRef)fontRef, Fix2X(pointSize), status); + XeTeXFontInst* font = new XeTeXFontInst_Mac((ATSFontRef)fontRef, Fix2D(pointSize), status); #else FcChar8* pathname = 0; FcPatternGetString(fontRef, FC_FILE, 0, &pathname); int index; FcPatternGetInteger(fontRef, FC_INDEX, 0, &index); - XeTeXFontInst* font = new XeTeXFontInst_FT2((const char*)pathname, index, Fix2X(pointSize), status); + XeTeXFontInst* font = new XeTeXFontInst_FT2((const char*)pathname, index, Fix2D(pointSize), status); #endif - if (LE_FAILURE(status)) { + if (status != 0) { delete font; return NULL; } @@ -139,9 +115,9 @@ XeTeXFont createFont(PlatformFontRef fontRef, Fixed pointSize) XeTeXFont createFontFromFile(const char* filename, int index, Fixed pointSize) { - LEErrorCode status = LE_NO_ERROR; - XeTeXFontInst* font = new XeTeXFontInst_FT2(filename, index, Fix2X(pointSize), status); - if (LE_FAILURE(status)) { + int status = 0; + XeTeXFontInst* font = new XeTeXFontInst_FT2(filename, index, Fix2D(pointSize), status); + if (status != 0) { delete font; return NULL; } @@ -163,6 +139,11 @@ char getReqEngine() return XeTeXFontMgr::GetFontManager()->getReqEngine(); } +void setReqEngine(char reqEngine) +{ + XeTeXFontMgr::GetFontManager()->setReqEngine(reqEngine); +} + const char* getFullName(PlatformFontRef fontRef) { return XeTeXFontMgr::GetFontManager()->getFullName(fontRef); @@ -201,323 +182,347 @@ void* getFontTablePtr(XeTeXFont font, UInt32 tableTag) Fixed getSlant(XeTeXFont font) { float italAngle = ((XeTeXFontInst*)font)->getItalicAngle(); - return X2Fix(tan(-italAngle * M_PI / 180.0)); + return D2Fix(tan(-italAngle * M_PI / 180.0)); } -static const ScriptListTable* -getLargerScriptListTable(XeTeXFont font) +static UInt32 +getLargerScriptListTable(XeTeXFont font, hb_tag_t** scriptList, hb_tag_t* tableTag) { - const ScriptListTable* scriptListSub = NULL; - const ScriptListTable* scriptListPos = NULL; - - const GlyphSubstitutionTableHeader* gsubTable = (const GlyphSubstitutionTableHeader*)((XeTeXFontInst*)font)->getFontTable(kGSUB); - UInt32 scriptCountSub = 0; - if (gsubTable != NULL) { - scriptListSub = (const ScriptListTable*)((const char*)gsubTable + SWAP(gsubTable->scriptListOffset)); - scriptCountSub = SWAP(scriptListSub->scriptCount); - } + hb_face_t* face = hb_font_get_face(((XeTeXFontInst*)font)->hbFont); - const GlyphPositioningTableHeader* gposTable = (const GlyphPositioningTableHeader*)((XeTeXFontInst*)font)->getFontTable(kGPOS); - UInt32 scriptCountPos = 0; - if (gposTable != NULL) { - scriptListPos = (const ScriptListTable*)((const char*)gposTable + SWAP(gposTable->scriptListOffset)); - scriptCountPos = SWAP(scriptListPos->scriptCount); - } + hb_tag_t* scriptListSub = NULL; + hb_tag_t* scriptListPos = NULL; + + uint32_t scriptCountSub = hb_ot_layout_table_get_script_tags(face, HB_OT_TAG_GSUB, 0, NULL, NULL); + scriptListSub = (hb_tag_t*) xmalloc(scriptCountSub * sizeof(hb_tag_t*)); + hb_ot_layout_table_get_script_tags(face, HB_OT_TAG_GSUB, 0, &scriptCountSub, scriptListSub); - return scriptCountPos > scriptCountSub ? scriptListPos : scriptListSub; + uint32_t scriptCountPos = hb_ot_layout_table_get_script_tags(face, HB_OT_TAG_GPOS, 0, NULL, NULL); + scriptListPos = (hb_tag_t*) xmalloc(scriptCountPos * sizeof(hb_tag_t*)); + hb_ot_layout_table_get_script_tags(face, HB_OT_TAG_GSUB, 0, &scriptCountPos, scriptListPos); + + if (scriptCountSub > scriptCountPos) { + if (scriptList != NULL) + *scriptList = scriptListSub; + if (tableTag != NULL) + *tableTag = HB_OT_TAG_GSUB; + return scriptCountSub; + } else { + if (scriptList != NULL) + *scriptList = scriptListPos; + if (tableTag != NULL) + *tableTag = HB_OT_TAG_GPOS; + return scriptCountPos; + } } UInt32 countScripts(XeTeXFont font) { - const ScriptListTable* scriptList = getLargerScriptListTable(font); - if (scriptList == NULL) - return 0; - - return SWAP(scriptList->scriptCount); + return getLargerScriptListTable(font, NULL, NULL); } UInt32 getIndScript(XeTeXFont font, UInt32 index) { - const ScriptListTable* scriptList = getLargerScriptListTable(font); + hb_tag_t* scriptList; + + UInt32 scriptCount = getLargerScriptListTable(font, &scriptList, NULL); if (scriptList == NULL) return 0; - if (index < SWAP(scriptList->scriptCount)) - return SWAPT(scriptList->scriptRecordArray[index].tag); + if (index < scriptCount) + return scriptList[index]; return 0; } UInt32 countScriptLanguages(XeTeXFont font, UInt32 script) { - const ScriptListTable* scriptList = getLargerScriptListTable(font); + hb_face_t* face = hb_font_get_face(((XeTeXFontInst*)font)->hbFont); + hb_tag_t* scriptList; + hb_tag_t tableTag; + + UInt32 scriptCount = getLargerScriptListTable(font, &scriptList, &tableTag); if (scriptList == NULL) return 0; - const ScriptTable* scriptTable = scriptList->findScript(script); - if (scriptTable == NULL) - return 0; - - UInt32 langCount = SWAP(scriptTable->langSysCount); - - return langCount; + for (int i = 0; i < scriptCount; i++) { + if (scriptList[i] == script) { + return hb_ot_layout_script_get_language_tags (face, tableTag, i, 0, NULL, NULL); + } + } } UInt32 getIndScriptLanguage(XeTeXFont font, UInt32 script, UInt32 index) { - const ScriptListTable* scriptList = getLargerScriptListTable(font); + hb_face_t* face = hb_font_get_face(((XeTeXFontInst*)font)->hbFont); + hb_tag_t* scriptList; + hb_tag_t tableTag; + + UInt32 scriptCount = getLargerScriptListTable(font, &scriptList, &tableTag); if (scriptList == NULL) return 0; - const ScriptTable* scriptTable = scriptList->findScript(script); - if (scriptTable == NULL) - return 0; + for (int i = 0; i < scriptCount; i++) { + if (scriptList[i] == script) { + uint32_t langCount = hb_ot_layout_script_get_language_tags(face, tableTag, i, 0, NULL, NULL); + hb_tag_t* langList = (hb_tag_t*) xmalloc(langCount * sizeof(hb_tag_t*)); + hb_ot_layout_script_get_language_tags(face, tableTag, i, 0, &langCount, langList); - if (index < SWAP(scriptTable->langSysCount)) - return SWAPT(scriptTable->langSysRecordArray[index].tag); + if (index < langCount) + return langList[index]; - return 0; + return 0; + } + } } UInt32 countFeatures(XeTeXFont font, UInt32 script, UInt32 language) { - UInt32 total = 0; - const GlyphLookupTableHeader* table; + hb_face_t* face = hb_font_get_face(((XeTeXFontInst*)font)->hbFont); + UInt32 total = 0; + for (int i = 0; i < 2; ++i) { - table = (const GlyphLookupTableHeader*)((XeTeXFontInst*)font)->getFontTable(i == 0 ? kGSUB : kGPOS); - if (table != NULL) { - const ScriptListTable* scriptList = (const ScriptListTable*)((const char*)table + SWAP(table->scriptListOffset)); - const ScriptTable* scriptTable = scriptList->findScript(script); - if (scriptTable != NULL) { - const LangSysTable* langTable = scriptTable->findLanguage(language, (language != 0)); - if (langTable != NULL) { - total += SWAP(langTable->featureCount); - if (langTable->reqFeatureIndex != 0xffff) - total += 1; - } + uint32_t scriptIndex, langIndex = 0; + hb_tag_t tableTag = i == 0 ? HB_OT_TAG_GSUB : HB_OT_TAG_GPOS; + if (hb_ot_layout_table_find_script(face, tableTag, script, &scriptIndex)) { + if (hb_ot_layout_script_find_language(face, tableTag, scriptIndex, language, &langIndex) || language == 0) { + total += hb_ot_layout_language_get_feature_tags(face, tableTag, scriptIndex, langIndex, 0, NULL, NULL); } } } - + return total; } UInt32 getIndFeature(XeTeXFont font, UInt32 script, UInt32 language, UInt32 index) { - const GlyphLookupTableHeader* table; - UInt16 featureIndex = 0xffff; + hb_face_t* face = hb_font_get_face(((XeTeXFontInst*)font)->hbFont); + for (int i = 0; i < 2; ++i) { - table = (const GlyphLookupTableHeader*)((XeTeXFontInst*)font)->getFontTable(i == 0 ? kGSUB : kGPOS); - if (table != NULL) { - const ScriptListTable* scriptList = (const ScriptListTable*)((const char*)table + SWAP(table->scriptListOffset)); - const ScriptTable* scriptTable = scriptList->findScript(script); - if (scriptTable != NULL) { - const LangSysTable* langTable = scriptTable->findLanguage(language, (language != 0)); - if (langTable != NULL) { - if (SWAP(langTable->reqFeatureIndex) != 0xffff) - if (index == 0) - featureIndex = SWAP(langTable->reqFeatureIndex); - else - index -= 1; - if (index < SWAP(langTable->featureCount)) - featureIndex = SWAP(langTable->featureIndexArray[index]); - index -= SWAP(langTable->featureCount); - } - } - if (featureIndex != 0xffff) { - LETag featureTag; - const FeatureListTable* featureListTable = (const FeatureListTable*)((const char*)table + SWAP(table->featureListOffset)); - (void)featureListTable->getFeatureTable(featureIndex, &featureTag); - return featureTag; + uint32_t scriptIndex, langIndex = 0; + hb_tag_t tableTag = i == 0 ? HB_OT_TAG_GSUB : HB_OT_TAG_GPOS; + if (hb_ot_layout_table_find_script(face, tableTag, script, &scriptIndex)) { + if (hb_ot_layout_script_find_language(face, tableTag, scriptIndex, language, &langIndex) || language == 0) { + uint32_t featCount = hb_ot_layout_language_get_feature_tags(face, tableTag, scriptIndex, langIndex, 0, NULL, NULL); + hb_tag_t* featList = (hb_tag_t*) xmalloc(featCount * sizeof(hb_tag_t*)); + hb_ot_layout_language_get_feature_tags(face, tableTag, scriptIndex, langIndex, 0, &featCount, featList); + + if (index < featCount) + return featList[index]; + + index -= featCount; } } } - + return 0; } -#ifdef XETEX_GRAPHITE UInt32 countGraphiteFeatures(XeTeXLayoutEngine engine) { - std::pair fi = engine->grFont->getFeatures(); - UInt32 rval = 0; - while (fi.first != fi.second) { - ++rval; - ++fi.first; - } + uint32_t rval = 0; + + hb_face_t* hbFace = hb_font_get_face(engine->font->hbFont); + gr_face* grFace = hb_graphite2_face_get_gr_face(hbFace); + + if (grFace != NULL) + rval = gr_face_n_fref(grFace); + return rval; } UInt32 getGraphiteFeatureCode(XeTeXLayoutEngine engine, UInt32 index) { - std::pair fi = engine->grFont->getFeatures(); - while (index > 0 && fi.first != fi.second) { - --index; - ++fi.first; + uint32_t rval = 0; + + hb_face_t* hbFace = hb_font_get_face(engine->font->hbFont); + gr_face* grFace = hb_graphite2_face_get_gr_face(hbFace); + + if (grFace != NULL) { + const gr_feature_ref* feature = gr_face_fref(grFace, index); + rval = gr_fref_id(feature); } - if (fi.first != fi.second) - return *fi.first; - return 0; + + return rval; } -UInt32 countGraphiteFeatureSettings(XeTeXLayoutEngine engine, UInt32 feature) +UInt32 countGraphiteFeatureSettings(XeTeXLayoutEngine engine, UInt32 featureID) { - std::pair fi = engine->grFont->getFeatures(); - while (fi.first != fi.second && *fi.first != feature) - ++fi.first; - if (fi.first != fi.second) { - std::pair - si = engine->grFont->getFeatureSettings(fi.first); - UInt32 rval = 0; - while (si.first != si.second) { - ++rval; - ++si.first; - } - return rval; + uint32_t rval = 0; + + hb_face_t* hbFace = hb_font_get_face(engine->font->hbFont); + gr_face* grFace = hb_graphite2_face_get_gr_face(hbFace); + + if (grFace != NULL) { + const gr_feature_ref* feature = gr_face_find_fref(grFace, featureID); + rval = gr_fref_n_values(feature); } - return 0; + + return rval; } -UInt32 getGraphiteFeatureSettingCode(XeTeXLayoutEngine engine, UInt32 feature, UInt32 index) +UInt32 getGraphiteFeatureSettingCode(XeTeXLayoutEngine engine, UInt32 featureID, UInt32 index) { - std::pair fi = engine->grFont->getFeatures(); - while (fi.first != fi.second && *fi.first != feature) - ++fi.first; - if (fi.first != fi.second) { - std::pair - si = engine->grFont->getFeatureSettings(fi.first); - while (index > 0 && si.first != si.second) { - --index; - ++si.first; - } - if (si.first != si.second) - return *si.first; + uint32_t rval = 0; + + hb_face_t* hbFace = hb_font_get_face(engine->font->hbFont); + gr_face* grFace = hb_graphite2_face_get_gr_face(hbFace); + + if (grFace != NULL) { + const gr_feature_ref* feature = gr_face_find_fref(grFace, featureID); + rval = gr_fref_value(feature, index); } - return 0; + + return rval; } -UInt32 getGraphiteFeatureDefaultSetting(XeTeXLayoutEngine engine, UInt32 feature) +void getGraphiteFeatureLabel(XeTeXLayoutEngine engine, UInt32 featureID, char* buf) { - std::pair fi = engine->grFont->getFeatures(); - while (fi.first != fi.second && *fi.first != feature) - ++fi.first; - if (fi.first != fi.second) { - gr::FeatureSettingIterator si = engine->grFont->getDefaultFeatureValue(fi.first); - return *si; + buf[0] = '\0'; + + hb_face_t* hbFace = hb_font_get_face(engine->font->hbFont); + gr_face* grFace = hb_graphite2_face_get_gr_face(hbFace); + + if (grFace != NULL) { + const gr_feature_ref* feature = gr_face_find_fref(grFace, featureID); + uint32_t len = 0; + uint16_t langID = 0x409; + + buf = (char*) gr_fref_label(feature, &langID, gr_utf8, &len); + + if (len > 128 + 1) { // 128 is set in XeTeX_ext.c + buf = (char*) realloc(buf, len + 1); + buf = (char*) gr_fref_label(feature, &langID, gr_utf8, &len); + } + + buf[len + 1] = '\0'; } - return 0; } -void getGraphiteFeatureLabel(XeTeXLayoutEngine engine, UInt32 feature, unsigned short* buf) +void getGraphiteFeatureSettingLabel(XeTeXLayoutEngine engine, UInt32 featureID, UInt32 settingID, char* buf) { - buf[0] = 0; - std::pair fi = engine->grFont->getFeatures(); - while (fi.first != fi.second && *fi.first != feature) - ++fi.first; - if (fi.first != fi.second) { - engine->grFont->getFeatureLabel(fi.first, 0x0409, buf); + buf[0] = '\0'; + + hb_face_t* hbFace = hb_font_get_face(engine->font->hbFont); + gr_face* grFace = hb_graphite2_face_get_gr_face(hbFace); + + if (grFace != NULL) { + const gr_feature_ref* feature = gr_face_find_fref(grFace, featureID); + for (int i = 0; i < gr_fref_n_values(feature); i++) { + if (settingID == gr_fref_value(feature, i)) { + uint32_t len = 0; + uint16_t langID = 0x409; + + buf = (char*) gr_fref_value_label(feature, i, &langID, gr_utf8, &len); + + if (len > 128 + 1) { // 128 is set in XeTeX_ext.c + buf = (char*) realloc(buf, len + 1); + buf = (char*) gr_fref_value_label(feature, i, &langID, gr_utf8, &len); + } + + buf[len + 1] = '\0'; + break; + } + } } } -void getGraphiteFeatureSettingLabel(XeTeXLayoutEngine engine, UInt32 feature, UInt32 setting, unsigned short* buf) +bool +findGraphiteFeature(XeTeXLayoutEngine engine, const char* s, const char* e, int* f, int* v) + /* s...e is a "feature[=setting]" string; look for this in the font */ { - buf[0] = 0; - std::pair fi = engine->grFont->getFeatures(); - while (fi.first != fi.second && *fi.first != feature) - ++fi.first; - if (fi.first != fi.second) { - std::pair - si = engine->grFont->getFeatureSettings(fi.first); - while (si.first != si.second && *si.first != setting) - ++si.first; - if (si.first != si.second) { - engine->grFont->getFeatureSettingLabel(si.first, 0x0409, buf); - } - } + *f = 0; + *v = 0; + while (*s == ' ' || *s == '\t') + ++s; + const char* cp = s; + while (cp < e && *cp != '=') + ++cp; + + *f = findGraphiteFeatureNamed(engine, s, cp - s); + if (*f == -1) + return false; + + ++cp; + while (cp < e && (*cp == ' ' || *cp == '\t')) + ++cp; + if (cp >= e) + // no setting was specified, so we just use the first + // XXX the default is not always the first? + return true; + + *v = findGraphiteFeatureSettingNamed(engine, *f, cp, e - cp); + if (*v == -1) + return false; + + return true; } -#endif /* XETEX_GRAPHITE */ long findGraphiteFeatureNamed(XeTeXLayoutEngine engine, const char* name, int namelength) { long rval = -1; -#ifdef XETEX_GRAPHITE - UErrorCode status = (UErrorCode)0; - - std::pair features = engine->grFont->getFeatures(); - while (features.first != features.second) { - gr::utf16 label[128]; - if (engine->grFont->getFeatureLabel(features.first, 0x409, &label[0])) { - UText* ut1 = utext_openUTF8(NULL, name, namelength, &status); - UText* ut2 = utext_openUChars(NULL, (const UChar*)&label[0], -1, &status); - UChar32 ch1 = 0, ch2 = 0; - while (ch1 != U_SENTINEL) { - ch1 = utext_next32(ut1); - ch2 = utext_next32(ut2); - if (ch1 != ch2) - break; - } - ut1 = utext_close(ut1); - ut2 = utext_close(ut2); - if (ch1 == ch2) { - rval = *features.first; + hb_face_t* hbFace = hb_font_get_face(engine->font->hbFont); + gr_face* grFace = hb_graphite2_face_get_gr_face(hbFace); + + if (grFace != NULL) { + for (int i = 0; i < gr_face_n_fref(grFace); i++) { + const gr_feature_ref* feature = gr_face_fref(grFace, i); + uint32_t len = 0; + uint16_t langID = 0x409; + + // the first call is to get the length of the string + gr_fref_label(feature, &langID, gr_utf8, &len); + char* label = (char*) xmalloc(len); + label = (char*) gr_fref_label(feature, &langID, gr_utf8, &len); + + if (strncmp(label, name, namelength) == 0) { + rval = gr_fref_id(feature); + gr_label_destroy(label); break; } + + gr_label_destroy(label); } - ++features.first; } -#endif return rval; } -long findGraphiteFeatureSettingNamed(XeTeXLayoutEngine engine, UInt32 feature, const char* name, int namelength) +long findGraphiteFeatureSettingNamed(XeTeXLayoutEngine engine, UInt32 id, const char* name, int namelength) { long rval = -1; -#ifdef XETEX_GRAPHITE - UErrorCode status = (UErrorCode)0; - - std::pair features = engine->grFont->getFeatures(); - while (features.first != features.second) { - if (*features.first == feature) { - std::pair - settings = engine->grFont->getFeatureSettings(features.first); - while (settings.first != settings.second) { - gr::utf16 label[128]; - if (engine->grFont->getFeatureSettingLabel(settings.first, 0x409, &label[0])) { - UText* ut1 = utext_openUTF8(NULL, name, namelength, &status); - UText* ut2 = utext_openUChars(NULL, (const UChar*)&label[0], -1, &status); - UChar32 ch1 = 0, ch2 = 0; - while (ch1 != U_SENTINEL) { - ch1 = utext_next32(ut1); - ch2 = utext_next32(ut2); - if (ch1 != ch2) - break; - } - ut1 = utext_close(ut1); - ut2 = utext_close(ut2); - if (ch1 == ch2) { - rval = *settings.first; - break; - } - } - ++settings.first; + hb_face_t* hbFace = hb_font_get_face(engine->font->hbFont); + gr_face* grFace = hb_graphite2_face_get_gr_face(hbFace); + + if (grFace != NULL) { + const gr_feature_ref* feature = gr_face_find_fref(grFace, id); + for (int i = 0; i < gr_fref_n_values(feature); i++) { + uint32_t len = 0; + uint16_t langID = 0x409; + + // the first call is to get the length of the string + gr_fref_value_label(feature, i, &langID, gr_utf8, &len); + char* label = (char*) xmalloc(len); + label = (char*) gr_fref_value_label(feature, i, &langID, gr_utf8, &len); + + if (strncmp(label, name, namelength) == 0) { + rval = gr_fref_value(feature, i); + gr_label_destroy(label); + break; } - break; + + gr_label_destroy(label); } - ++features.first; } -#endif return rval; } float getGlyphWidth(XeTeXFont font, UInt32 gid) { - LEPoint adv; - ((XeTeXFontInst*)font)->getGlyphAdvance(gid, adv); - return adv.fX; + return ((XeTeXFontInst*)font)->getGlyphWidth(gid); } UInt32 @@ -546,131 +551,134 @@ float getEmboldenFactor(XeTeXLayoutEngine engine) return engine->embolden; } -XeTeXLayoutEngine createLayoutEngine(PlatformFontRef fontRef, XeTeXFont font, UInt32 scriptTag, UInt32 languageTag, - UInt32* addFeatures, SInt32* addParams, UInt32* removeFeatures, UInt32 rgbValue, +XeTeXLayoutEngine createLayoutEngine(PlatformFontRef fontRef, XeTeXFont font, char* script, char* language, + hb_feature_t* features, int nFeatures, char **shapers, UInt32 rgbValue, float extend, float slant, float embolden) { - LEErrorCode status = LE_NO_ERROR; XeTeXLayoutEngine result = new XeTeXLayoutEngine_rec; result->fontRef = fontRef; result->font = (XeTeXFontInst*)font; - result->scriptTag = scriptTag; - result->languageTag = languageTag; - result->addedFeatures = addFeatures; - result->removedFeatures = removeFeatures; + result->script = script; + result->language = language; + result->features = features; + result->shapers = shapers; + result->nFeatures = nFeatures; result->rgbValue = rgbValue; result->extend = extend; result->slant = slant; result->embolden = embolden; - -#ifdef XETEX_GRAPHITE - result->grSegment = NULL; - result->grSource = NULL; - result->grFont = NULL; -#endif - - result->layoutEngine = XeTeXOTLayoutEngine::LayoutEngineFactory((XeTeXFontInst*)font, scriptTag, languageTag, - (LETag*)addFeatures, (le_int32*)addParams, (LETag*)removeFeatures, status); - if (LE_FAILURE(status) || result->layoutEngine == NULL) { - delete result; - return NULL; - } + result->hbBuffer = hb_buffer_create(); return result; } void deleteLayoutEngine(XeTeXLayoutEngine engine) { - delete engine->layoutEngine; + hb_buffer_destroy(engine->hbBuffer); delete engine->font; -#ifdef XETEX_GRAPHITE - delete engine->grSegment; - delete engine->grSource; - delete engine->grFont; -#endif } -SInt32 layoutChars(XeTeXLayoutEngine engine, UInt16 chars[], SInt32 offset, SInt32 count, SInt32 max, - char rightToLeft, float x, float y, SInt32* status) +int layoutChars(XeTeXLayoutEngine engine, UInt16 chars[], SInt32 offset, SInt32 count, SInt32 max, + bool rightToLeft) { - LEErrorCode success = (LEErrorCode)*status; - le_int32 glyphCount = engine->layoutEngine->layoutChars((const LEUnicode*)chars, - offset, count, max, rightToLeft, x, y, success); - *status = success; - return glyphCount; -} + hb_script_t script = HB_SCRIPT_INVALID; + hb_language_t language = HB_LANGUAGE_INVALID; + hb_direction_t direction = HB_DIRECTION_LTR; -void getGlyphs(XeTeXLayoutEngine engine, UInt32 glyphs[], SInt32* status) -{ - LEErrorCode success = (LEErrorCode)*status; - engine->layoutEngine->getGlyphs((LEGlyphID*)glyphs, success); - *status = success; -} + if (engine->font->getLayoutDirVertical()) + direction = HB_DIRECTION_TTB; + else if (rightToLeft) + direction = HB_DIRECTION_RTL; -void getGlyphPositions(XeTeXLayoutEngine engine, float positions[], SInt32* status) -{ - LEErrorCode success = (LEErrorCode)*status; - engine->layoutEngine->getGlyphPositions(positions, success); + if (engine->script != NULL) + script = hb_script_from_string(engine->script, -1); - if (engine->extend != 1.0 || engine->slant != 0.0) - for (int i = 0; i <= engine->layoutEngine->getGlyphCount(); ++i) - positions[2*i] = positions[2*i] * engine->extend - positions[2*i+1] * engine->slant; + if (engine->language != NULL) + language = hb_language_from_string(engine->language, -1); - *status = success; -} + hb_buffer_reset(engine->hbBuffer); + hb_buffer_add_utf16(engine->hbBuffer, chars, max, offset, count); + hb_buffer_set_direction(engine->hbBuffer, direction); + hb_buffer_set_script(engine->hbBuffer, script); + hb_buffer_set_language(engine->hbBuffer, language); -void getGlyphPosition(XeTeXLayoutEngine engine, SInt32 index, float* x, float* y, SInt32* status) -{ - LEErrorCode success = (LEErrorCode)*status; - engine->layoutEngine->getGlyphPosition(index, *x, *y, success); + hb_shape_full(engine->font->hbFont, engine->hbBuffer, engine->features, engine->nFeatures, engine->shapers); + int glyphCount = hb_buffer_get_length(engine->hbBuffer); - if (engine->extend != 1.0 || engine->slant != 0.0) - *x = *x * engine->extend - *y * engine->slant; +#ifdef DEBUG + char buf[1024]; + unsigned int consumed; + hb_buffer_serialize_flags_t flags = HB_BUFFER_SERIALIZE_FLAGS_DEFAULT; - *status = success; -} + hb_buffer_serialize_glyphs (engine->hbBuffer, 0, glyphCount, buf, sizeof(buf), &consumed, engine->font->hbFont, HB_BUFFER_SERIALIZE_FORMAT_JSON, flags); + if (consumed) + printf ("buffer glyphs: %s\n", buf); +#endif -UInt32 getScriptTag(XeTeXLayoutEngine engine) -{ - return engine->scriptTag; + return glyphCount; } -UInt32 getLanguageTag(XeTeXLayoutEngine engine) +void getGlyphs(XeTeXLayoutEngine engine, UInt32 glyphs[]) { - return engine->languageTag; -} + int glyphCount = hb_buffer_get_length(engine->hbBuffer); + hb_glyph_info_t *hbGlyphs = hb_buffer_get_glyph_infos(engine->hbBuffer, NULL); -float getPointSize(XeTeXLayoutEngine engine) -{ - return engine->font->getXPixelsPerEm(); + for (int i = 0; i < glyphCount; i++) + glyphs[i] = hbGlyphs[i].codepoint; } -void getAscentAndDescent(XeTeXLayoutEngine engine, float* ascent, float* descent) +void getGlyphPositions(XeTeXLayoutEngine engine, float positions[]) { - *ascent = engine->font->getExactAscent(); - *descent = engine->font->getExactDescent(); + int glyphCount = hb_buffer_get_length(engine->hbBuffer); + hb_glyph_position_t *hbPositions = hb_buffer_get_glyph_positions(engine->hbBuffer, NULL); + + int i = 0; + float x = 0, y = 0; + + if (engine->font->getLayoutDirVertical()) { + x -= hbPositions[0].y_offset / 64.0; // hack to compensate offset of 1st glyph + for (i = 0; i < glyphCount; i++) { + positions[2*i] = -(x + hbPositions[i].y_offset / 64.0); /* negative is forwards */ + positions[2*i+1] = (y + hbPositions[i].x_offset / 64.0); + x += hbPositions[i].y_advance / 64.0; + y += hbPositions[i].x_advance / 64.0; + } + positions[2*i] = -x; + positions[2*i+1] = y; + } else { + for (i = 0; i < glyphCount; i++) { + positions[2*i] = x + hbPositions[i].x_offset / 64.0; + positions[2*i+1] = -(y + hbPositions[i].y_offset / 64.0); /* negative is upwards */ + x += hbPositions[i].x_advance / 64.0; + y += hbPositions[i].y_advance / 64.0; + } + positions[2*i] = x; + positions[2*i+1] = -y; + } + + if (engine->extend != 1.0 || engine->slant != 0.0) + for (int i = 0; i <= glyphCount; ++i) + positions[2*i] = positions[2*i] * engine->extend - positions[2*i+1] * engine->slant; } -UInt32* getAddedFeatures(XeTeXLayoutEngine engine) +float getPointSize(XeTeXLayoutEngine engine) { - return engine->addedFeatures; + return engine->font->getPointSize(); } -UInt32* getRemovedFeatures(XeTeXLayoutEngine engine) +void getAscentAndDescent(XeTeXLayoutEngine engine, float* ascent, float* descent) { - return engine->removedFeatures; + *ascent = engine->font->getAscent(); + *descent = engine->font->getDescent(); } int getDefaultDirection(XeTeXLayoutEngine engine) { - switch (engine->scriptTag) { - case kArabic: - case kSyriac: - case kThaana: - case kHebrew: - return UBIDI_DEFAULT_RTL; - } - return UBIDI_DEFAULT_LTR; + hb_script_t script = hb_buffer_get_script(engine->hbBuffer); + if (hb_script_get_horizontal_direction (script) == HB_DIRECTION_RTL) + return UBIDI_DEFAULT_RTL; + else + return UBIDI_DEFAULT_LTR; } UInt32 getRgbValue(XeTeXLayoutEngine engine) @@ -855,282 +863,101 @@ mapGlyphToIndex(XeTeXLayoutEngine engine, const char* glyphName) return engine->font->mapGlyphToIndex(glyphName); } -#ifdef XETEX_MAC -/* this is here rather than XeTeX_mac.c because I want it in a .cpp file */ -int -GetFontCharRange_AAT(ATSUStyle style, int reqFirst) -{ - ATSUFontID fontID; - ATSUGetAttribute(style, kATSUFontTag, sizeof(ATSUFontID), &fontID, 0); - - ATSFontRef fontRef = FMGetATSFontRefFromFont(fontID); - - ByteCount length; - OSStatus status = ATSFontGetTable(fontRef, kCmap, 0, 0, 0, &length); - if (status != noErr) - return 0; - - void* table = LE_NEW_ARRAY(char, length); - status = ATSFontGetTable(fontRef, kCmap, 0, length, table, &length); - if (status != noErr) { - free(table); - return 0; - } - - CMAPMapper* mapper = CMAPMapper::createUnicodeMapper((const CMAPTable *)table); - - int ch = 0; - if (mapper) { - if (reqFirst) - while (mapper->unicodeToGlyph(ch) == 0 && ch < 0x10ffff) - ++ch; - else { - ch = 0x10ffff; - while (mapper->unicodeToGlyph(ch) == 0 && ch > 0) - --ch; - } - delete mapper; - } - else { - LE_DELETE_ARRAY(table); - } - - return ch; - - if (reqFirst) { - int ch = 0; - while (MapCharToGlyph_AAT(style, ch) == 0 && ch < 0x10ffff) - ++ch; - return ch; - } - else { - int ch = 0x10ffff; - while (MapCharToGlyph_AAT(style, ch) == 0 && ch > 0) - --ch; - return ch; - } -} -#endif - -#ifdef XETEX_GRAPHITE +static gr_segment* grSegment = NULL; +static const gr_slot* grPrevSlot = NULL; -/* Graphite interface */ - -gr::LayoutEnvironment layoutEnv; - -XeTeXLayoutEngine createGraphiteEngine(PlatformFontRef fontRef, XeTeXFont font, - const char* name, - UInt32 rgbValue, int rtl, UInt32 languageTag, - float extend, float slant, float embolden, - int nFeatures, const int* featureIDs, const int* featureValues) +bool +initGraphiteBreaking(XeTeXLayoutEngine engine, const UniChar* txtPtr, int txtLen) { - // check if the font supports graphite, and return NULL if not - const UInt32 kttiSilf = 0x53696C66; // from GrConstants.h - if (getFontTablePtr(font, kttiSilf) == NULL) - return NULL; - - XeTeXLayoutEngine result = new XeTeXLayoutEngine_rec; - result->fontRef = fontRef; - result->font = (XeTeXFontInst*)font; - result->scriptTag = 0; - result->languageTag = languageTag; - result->addedFeatures = NULL; - result->removedFeatures = NULL; - result->rgbValue = rgbValue; - result->extend = extend; - result->slant = slant; - result->embolden = embolden; - result->layoutEngine = NULL; + hb_face_t* hbFace = hb_font_get_face(engine->font->hbFont); + gr_face* grFace = hb_graphite2_face_get_gr_face(hbFace); + gr_font* grFont = hb_graphite2_font_get_gr_font(engine->font->hbFont); + if (grFace != NULL && grFont != NULL) { + if (grSegment != NULL) { + gr_seg_destroy(grSegment); + grSegment = NULL; + grPrevSlot = NULL; + } - result->grFont = new XeTeXGrFont(result->font, name); + hb_tag_t script = HB_TAG_NONE, lang = HB_TAG_NONE; - result->grSource = new XeTeXGrTextSource(rtl); - result->grSource->setFeatures(nFeatures, featureIDs, featureValues); - if (languageTag != 0) - result->grSource->setLanguage(languageTag); + if (engine->script != NULL) + script = hb_tag_from_string(engine->script, -1); - result->grSegment = NULL; - - layoutEnv.setDumbFallback(true); + if (engine->language != NULL) + lang = hb_tag_from_string(engine->language, -1); - return result; -} + gr_feature_val *grFeatures = gr_face_featureval_for_lang (grFace, lang); -int -makeGraphiteSegment(XeTeXLayoutEngine engine, const UniChar* txtPtr, int txtLen) -{ - if (engine->grSegment) { - delete engine->grSegment; - engine->grSegment = NULL; - } - - engine->grSource->setText(txtPtr, txtLen); - try { - engine->grSegment = new gr::RangeSegment(engine->grFont, engine->grSource, &layoutEnv); - } - catch (gr::FontException f) { - fprintf(stderr, "*** makeGraphiteSegment: font error %d, returning 0\n", (int)f.errorCode); - return 0; - } - catch (...) { - fprintf(stderr, "*** makeGraphiteSegment: segment creation failed, returning 0\n"); - return 0; - } + int nFeatures = engine->nFeatures; + hb_feature_t *features = engine->features; + while (nFeatures--) { + const gr_feature_ref *fref = gr_face_find_fref (grFace, features->tag); + if (fref) + gr_fref_set_feature_value (fref, features->value, grFeatures); + features++; + } - return engine->grSegment->glyphs().second - engine->grSegment->glyphs().first; -} + grSegment = gr_make_seg(grFont, grFace, script, grFeatures, gr_utf16, txtPtr, txtLen, 0); + grPrevSlot = gr_seg_first_slot(grSegment); -void -getGraphiteGlyphInfo(XeTeXLayoutEngine engine, int index, UInt16* glyphID, float* x, float* y) -{ - if (engine->grSegment == NULL) { - *glyphID = 0; - *x = *y = 0.0; - return; + return true; } - gr::GlyphIterator i = engine->grSegment->glyphs().first + index; - *glyphID = i->glyphID(); - if (engine->extend != 1.0 || engine->slant != 0.0) - *x = i->origin() * engine->extend + i->yOffset() * engine->slant; - else - *x = i->origin(); - *y = - i->yOffset(); -} -float -graphiteSegmentWidth(XeTeXLayoutEngine engine) -{ - if (engine->grSegment == NULL) - return 0.0; - //return engine->grSegment->advanceWidth(); // can't use this because it ignores trailing WS - try { - return engine->extend * engine->grSegment->getRangeWidth(0, engine->grSource->getLength(), false, false, false); - } - catch (gr::FontException f) { - fprintf(stderr, "*** graphiteSegmentWidth: font error %d, returning 0.0\n", (int)f.errorCode); - return 0.0; - } - catch (...) { - fprintf(stderr, "*** graphiteSegmentWidth: getRangeWidth failed, returning 0.0\n"); - return 0.0; - } + return false; } -/* line-breaking uses its own private textsource and segment, not the engine's ones */ -static XeTeXGrTextSource* lbSource = NULL; -static gr::Segment* lbSegment = NULL; -static XeTeXLayoutEngine lbEngine = NULL; - -#endif /* XETEX_GRAPHITE */ - -void -initGraphiteBreaking(XeTeXLayoutEngine engine, const UniChar* txtPtr, int txtLen) +int +findNextGraphiteBreak(void) { -#ifdef XETEX_GRAPHITE - if (lbSource == NULL) - lbSource = new XeTeXGrTextSource(0); + if (grSegment == NULL) + return -1; - if (lbSegment != NULL) { - delete lbSegment; - lbSegment = NULL; - } + // XXX: gr_cinfo_base() returns "code unit" index not char index, so this + // is broken outside BMP + if (grPrevSlot && grPrevSlot != gr_seg_last_slot(grSegment)) { + const gr_slot* s; + const gr_char_info* ci = NULL; + for (s = gr_slot_next_in_segment(grPrevSlot); s != NULL; s = gr_slot_next_in_segment(s)) { + int bw; + + ci = gr_seg_cinfo(grSegment, gr_slot_index(s)); + bw = gr_cinfo_break_weight(ci); + if (bw < gr_breakNone && bw >= gr_breakBeforeWord) { + grPrevSlot = s; + return gr_cinfo_base(ci); + } - lbSource->setText(txtPtr, txtLen); - - if (lbEngine != engine) { - gr::FeatureSetting features[64]; - size_t nFeatures = engine->grSource->getFontFeatures(0, features); - lbSource->setFeatures(nFeatures, &features[0]); - lbEngine = engine; - } - - try { - lbSegment = new gr::RangeSegment(engine->grFont, lbSource, &layoutEnv); - } - catch (gr::FontException f) { - fprintf(stderr, "*** initGraphiteBreaking: font error %d\n", (int)f.errorCode); - } - catch (...) { - fprintf(stderr, "*** initGraphiteBreaking: segment creation failed\n"); - } -#endif -} + if (bw > gr_breakNone && bw <= gr_breakWord) { + grPrevSlot = gr_slot_next_in_segment(s); + return gr_cinfo_base(ci) + 1; + } + } -int -findNextGraphiteBreak(int iOffset, int iBrkVal) -{ -#ifdef XETEX_GRAPHITE - if (lbSegment == NULL) + grPrevSlot = gr_seg_last_slot(grSegment); + ci = gr_seg_cinfo(grSegment, gr_slot_after(grPrevSlot)); + return gr_cinfo_base(ci) + 1; + } else { return -1; - if (iOffset < lbSource->getLength()) { - while (++iOffset < lbSource->getLength()) { - const std::pair gsiPair = lbSegment->charToGlyphs(iOffset); - const gr::GlyphSetIterator& gsi = gsiPair.first; - if (gsi == gsiPair.second) - continue; - if (gsi->breakweight() < gr::klbNoBreak && gsi->breakweight() >= -(gr::LineBrk)iBrkVal) - return iOffset; - if (gsi->breakweight() > gr::klbNoBreak && gsi->breakweight() <= (gr::LineBrk)iBrkVal) - return iOffset + 1; - } - return lbSource->getLength(); } - else -#endif - return -1; } int usingGraphite(XeTeXLayoutEngine engine) { -#ifdef XETEX_GRAPHITE - return engine->grFont != NULL; -#else return 0; -#endif } int usingOpenType(XeTeXLayoutEngine engine) { - return engine->layoutEngine != NULL; + return engine->hbBuffer != NULL; } -#define kMATHTableTag 0x4D415448 /* 'MATH' */ - int isOpenTypeMathFont(XeTeXLayoutEngine engine) { - if (engine->layoutEngine != NULL) { - if (engine->font->getFontTable(kMATHTableTag) != NULL) + if (usingOpenType(engine)) { + if (engine->font->getFontTable(kMATH) != NULL) return 1; } return 0; } -int -findGraphiteFeature(XeTeXLayoutEngine engine, const char* s, const char* e, int* f, int* v) - /* s...e is a "feature=setting" string; look for this in the font */ -{ - while (*s == ' ' || *s == '\t') - ++s; - const char* cp = s; - while (cp < e && *cp != '=') - ++cp; - if (cp == e) - return 0; - - *f = findGraphiteFeatureNamed(engine, s, cp - s); - if (*f == -1) - return 0; - - ++cp; - while (cp < e && (*cp == ' ' || *cp == '\t')) - ++cp; - if (cp == e) - return 0; - - *v = findGraphiteFeatureSettingNamed(engine, *f, cp, e - cp); - if (*v == -1) - return 0; - - return 1; -} - diff --git a/Build/source/texk/web2c/xetexdir/XeTeXLayoutInterface.h b/Build/source/texk/web2c/xetexdir/XeTeXLayoutInterface.h index 79fd9b4477f..119bccbadec 100644 --- a/Build/source/texk/web2c/xetexdir/XeTeXLayoutInterface.h +++ b/Build/source/texk/web2c/xetexdir/XeTeXLayoutInterface.h @@ -1,9 +1,10 @@ /****************************************************************************\ Part of the XeTeX typesetting system - copyright (c) 1994-2008 by SIL International - copyright (c) 2009 by Jonathan Kew + Copyright (c) 1994-2008 by SIL International + Copyright (c) 2009 by Jonathan Kew + Copyright (c) 2012 by Khaled Hosny - Written by Jonathan Kew + SIL Author(s): Jonathan Kew Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -48,6 +49,15 @@ typedef struct XeTeXLayoutEngine_rec* XeTeXLayoutEngine; #include "XeTeX_ext.h" #include "XeTeXFontMgr.h" +#include +#include +#include +#include +#include + +#include +#include +#include #ifdef __cplusplus extern "C" { @@ -73,6 +83,7 @@ void setFontLayoutDir(XeTeXFont font, int vertical); PlatformFontRef findFontByName(const char* name, char* var, double size); char getReqEngine(); +void setReqEngine(char reqEngine); const char* getFullName(PlatformFontRef fontRef); const char* getFontFilename(XeTeXLayoutEngine engine); @@ -95,8 +106,8 @@ UInt32 getIndFeature(XeTeXFont font, UInt32 script, UInt32 language, UInt32 inde float getGlyphWidth(XeTeXFont font, UInt32 gid); UInt32 countGlyphs(XeTeXFont font); -XeTeXLayoutEngine createLayoutEngine(PlatformFontRef fontRef, XeTeXFont font, UInt32 scriptTag, UInt32 languageTag, - UInt32* addFeatures, SInt32* addParams, UInt32* removeFeatures, UInt32 rgbValue, +XeTeXLayoutEngine createLayoutEngine(PlatformFontRef fontRef, XeTeXFont font, char* script, char* language, + hb_feature_t* features, int nFeatures, char **shapers, UInt32 rgbValue, float extend, float slant, float embolden); void deleteLayoutEngine(XeTeXLayoutEngine engine); @@ -108,27 +119,17 @@ float getExtendFactor(XeTeXLayoutEngine engine); float getSlantFactor(XeTeXLayoutEngine engine); float getEmboldenFactor(XeTeXLayoutEngine engine); -SInt32 layoutChars(XeTeXLayoutEngine engine, UInt16* chars, SInt32 offset, SInt32 count, SInt32 max, - char rightToLeft, float x, float y, SInt32* status); - -void getGlyphs(XeTeXLayoutEngine engine, UInt32* glyphs, SInt32* status); - -void getGlyphPositions(XeTeXLayoutEngine engine, float* positions, SInt32* status); +int layoutChars(XeTeXLayoutEngine engine, UInt16* chars, SInt32 offset, SInt32 count, SInt32 max, + bool rightToLeft); -void getGlyphPosition(XeTeXLayoutEngine engine, SInt32 index, float* x, float* y, SInt32* status); +void getGlyphs(XeTeXLayoutEngine engine, UInt32* glyphs); -UInt32 getScriptTag(XeTeXLayoutEngine engine); - -UInt32 getLanguageTag(XeTeXLayoutEngine engine); +void getGlyphPositions(XeTeXLayoutEngine engine, float* positions); float getPointSize(XeTeXLayoutEngine engine); void getAscentAndDescent(XeTeXLayoutEngine engine, float* ascent, float* descent); -UInt32* getAddedFeatures(XeTeXLayoutEngine engine); - -UInt32* getRemovedFeatures(XeTeXLayoutEngine engine); - int getDefaultDirection(XeTeXLayoutEngine engine); UInt32 getRgbValue(XeTeXLayoutEngine engine); @@ -154,30 +155,21 @@ const char* getGlyphName(XeTeXFont font, UInt16 gid, int* len); int getFontCharRange(XeTeXLayoutEngine engine, int reqFirst); /* graphite interface functions... */ -XeTeXLayoutEngine createGraphiteEngine(PlatformFontRef fontRef, XeTeXFont font, - const char* name, - UInt32 rgbValue, int rtl, UInt32 languageTag, - float extend, float slant, float embolden, - int nFeatures, const int* featureIDs, const int* featureValues); -int makeGraphiteSegment(XeTeXLayoutEngine engine, const UniChar* txtPtr, int txtLen); -void getGraphiteGlyphInfo(XeTeXLayoutEngine engine, int index, UInt16* glyphID, float* x, float* y); -float graphiteSegmentWidth(XeTeXLayoutEngine engine); -void initGraphiteBreaking(XeTeXLayoutEngine engine, const UniChar* txtPtr, int txtLen); -int findNextGraphiteBreak(int iOffset, int iBrkVal); +bool initGraphiteBreaking(XeTeXLayoutEngine engine, const UniChar* txtPtr, int txtLen); +int findNextGraphiteBreak(void); int usingOpenType(XeTeXLayoutEngine engine); int usingGraphite(XeTeXLayoutEngine engine); int isOpenTypeMathFont(XeTeXLayoutEngine engine); -int findGraphiteFeature(XeTeXLayoutEngine engine, const char* s, const char* e, int* f, int* v); +bool findGraphiteFeature(XeTeXLayoutEngine engine, const char* s, const char* e, int* f, int* v); UInt32 countGraphiteFeatures(XeTeXLayoutEngine engine); UInt32 getGraphiteFeatureCode(XeTeXLayoutEngine engine, UInt32 index); UInt32 countGraphiteFeatureSettings(XeTeXLayoutEngine engine, UInt32 feature); UInt32 getGraphiteFeatureSettingCode(XeTeXLayoutEngine engine, UInt32 feature, UInt32 index); -UInt32 getGraphiteFeatureDefaultSetting(XeTeXLayoutEngine engine, UInt32 feature); -void getGraphiteFeatureLabel(XeTeXLayoutEngine engine, UInt32 feature, unsigned short* buf); -void getGraphiteFeatureSettingLabel(XeTeXLayoutEngine engine, UInt32 feature, UInt32 setting, unsigned short* buf); +void getGraphiteFeatureLabel(XeTeXLayoutEngine engine, UInt32 feature, char* buf); +void getGraphiteFeatureSettingLabel(XeTeXLayoutEngine engine, UInt32 feature, UInt32 setting, char* buf); long findGraphiteFeatureNamed(XeTeXLayoutEngine engine, const char* name, int namelength); long findGraphiteFeatureSettingNamed(XeTeXLayoutEngine engine, UInt32 feature, const char* name, int namelength); diff --git a/Build/source/texk/web2c/xetexdir/XeTeXOTLayoutEngine.cpp b/Build/source/texk/web2c/xetexdir/XeTeXOTLayoutEngine.cpp deleted file mode 100644 index 3194bda18ce..00000000000 --- a/Build/source/texk/web2c/xetexdir/XeTeXOTLayoutEngine.cpp +++ /dev/null @@ -1,378 +0,0 @@ -/****************************************************************************\ - Part of the XeTeX typesetting system - copyright (c) 1994-2008 by SIL International - copyright (c) 2009, 2011 by Jonathan Kew - - Written by Jonathan Kew - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE -FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF -CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of the copyright holders -shall not be used in advertising or otherwise to promote the sale, -use or other dealings in this Software without prior written -authorization from the copyright holders. -\****************************************************************************/ - -#include "XeTeXOTLayoutEngine.h" - -/****************************************************************************\ -class XeTeXHanLayoutEngine - moved from XeTeXOTLayoutEngine.h to here in order not to include it into - XeTeXLayoutInterface.cpp. -\****************************************************************************/ -class XeTeXHanLayoutEngine : public XeTeXOTLayoutEngine -{ -public: - XeTeXHanLayoutEngine(const XeTeXFontInst *fontInstance, LETag scriptTag, LETag languageTag, - const GlyphSubstitutionTableHeader *gsubTable, - const GlyphPositioningTableHeader* gposTable, - const LETag* addFeatures, const le_int32* addParams, - const LETag* removeFeatures, LEErrorCode &success); - - virtual ~XeTeXHanLayoutEngine(); - - virtual UClassID getDynamicClassID() const; - static UClassID getStaticClassID(); -}; - -#include "layout/ArabicLayoutEngine.h" -#include "layout/IndicLayoutEngine.h" -#include "layout/TibetanLayoutEngine.h" -#include "layout/ThaiLayoutEngine.h" -#include "layout/KhmerLayoutEngine.h" - -#include "layout/LEScripts.h" -#include "layout/LELanguages.h" - -const LETag emptyTag = 0x00000000; - -static le_int32 getScriptCode(LETag scriptTag) -{ - for (le_int32 i = 0; i < scriptCodeCount; ++i) - if (OpenTypeLayoutEngine::getScriptTag(i) == scriptTag) - return i; - return -1; -} - -static le_int32 getLanguageCode(LETag languageTag) -{ - for (le_int32 i = 0; i < languageCodeCount; ++i) - if (OpenTypeLayoutEngine::getLangSysTag(i) == languageTag) - return i; - return -1; -} - -/* - * XeTeXOTLayoutEngine - */ - -UOBJECT_DEFINE_RTTI_IMPLEMENTATION(XeTeXOTLayoutEngine) - -LayoutEngine* XeTeXOTLayoutEngine::LayoutEngineFactory - (const XeTeXFontInst* fontInstance, - LETag scriptTag, LETag languageTag, - const LETag* addFeatures, const le_int32* addParams, - const LETag* removeFeatures, - LEErrorCode &success) -{ - static le_uint32 gsubTableTag = LE_GSUB_TABLE_TAG; - static le_uint32 gposTableTag = LE_GPOS_TABLE_TAG; - - if (LE_FAILURE(success)) - return NULL; - - const GlyphSubstitutionTableHeader* gsubTable = (const GlyphSubstitutionTableHeader*)fontInstance->getFontTable(gsubTableTag); - const GlyphPositioningTableHeader* gposTable = (const GlyphPositioningTableHeader*)fontInstance->getFontTable(gposTableTag); - LayoutEngine *result = NULL; - - le_uint32 scriptCode = getScriptCode(scriptTag); - le_uint32 languageCode = getLanguageCode(languageTag); - - le_int32 typoFlags = 3; - - if ((gsubTable != NULL && gsubTable->coversScript(scriptTag)) - || (gposTable != NULL && gposTable->coversScript(scriptTag))) { - switch (scriptCode) { - case bengScriptCode: - case devaScriptCode: - case gujrScriptCode: - case kndaScriptCode: - case mlymScriptCode: - case oryaScriptCode: - case guruScriptCode: - case tamlScriptCode: - case teluScriptCode: - case sinhScriptCode: -// result = new XeTeXIndicLayoutEngine(fontInstance, scriptTag, languageTag, gsubTable, addFeatures, removeFeatures); - result = new IndicOpenTypeLayoutEngine(fontInstance, scriptCode, languageCode, typoFlags, FALSE, gsubTable, success); - break; - - case arabScriptCode: - case syrcScriptCode: - case mongScriptCode: -// result = new XeTeXArabicLayoutEngine(fontInstance, scriptTag, languageTag, gsubTable, addFeatures, removeFeatures); - result = new ArabicOpenTypeLayoutEngine(fontInstance, scriptCode, languageCode, typoFlags, gsubTable, success); - break; - - case bopoScriptCode: - case haniScriptCode: - case hangScriptCode: - case hiraScriptCode: - case kanaScriptCode: - case hrktScriptCode: - result = new XeTeXHanLayoutEngine(fontInstance, scriptTag, languageTag, gsubTable, gposTable, addFeatures, addParams, removeFeatures, success); - break; - - case tibtScriptCode: - result = new TibetanOpenTypeLayoutEngine(fontInstance, scriptCode, languageCode, typoFlags, gsubTable, success); - break; - - case khmrScriptCode: - result = new KhmerOpenTypeLayoutEngine(fontInstance, scriptCode, languageCode, typoFlags, gsubTable, success); - break; - - default: - result = new XeTeXOTLayoutEngine(fontInstance, scriptTag, languageTag, gsubTable, gposTable, addFeatures, addParams, removeFeatures, success); - break; - } - } - else { - switch (scriptCode) { - case bengScriptCode: - case devaScriptCode: - case gujrScriptCode: - case kndaScriptCode: - case mlymScriptCode: - case oryaScriptCode: - case guruScriptCode: - case tamlScriptCode: - case teluScriptCode: - case sinhScriptCode: - result = new IndicOpenTypeLayoutEngine(fontInstance, scriptCode, languageCode, typoFlags, success); - break; - - case arabScriptCode: -// case hebrScriptCode: - result = new UnicodeArabicOpenTypeLayoutEngine(fontInstance, scriptCode, languageCode, typoFlags, success); - break; - - case thaiScriptCode: - result = new ThaiLayoutEngine(fontInstance, scriptCode, languageCode, typoFlags, success); - break; - - default: - result = new OpenTypeLayoutEngine(fontInstance, scriptCode, languageCode, typoFlags, success); - break; - } - } - - if (LE_FAILURE(success)) - return NULL; - - return result; -} - -XeTeXOTLayoutEngine::XeTeXOTLayoutEngine( - const LEFontInstance* fontInstance, LETag scriptTag, LETag languageTag, - const GlyphSubstitutionTableHeader* gsubTable, const GlyphPositioningTableHeader* gposTable, - const LETag* addFeatures, const le_int32* addParams, const LETag* removeFeatures, LEErrorCode &success) - : OpenTypeLayoutEngine(fontInstance, getScriptCode(scriptTag), getLanguageCode(languageTag), 3, gsubTable, success) -{ - fDefaultFeatureMap = fFeatureMap; - - // check the result of setScriptAndLanguageTags(), in case they were unknown to ICU - if (fScriptTag != scriptTag || fLangSysTag != languageTag) { - fScriptTag = scriptTag; - fLangSysTag = languageTag; - - // reset the GPOS if the tags changed - fGPOSTable = NULL; - if (gposTable != NULL && gposTable->coversScriptAndLanguage(fScriptTag, fLangSysTag)) { - fGPOSTable = gposTable; - } - } - - adjustFeatures(addFeatures, addParams, removeFeatures); -} - -XeTeXOTLayoutEngine::~XeTeXOTLayoutEngine() -{ - if (fFeatureMap != NULL && fFeatureMap != fDefaultFeatureMap) - LE_DELETE_ARRAY(fFeatureMap); - if (fFeatureParamList != NULL) - LE_DELETE_ARRAY(fFeatureParamList); -} - -void XeTeXOTLayoutEngine::adjustFeatures(const LETag* addTags, const le_int32* addParams, const LETag* removeTags) -{ - // bail out if nothing was requested! - if ((addTags == NULL || *addTags == emptyTag) && (removeTags == NULL || *removeTags == emptyTag)) - return; - - // figure out total tag count: initial set - removed tags + added tags omitting duplicates - le_int32 totalCount = 0; - for (le_int32 i = 0; i < fFeatureMapCount; ++i) { - // skip any that are disabled by the mask - if ((fFeatureMask & fFeatureMap[i].mask) != 0) { - bool remove = false; - for (const LETag* r = removeTags; r != NULL && *r != emptyTag; ++r) - if (*r == fFeatureMap[i].tag) { - remove = true; - break; - } - if (!remove) - ++totalCount; - } - } - for (const LETag* a = addTags; a != NULL && *a != emptyTag; ++a) { - // before counting an add tag, check original map, and check for duplicates in list - bool add = true; - for (le_int32 i = 0; i < fFeatureMapCount; ++i) - if (*a == fFeatureMap[i].tag) { - if ((fFeatureMask & fFeatureMap[i].mask) != 0) - add = false; - break; - } - if (add) { - for (const LETag* t = addTags; t != a; ++t) - if (*a == *t) { - add = false; - break; - } - } - if (add) - ++totalCount; - } - - if (totalCount > 32) - fprintf(stderr, "\n*** feature count exceeds mask size; some features will be ignored\n"); - - // allocate new map - FeatureMap* newFeatureMap = LE_NEW_ARRAY(FeatureMap, totalCount); - le_int32 newFeatureCount = 0; - le_int32* newParamList = (addParams == NULL) ? NULL : LE_NEW_ARRAY(le_int32, totalCount); - - // copy the features into the map and assign mask bits - FeatureMask newFeatureMask = 0; - FeatureMask maskBit = 0x80000000UL; - for (le_int32 i = 0; i < fFeatureMapCount; ++i) { - bool remove = false; - if ((fFeatureMask & fFeatureMap[i].mask) == 0) - remove = true; - else - for (const LETag* r = removeTags; r != NULL && *r != emptyTag; ++r) - if (*r == fFeatureMap[i].tag) { - remove = true; - break; - } - if (!remove) { - newFeatureMap[newFeatureCount].tag = fFeatureMap[i].tag; - newFeatureMap[newFeatureCount].mask = maskBit; - if (newParamList != NULL) - newParamList[newFeatureCount] = 0; - ++newFeatureCount; - newFeatureMask |= maskBit; - maskBit >>= 1; - } - } - const le_int32* param = addParams; - for (const LETag* a = addTags; a != NULL && *a != emptyTag; ++a) { - bool add = true; - for (le_int32 i = 0; i < fFeatureMapCount; ++i) - if (*a == fFeatureMap[i].tag) { - if ((fFeatureMask & fFeatureMap[i].mask) != 0) - add = false; - break; - } - if (add) { - for (const LETag* t = addTags; t != a; ++t) - if (*a == *t) { - add = false; - break; - } - } - if (add) { - newFeatureMap[newFeatureCount].tag = *a; - newFeatureMap[newFeatureCount].mask = maskBit; - if (newParamList != NULL) - newParamList[newFeatureCount] = *param++; - ++newFeatureCount; - newFeatureMask |= maskBit; - maskBit >>= 1; - } - } - - fFeatureMask = newFeatureMask; - fFeatureMap = newFeatureMap; - fFeatureMapCount = newFeatureCount; - fFeatureParamList = newParamList; -} - - -/* - * XeTeXHanLayoutEngine - */ - -UOBJECT_DEFINE_RTTI_IMPLEMENTATION(XeTeXHanLayoutEngine) - -static const LETag loclFeatureTag = LE_LOCL_FEATURE_TAG; -static const LETag smplFeatureTag = LE_SMPL_FEATURE_TAG; -static const LETag tradFeatureTag = LE_TRAD_FEATURE_TAG; -static const LETag vertFeatureTag = LE_VERT_FEATURE_TAG; -static const LETag vrt2FeatureTag = LE_VRT2_FEATURE_TAG; - -#define loclFeatureMask 0x80000000UL -#define smplFeatureMask 0x40000000UL -#define tradFeatureMask 0x20000000UL -#define vertFeatureMask 0x10000000UL -#define vrt2FeatureMask 0x08000000UL - -static const FeatureMap featureMap[] = { - {loclFeatureTag, loclFeatureMask}, - {smplFeatureTag, smplFeatureMask}, - {tradFeatureTag, tradFeatureMask}, - {vertFeatureTag, vertFeatureMask}, - {vrt2FeatureTag, vrt2FeatureMask}, -}; -static const le_int32 featureMapCount = LE_ARRAY_SIZE(featureMap); - -#define HORIZ_FEATURES (loclFeatureMask) -#define VERT_FEATURES (loclFeatureMask|vertFeatureMask|vrt2FeatureMask) - -XeTeXHanLayoutEngine::XeTeXHanLayoutEngine(const XeTeXFontInst *fontInstance, LETag scriptTag, LETag languageTag, - const GlyphSubstitutionTableHeader *gsubTable, const GlyphPositioningTableHeader *gposTable, - const LETag *addFeatures, const le_int32* addParams, - const LETag *removeFeatures, LEErrorCode &success) - : XeTeXOTLayoutEngine(fontInstance, scriptTag, languageTag, gsubTable, gposTable, NULL, NULL, NULL, success) -{ - // reset the feature map and default features - fFeatureMap = featureMap; - fDefaultFeatureMap = fFeatureMap; - fFeatureMapCount = featureMapCount; - - fFeatureMask = fontInstance->getLayoutDirVertical() ? VERT_FEATURES : HORIZ_FEATURES; - - // then apply any adjustments - adjustFeatures(addFeatures, addParams, removeFeatures); -} - -XeTeXHanLayoutEngine::~XeTeXHanLayoutEngine() -{ -} diff --git a/Build/source/texk/web2c/xetexdir/XeTeXOTLayoutEngine.h b/Build/source/texk/web2c/xetexdir/XeTeXOTLayoutEngine.h deleted file mode 100644 index f7ac66c5f8a..00000000000 --- a/Build/source/texk/web2c/xetexdir/XeTeXOTLayoutEngine.h +++ /dev/null @@ -1,74 +0,0 @@ -/****************************************************************************\ - Part of the XeTeX typesetting system - copyright (c) 1994-2008 by SIL International - copyright (c) 2009, 2011 by Jonathan Kew - - Written by Jonathan Kew - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE -FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF -CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of the copyright holders -shall not be used in advertising or otherwise to promote the sale, -use or other dealings in this Software without prior written -authorization from the copyright holders. -\****************************************************************************/ - -#ifndef __XeTeXOTLayoutEngine_h -#define __XeTeXOTLayoutEngine_h - -#include "layout/OpenTypeLayoutEngine.h" - -// /* ICU-4.2 added 'success' as last parameter to LayoutEngine constructors. */ -// #include "unicode/uversion.h" -// #define U_ICU_VERSION_CODE (U_ICU_VERSION_MAJOR_NUM*10+U_ICU_VERSION_MINOR_NUM) - -#include "XeTeXFontInst.h" - -class XeTeXOTLayoutEngine : public OpenTypeLayoutEngine -{ -public: - XeTeXOTLayoutEngine(const LEFontInstance* fontInstance, LETag scriptTag, LETag languageTag, - const GlyphSubstitutionTableHeader* gsubTable, - const GlyphPositioningTableHeader* gposTable, - const LETag* addFeatures, const le_int32* addParams, - const LETag* removeFeatures, LEErrorCode &success); - - virtual ~XeTeXOTLayoutEngine(); - - virtual void adjustFeatures(const LETag* addTags, const le_int32* addParams, const LETag* removeTags); - - virtual UClassID getDynamicClassID() const; - static UClassID getStaticClassID(); - - static LayoutEngine* LayoutEngineFactory - (const XeTeXFontInst* fontInstance, - LETag scriptTag, LETag languageTag, - const LETag* addFeatures, const le_int32* addParams, - const LETag* removeFeatures, - LEErrorCode &success); - -protected: - const FeatureMap* fDefaultFeatureMap; - -private: -}; - -#endif - diff --git a/Build/source/texk/web2c/xetexdir/XeTeXOTMath.cpp b/Build/source/texk/web2c/xetexdir/XeTeXOTMath.cpp index 0374cb4cf40..e2c2e9e82ca 100644 --- a/Build/source/texk/web2c/xetexdir/XeTeXOTMath.cpp +++ b/Build/source/texk/web2c/xetexdir/XeTeXOTMath.cpp @@ -1,9 +1,10 @@ /****************************************************************************\ Part of the XeTeX typesetting system - copyright (c) 1994-2008 by SIL International - copyright (c) 2009 by Jonathan Kew + Copyright (c) 1994-2008 by SIL International + Copyright (c) 2009 by Jonathan Kew + Copyright (c) 2012 by Khaled Hosny - Written by Jonathan Kew + SIL Author(s): Jonathan Kew Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -30,15 +31,14 @@ use or other dealings in this Software without prior written authorization from the copyright holders. \****************************************************************************/ +#include + #include "XeTeXOTMath.h" #include "XeTeX_ext.h" #include "XeTeXLayoutInterface.h" #include "XeTeXFontInst.h" - -#include "layout/CoverageTables.h" - -#define kMATHTableTag 0x4D415448 +#include "XeTeXswap.h" typedef void* voidptr; @@ -48,27 +48,44 @@ extern "C" { extern integer* fontsize; } -#include "layout/LESwaps.h" +static int32_t getCoverage(const Coverage* coverage, GlyphID g) +{ + if (SWAP(coverage->format) == 1) { + const CoverageFormat1 *table = (const CoverageFormat1 *) coverage; + for (int i = 0; i < SWAP(table->glyphCount); i++) { + if (SWAP(table->glyphArray[i]) == g) + return i; + } + } else if (SWAP(coverage->format) == 2) { + const CoverageFormat2 *table = (const CoverageFormat2 *) coverage; + for (int i = 0; i < SWAP(table->rangeCount); i++) { + if (SWAP(table->rangeArray[i].start) <= g && SWAP(table->rangeArray[i].end) >= g) + return SWAP(table->rangeArray[i].startCoverageIndex) + (g - SWAP(table->rangeArray[i].start)); + } + } + + return -1; +} -static SInt16 getMathConstant(LEFontInstance* fontInst, mathConstantIndex whichConstant) +static SInt16 getMathConstant(XeTeXFontInst* fontInst, mathConstantIndex whichConstant) { - const char* table = (const char*)fontInst->getFontTable(kMATHTableTag); + const char* table = (const char*)fontInst->getFontTable(kMATH); if (table == NULL) return 0; - const UInt16* constants = (const UInt16*)(table + SWAPW(((const MathTableHeader*)table)->mathConstants)); + const UInt16* constants = (const UInt16*)(table + SWAP(((const MathTableHeader*)table)->mathConstants)); if (whichConstant < firstMathValueRecord) { /* it's a simple 16-bit value */ - return SWAPW(constants[whichConstant]); + return SWAP(constants[whichConstant]); } else if (whichConstant <= lastMathValueRecord) { const MathValueRecord* valueRecords = (const MathValueRecord*) ((char*)constants + firstMathValueRecord * sizeof(UInt16) - firstMathValueRecord * sizeof(MathValueRecord)); - return SWAPW(valueRecords[whichConstant].value); + return SWAP(valueRecords[whichConstant].value); } else if (whichConstant <= lastMathConstant) { - return SWAPW(constants[whichConstant + (lastMathValueRecord - firstMathValueRecord + 1)]); + return SWAP(constants[whichConstant + (lastMathValueRecord - firstMathValueRecord + 1)]); } else return 0; /* or abort, with "internal error" or something */ @@ -84,7 +101,7 @@ get_ot_math_constant(int f, int n) rval = getMathConstant(font, (mathConstantIndex)n); /* scale according to font size, except the ones that are percentages */ if (n > scriptScriptPercentScaleDown && n < radicalDegreeBottomRaisePercent) - rval = X2Fix(rval * Fix2X(fontsize[f]) / font->getUnitsPerEM()); + rval = D2Fix(font->unitsToPoints(rval)); } return rval; } @@ -148,7 +165,7 @@ get_native_mathsy_param(int f, int n) rval = get_ot_math_constant(f, (int)ot_index); } } -// fprintf(stderr, " math_sy(%d, %d) returns %.3f\n", f, n, Fix2X(rval)); +// fprintf(stderr, " math_sy(%d, %d) returns %.3f\n", f, n, Fix2D(rval)); return rval; } @@ -192,7 +209,7 @@ get_native_mathex_param(int f, int n) rval = get_ot_math_constant(f, (int)ot_index); } } -// fprintf(stderr, " math_ex(%d, %d) returns %.3f\n", f, n, Fix2X(rval)); +// fprintf(stderr, " math_ex(%d, %d) returns %.3f\n", f, n, Fix2D(rval)); return rval; } @@ -206,30 +223,29 @@ get_ot_math_variant(int f, int g, int v, integer* adv, int horiz) if (fontarea[f] == OTGR_FONT_FLAG) { XeTeXFontInst* font = (XeTeXFontInst*)getFont((XeTeXLayoutEngine)fontlayoutengine[f]); - const char* table = (const char*)font->getFontTable(kMATHTableTag); + const char* table = (const char*)font->getFontTable(kMATH); if (table == NULL) return rval; - le_uint16 offset = SWAPW(((const MathTableHeader*)table)->mathVariants); + uint16_t offset = SWAP(((const MathTableHeader*)table)->mathVariants); if (offset == 0) return rval; const MathVariants* variants = (const MathVariants*)(table + offset); - offset = horiz ? SWAPW(variants->horizGlyphCoverage) : SWAPW(variants->vertGlyphCoverage); + offset = horiz ? SWAP(variants->horizGlyphCoverage) : SWAP(variants->vertGlyphCoverage); if (offset == 0) return rval; - const CoverageTable* coverage = (const CoverageTable*)(((const char*)variants) + offset); + const Coverage* coverage = (const Coverage*)(((const char*)variants) + offset); - le_int32 index = coverage->getGlyphCoverage(g); + int32_t index = getCoverage(coverage, g); if (index >= 0) { if (horiz) - index += SWAPW(variants->vertGlyphCount); + index += SWAP(variants->vertGlyphCount); const MathGlyphConstruction* construction = (const MathGlyphConstruction*)(((const char*)variants) - + SWAPW(variants->vertGlyphConstruction[index])); - if (v < SWAPW(construction->variantCount)) { - rval = SWAPW(construction->mathGlyphVariantRecord[v].variantGlyph); - *adv = X2Fix(SWAPW(construction->mathGlyphVariantRecord[v].advanceMeasurement) - * Fix2X(fontsize[f]) / font->getUnitsPerEM()); + + SWAP(variants->vertGlyphConstruction[index])); + if (v < SWAP(construction->variantCount)) { + rval = SWAP(construction->mathGlyphVariantRecord[v].variantGlyph); + *adv = D2Fix(font->unitsToPoints(SWAP(construction->mathGlyphVariantRecord[v].advanceMeasurement))); } } } @@ -245,27 +261,27 @@ get_ot_assembly_ptr(int f, int g, int horiz) if (fontarea[f] == OTGR_FONT_FLAG) { XeTeXFontInst* font = (XeTeXFontInst*)getFont((XeTeXLayoutEngine)fontlayoutengine[f]); - const char* table = (const char*)font->getFontTable(kMATHTableTag); + const char* table = (const char*)font->getFontTable(kMATH); if (table == NULL) return rval; - le_uint16 offset = SWAPW(((const MathTableHeader*)table)->mathVariants); + uint16_t offset = SWAP(((const MathTableHeader*)table)->mathVariants); if (offset == 0) return rval; const MathVariants* variants = (const MathVariants*)(table + offset); - offset = horiz ? SWAPW(variants->horizGlyphCoverage) : SWAPW(variants->vertGlyphCoverage); + offset = horiz ? SWAP(variants->horizGlyphCoverage) : SWAP(variants->vertGlyphCoverage); if (offset == 0) return rval; - const CoverageTable* coverage = (const CoverageTable*)(((const char*)variants) + offset); + const Coverage* coverage = (const Coverage*)(((const char*)variants) + offset); - le_int32 index = coverage->getGlyphCoverage(g); + int32_t index = getCoverage(coverage, g); if (index >= 0) { if (horiz) - index += SWAPW(variants->vertGlyphCount); + index += SWAP(variants->vertGlyphCount); const MathGlyphConstruction* construction = (const MathGlyphConstruction*)(((const char*)variants) - + SWAPW(variants->vertGlyphConstruction[index])); - offset = SWAPW(construction->glyphAssembly); + + SWAP(variants->vertGlyphConstruction[index])); + offset = SWAP(construction->glyphAssembly); if (offset != 0) rval = (void*)(((const char*)construction) + offset); } @@ -282,28 +298,28 @@ get_ot_math_ital_corr(int f, int g) if (fontarea[f] == OTGR_FONT_FLAG) { XeTeXFontInst* font = (XeTeXFontInst*)getFont((XeTeXLayoutEngine)fontlayoutengine[f]); - const char* table = (const char*)font->getFontTable(kMATHTableTag); + const char* table = (const char*)font->getFontTable(kMATH); if (table == NULL) return rval; - le_uint16 offset = SWAPW(((const MathTableHeader*)table)->mathGlyphInfo); + uint16_t offset = SWAP(((const MathTableHeader*)table)->mathGlyphInfo); if (offset == 0) return rval; const MathGlyphInfo* glyphInfo = (const MathGlyphInfo*)(table + offset); - offset = SWAPW(glyphInfo->mathItalicsCorrectionInfo); + offset = SWAP(glyphInfo->mathItalicsCorrectionInfo); if (offset == 0) return rval; const MathItalicsCorrectionInfo* italCorrInfo = (const MathItalicsCorrectionInfo*)(((const char*)glyphInfo) + offset); - offset = SWAPW(italCorrInfo->coverage); + offset = SWAP(italCorrInfo->coverage); if (offset == 0) return rval; - const CoverageTable* coverage = (const CoverageTable*)(((const char*)italCorrInfo) + offset); + const Coverage* coverage = (const Coverage*)(((const char*)italCorrInfo) + offset); - le_int32 index = coverage->getGlyphCoverage(g); - if (index >= 0 && index < SWAPW(italCorrInfo->italicsCorrectionCount)) - rval = X2Fix(SWAPW(italCorrInfo->italicsCorrection[index].value) * Fix2X(fontsize[f]) / font->getUnitsPerEM()); + int32_t index = getCoverage(coverage, g); + if (index >= 0 && index < SWAP(italCorrInfo->italicsCorrectionCount)) + rval = D2Fix(font->unitsToPoints(SWAP(italCorrInfo->italicsCorrection[index].value))); } return rval; @@ -317,29 +333,29 @@ get_ot_math_accent_pos(int f, int g) if (fontarea[f] == OTGR_FONT_FLAG) { XeTeXFontInst* font = (XeTeXFontInst*)getFont((XeTeXLayoutEngine)fontlayoutengine[f]); - const char* table = (const char*)font->getFontTable(kMATHTableTag); + const char* table = (const char*)font->getFontTable(kMATH); if (table == NULL) return rval; - le_uint16 offset = SWAPW(((const MathTableHeader*)table)->mathGlyphInfo); + uint16_t offset = SWAP(((const MathTableHeader*)table)->mathGlyphInfo); if (offset == 0) return rval; const MathGlyphInfo* glyphInfo = (const MathGlyphInfo*)(table + offset); - offset = SWAPW(glyphInfo->mathTopAccentAttachment); + offset = SWAP(glyphInfo->mathTopAccentAttachment); if (offset == 0) return rval; const MathTopAccentAttachment* accentAttachment = (const MathTopAccentAttachment*)(((const char*)glyphInfo) + offset); - offset = SWAPW(accentAttachment->coverage); + offset = SWAP(accentAttachment->coverage); if (offset == 0) return rval; - const CoverageTable* coverage = (const CoverageTable*)(((const char*)accentAttachment) + offset); + const Coverage* coverage = (const Coverage*)(((const char*)accentAttachment) + offset); - le_int32 index = coverage->getGlyphCoverage(g); - if (index >= 0 && index < SWAPW(accentAttachment->topAccentAttachmentCount)) { - rval = (le_int16)SWAPW(accentAttachment->topAccentAttachment[index].value); - rval = X2Fix(rval * Fix2X(fontsize[f]) / font->getUnitsPerEM()); + int32_t index = getCoverage(coverage, g); + if (index >= 0 && index < SWAP(accentAttachment->topAccentAttachmentCount)) { + rval = (int16_t)SWAP(accentAttachment->topAccentAttachment[index].value); + rval = D2Fix(font->unitsToPoints(rval)); } } @@ -354,16 +370,174 @@ ot_min_connector_overlap(int f) if (fontarea[f] == OTGR_FONT_FLAG) { XeTeXFontInst* font = (XeTeXFontInst*)getFont((XeTeXLayoutEngine)fontlayoutengine[f]); - const char* table = (const char*)font->getFontTable(kMATHTableTag); + const char* table = (const char*)font->getFontTable(kMATH); if (table == NULL) return rval; - le_uint16 offset = SWAPW(((const MathTableHeader*)table)->mathVariants); + uint16_t offset = SWAP(((const MathTableHeader*)table)->mathVariants); if (offset == 0) return rval; const MathVariants* variants = (const MathVariants*)(table + offset); - rval = X2Fix(SWAPW(variants->minConnectorOverlap) * Fix2X(fontsize[f]) / font->getUnitsPerEM()); + rval = D2Fix(font->unitsToPoints(SWAP(variants->minConnectorOverlap))); + } + + return rval; +} + +typedef enum { + topRight, + topLeft, + bottomRight, + bottomLeft, +} MathKernSide; + +static int +getMathKernAt(int f, int g, MathKernSide side, int height) +{ + int rval = 0; + if (fontarea[f] == OTGR_FONT_FLAG) { + XeTeXFontInst* font = (XeTeXFontInst*)getFont((XeTeXLayoutEngine)fontlayoutengine[f]); + + const char* table = (const char*)font->getFontTable(kMATH); + if (table == NULL) + return rval; + + uint16_t offset = SWAP(((const MathTableHeader*)table)->mathGlyphInfo); + if (offset == 0) + return rval; + + const MathGlyphInfo* glyphInfo = (const MathGlyphInfo*)(table + offset); + + offset = SWAP(glyphInfo->mathKernInfo); + if (offset == 0) + return rval; + + const MathKernInfo* mathKernInfo = (const MathKernInfo*)(((const char*)glyphInfo) + offset); + + offset = SWAP(mathKernInfo->coverage); + if (offset == 0) + return rval; + + const Coverage* coverage = (const Coverage*)(((const char*)mathKernInfo) + offset); + + int32_t index = getCoverage(coverage, g); + if (index >= 0 && index < SWAP(mathKernInfo->kernInfoCount)) { + if (side == topRight) + offset = SWAP(mathKernInfo->kernInfo[index].topRight); + else if (side == bottomRight) + offset = SWAP(mathKernInfo->kernInfo[index].bottomRight); + else if (side == topLeft) + offset = SWAP(mathKernInfo->kernInfo[index].topLeft); + else if (side == bottomLeft) + offset = SWAP(mathKernInfo->kernInfo[index].bottomLeft); + else + assert(0); // we should not reach here + + if (offset == 0) + return rval; + + const MathKernTable* kernTable = (const MathKernTable*)(((const char*)mathKernInfo) + offset); + + uint16_t count = SWAP(kernTable->heightCount); + + // XXX: the following makes no sense WRT my understanding of the + // spec! it is just how things worked for me. + if (count == 0) + rval = SWAP(kernTable->kern[-1].value); + else if (height < SWAP(kernTable->height[0].value)) + rval = SWAP(kernTable->kern[1].value); + else if (height > SWAP(kernTable->height[count].value)) + rval = SWAP(kernTable->kern[count+1].value); + else { + for (int i = 0; i < count; i++) { + if (height > SWAP(kernTable->height[i].value)) { + rval = SWAP(kernTable->kern[i+1].value); + break; + } + } + } + + //fprintf(stderr, " kern: %f %f\n", font->unitsToPoints(height), font->unitsToPoints(rval)); + } + } + + return rval; +} + +static float +glyph_height(int f, int g) +{ + float rval = 0.0; + + if (fontarea[f] == OTGR_FONT_FLAG) { + XeTeXLayoutEngine engine = (XeTeXLayoutEngine)fontlayoutengine[f]; + getGlyphHeightDepth(engine, g, &rval, NULL); + } + + return rval; +} + +static float +glyph_depth(int f, int g) +{ + float rval = 0.0; + + if (fontarea[f] == OTGR_FONT_FLAG) { + XeTeXLayoutEngine engine = (XeTeXLayoutEngine)fontlayoutengine[f]; + getGlyphHeightDepth(engine, g, NULL, &rval); + } + + return rval; +} + +// keep in sync with xetex.web +#define sup_cmd 0 +#define sub_cmd 1 + +int +get_ot_math_kern(int f, int g, int sf, int sg, int cmd, int shift) +{ + int rval = 0; + + if (fontarea[f] == OTGR_FONT_FLAG) { + XeTeXFontInst* font = (XeTeXFontInst*)getFont((XeTeXLayoutEngine)fontlayoutengine[f]); + int kern = 0, skern = 0; + float corr_height_top = 0.0, corr_height_bot = 0.0; + + shift = Fix2D(shift); + + if (cmd == sup_cmd) { // superscript + corr_height_top = font->pointsToUnits(glyph_height(f, g)); + corr_height_bot = -font->pointsToUnits(glyph_depth(sf, sg) + shift); + + kern = getMathKernAt(f, g, topRight, corr_height_top); + skern = getMathKernAt(sf, sg, bottomLeft, corr_height_top); + rval = kern + skern; + + kern = getMathKernAt(f, g, topRight, corr_height_bot); + skern = getMathKernAt(sf, sg, bottomLeft, corr_height_bot); + if ((kern + skern) < rval) + rval = kern + skern; + + } else if (cmd == sub_cmd) { // subscript + corr_height_top = font->pointsToUnits(glyph_height(sf, sg) - shift); + corr_height_bot = -font->pointsToUnits(glyph_depth(f, g)); + + kern = getMathKernAt(f, g, bottomRight, corr_height_top); + skern = getMathKernAt(sf, sg, topLeft, corr_height_top); + rval = kern + skern; + + kern = getMathKernAt(f, g, bottomRight, corr_height_bot); + skern = getMathKernAt(sf, sg, topLeft, corr_height_bot); + if ((kern + skern) < rval) + rval = kern + skern; + + } else { + assert(0); // we should not reach here + } + + rval = D2Fix(font->unitsToPoints(rval)); } return rval; @@ -372,19 +546,19 @@ ot_min_connector_overlap(int f) int ot_part_count(const GlyphAssembly* a) { - return SWAPW(a->partCount); + return SWAP(a->partCount); } int ot_part_glyph(const GlyphAssembly* a, int i) { - return SWAPW(a->partRecords[i].glyph); + return SWAP(a->partRecords[i].glyph); } int ot_part_is_extender(const GlyphAssembly* a, int i) { - return (SWAPW(a->partRecords[i].partFlags) & fExtender) != 0; + return (SWAP(a->partRecords[i].partFlags) & fExtender) != 0; } int @@ -394,7 +568,7 @@ ot_part_start_connector(int f, const GlyphAssembly* a, int i) if (fontarea[f] == OTGR_FONT_FLAG) { XeTeXFontInst* font = (XeTeXFontInst*)getFont((XeTeXLayoutEngine)fontlayoutengine[f]); - rval = X2Fix(SWAPW(a->partRecords[i].startConnectorLength) * Fix2X(fontsize[f]) / font->getUnitsPerEM()); + rval = D2Fix(font->unitsToPoints(SWAP(a->partRecords[i].startConnectorLength))); } return rval; @@ -407,7 +581,7 @@ ot_part_end_connector(int f, const GlyphAssembly* a, int i) if (fontarea[f] == OTGR_FONT_FLAG) { XeTeXFontInst* font = (XeTeXFontInst*)getFont((XeTeXLayoutEngine)fontlayoutengine[f]); - rval = X2Fix(SWAPW(a->partRecords[i].endConnectorLength) * Fix2X(fontsize[f]) / font->getUnitsPerEM()); + rval = D2Fix(font->unitsToPoints(SWAP(a->partRecords[i].endConnectorLength))); } return rval; @@ -420,7 +594,7 @@ ot_part_full_advance(int f, const GlyphAssembly* a, int i) if (fontarea[f] == OTGR_FONT_FLAG) { XeTeXFontInst* font = (XeTeXFontInst*)getFont((XeTeXLayoutEngine)fontlayoutengine[f]); - rval = X2Fix(SWAPW(a->partRecords[i].fullAdvance) * Fix2X(fontsize[f]) / font->getUnitsPerEM()); + rval = D2Fix(font->unitsToPoints(SWAP(a->partRecords[i].fullAdvance))); } return rval; diff --git a/Build/source/texk/web2c/xetexdir/XeTeXOTMath.h b/Build/source/texk/web2c/xetexdir/XeTeXOTMath.h index 7e2fe3f552a..1304c84e76e 100644 --- a/Build/source/texk/web2c/xetexdir/XeTeXOTMath.h +++ b/Build/source/texk/web2c/xetexdir/XeTeXOTMath.h @@ -1,9 +1,9 @@ /****************************************************************************\ Part of the XeTeX typesetting system - copyright (c) 1994-2008 by SIL International - copyright (c) 2009 by Jonathan Kew + Copyright (c) 1994-2008 by SIL International + Copyright (c) 2009 by Jonathan Kew - Written by Jonathan Kew + SIL Author(s): Jonathan Kew Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -47,6 +47,7 @@ extern "C" { void* get_ot_assembly_ptr(int f, int g, int horiz); int get_ot_math_ital_corr(int f, int g); int get_ot_math_accent_pos(int f, int g); + int get_ot_math_kern(int f, int g, int sf, int sg, int cmd, int shift); int ot_part_count(const GlyphAssembly* a); int ot_part_glyph(const GlyphAssembly* a, int i); int ot_part_is_extender(const GlyphAssembly* a, int i); diff --git a/Build/source/texk/web2c/xetexdir/XeTeX_ext.c b/Build/source/texk/web2c/xetexdir/XeTeX_ext.c index c23f9e16bcc..8833145f5c8 100644 --- a/Build/source/texk/web2c/xetexdir/XeTeX_ext.c +++ b/Build/source/texk/web2c/xetexdir/XeTeX_ext.c @@ -1,9 +1,10 @@ /****************************************************************************\ Part of the XeTeX typesetting system - copyright (c) 1994-2008 by SIL International - copyright (c) 2009, 2011 by Jonathan Kew + Copyright (c) 1994-2008 by SIL International + Copyright (c) 2009, 2011 by Jonathan Kew + Copyright (c) 2012 by Khaled Hosny - Written by Jonathan Kew + SIL Author(s): Jonathan Kew Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -86,47 +87,12 @@ authorization from the copyright holders. #include "XeTeXswap.h" -#include "unicode/ubidi.h" -#include "unicode/ubrk.h" -#include "unicode/ucnv.h" +#include +#include +#include #include -/* #include "sfnt.h" - doesn't work in plain C files :( -*/ - -typedef struct -{ - Fixed version; - UInt16 numGlyphs; - UInt16 maxPoints; - UInt16 maxContours; - UInt16 maxComponentPoints; - UInt16 maxComponentContours; - UInt16 maxZones; - UInt16 maxTwilightPoints; - UInt16 maxStorage; - UInt16 maxFunctionDefs; - UInt16 maxInstructionDefs; - UInt16 maxStackElements; - UInt16 maxSizeOfInstructions; - UInt16 maxComponentElements; - UInt16 maxComponentDepth; -} MAXPTable; - -typedef struct -{ - Fixed version; - Fixed italicAngle; - SInt16 underlinePosition; - UInt16 underlineThickness; - UInt32 isFixedPitch; - UInt32 minMemType42; - UInt32 maxMemType42; - UInt32 minMemType1; - UInt32 maxMemType1; -} POSTTable; /* tables/values used in UTF-8 interpretation - code is based on ConvertUTF.[ch] sample code @@ -182,9 +148,10 @@ void initversionstring(char **versions) FT_Int ftMajor, ftMinor, ftPatch; const_string fmt = - "Compiled with ICU version %s [with modifications for XeTeX]\n" + "Compiled with ICU version %s\n" "Compiled with zlib version %s; using %s\n" "Compiled with FreeType2 version %d.%d.%d; using %d.%d.%d\n" + "Compiled with HarfBuzz version %s; using %s\n" #ifdef XETEX_MAC "Using Mac OS X Carbon, Cocoa & QuickTime frameworks\n" #else @@ -198,6 +165,8 @@ void initversionstring(char **versions) + strlen(U_ICU_VERSION) + strlen(ZLIB_VERSION) + strlen(zlib_version) + + strlen(HB_VERSION_STRING) + + strlen(hb_version_string()) #ifdef XETEX_OTHER + strlen(PNG_LIBPNG_VER_STRING) + strlen(png_libpng_ver) @@ -220,7 +189,8 @@ void initversionstring(char **versions) U_ICU_VERSION, ZLIB_VERSION, zlib_version, FREETYPE_MAJOR, FREETYPE_MINOR, FREETYPE_PATCH, - ftMajor, ftMinor, ftPatch + ftMajor, ftMinor, ftPatch, + HB_VERSION_STRING, hb_version_string() #ifdef XETEX_OTHER , FC_VERSION / 10000, (FC_VERSION % 10000) / 100, FC_VERSION % 100, @@ -483,8 +453,17 @@ static UBreakIterator* brkIter = NULL; static int brkLocaleStrNum = 0; void -linebreakstart(integer localeStrNum, const UniChar* text, integer textLength) +linebreakstart(int f, integer localeStrNum, const UniChar* text, integer textLength) { + char* locale = (char*)gettexstring(localeStrNum); + + if (fontarea[f] == OTGR_FONT_FLAG && strcmp(locale, "G") == 0) { + XeTeXLayoutEngine engine = (XeTeXLayoutEngine) fontlayoutengine[f]; + if (initGraphiteBreaking(engine, text, textLength)) + /* user asked for Graphite line breaking and the font supports it */ + return; + } + UErrorCode status = 0; if ((localeStrNum != brkLocaleStrNum) && (brkIter != NULL)) { @@ -493,7 +472,6 @@ linebreakstart(integer localeStrNum, const UniChar* text, integer textLength) } if (brkIter == NULL) { - char* locale = (char*)gettexstring(localeStrNum); brkIter = ubrk_open(UBRK_LINE, locale, NULL, 0, &status); if (U_FAILURE(status)) { begindiagnostic(); @@ -523,7 +501,10 @@ linebreakstart(integer localeStrNum, const UniChar* text, integer textLength) int linebreaknext() { - return ubrk_next((UBreakIterator*)brkIter); + if (brkIter != NULL) + return ubrk_next((UBreakIterator*)brkIter); + else + return findNextGraphiteBreak(); } int @@ -728,6 +709,23 @@ read_double(const char** s) return neg ? -val : val; } +static char* +read_str_tag(const char* cp) +{ + char tag[5]; + int i; + for (i = 0; i < 4; ++i) { + if (*cp && /* *cp < 128 && */ *cp != ',' && *cp != ';' && *cp != ':') { + tag[i] = *cp; + ++cp; + } + else + tag[i] = ' '; + } + tag[4] = '\0'; + return tag; +} + static UInt32 read_tag(const char* cp, char padChar) { @@ -745,19 +743,18 @@ read_tag(const char* cp, char padChar) return tag; } -static UInt32 -read_tag_with_param(const char* cp, SInt32* param) +static hb_tag_t +read_tag_with_param(const char* cp, int* param) { - UInt32 tag = 0; + char tag[4]; int i; for (i = 0; i < 4; ++i) { - tag <<= 8; if (*cp && /* *cp < 128 && */ *cp != ',' && *cp != ';' && *cp != ':') { - tag += *(unsigned char*)cp; + tag[i] = *cp; ++cp; } else - tag += ' '; + tag[i] = ' '; } if (*cp == '=') { int neg = 0; @@ -773,7 +770,7 @@ read_tag_with_param(const char* cp, SInt32* param) if (neg) *param = -(*param); } - return tag; + return HB_TAG(tag[0],tag[1],tag[2],tag[3]); } unsigned int @@ -879,24 +876,52 @@ readCommonFeatures(const char* feat, const char* end, float* extend, float* slan return 0; } +static bool +readFeatureNumber(const char* s, const char* e, int* f, int* v) + /* s...e is a "id[=setting]" string; */ +{ + *f = 0; + *v = 0; + if (*s < '0' || *s > '9') + return false; + while (*s >= '0' && *s <= '9') + *f = *f * 10 + *s++ - '0'; + while ((*s == ' ') || (*s == '\t')) + ++s; + if (*s++ != '=') { + if (s >= e) + // no setting was specified, so we just use the first + // XXX the default is not always the first? + return true; + else + return false; + } + if (*s < '0' || *s > '9') + return false; + while (*s >= '0' && *s <= '9') + *v = *v * 10 + *s++ - '0'; + while ((*s == ' ') || (*s == '\t')) + ++s; + if (s != e) + return false; + return true; +} + static void* loadOTfont(PlatformFontRef fontRef, XeTeXFont font, Fixed scaled_size, const char* cp1) { XeTeXLayoutEngine engine; - UInt32 scriptTag = kLatin; - UInt32 languageTag = 0; - - UInt32* addFeatures = 0; - UInt32* removeFeatures = 0; - SInt32* addParams = 0; - - int nAdded = 0; - int nRemoved = 0; + char* script = NULL; + char* language = NULL; + hb_feature_t* features = NULL; + char** shapers = NULL; + int nFeatures = 0; + int nShapers = 0; const char* cp2; const char* cp3; - UInt32 tag; + hb_tag_t tag; UInt32 rgbValue = 0x000000FF; @@ -907,6 +932,16 @@ loadOTfont(PlatformFontRef fontRef, XeTeXFont font, Fixed scaled_size, const cha int i; + if (getReqEngine() == 'G') { + /* create a default engine so we can query the font for Graphite features; + * because of font caching, it's cheap to discard this and create the real one later */ + engine = createLayoutEngine(fontRef, font, script, language, + features, nFeatures, shapers, rgbValue, extend, slant, embolden); + + if (engine == NULL) + return NULL; + } + /* scan the feature string (if any) */ if (cp1 != NULL) { while (*cp1) { @@ -925,7 +960,7 @@ loadOTfont(PlatformFontRef fontRef, XeTeXFont font, Fixed scaled_size, const cha cp3 = cp1 + 6; if (*cp3 != '=') goto bad_option; - scriptTag = read_tag(cp3 + 1, ' '); + script = read_str_tag(cp3 + 1); goto next_option; } @@ -933,41 +968,64 @@ loadOTfont(PlatformFontRef fontRef, XeTeXFont font, Fixed scaled_size, const cha cp3 = cp1 + 8; if (*cp3 != '=') goto bad_option; - languageTag = read_tag(cp3 + 1, ' '); + language = read_str_tag(cp3 + 1); goto next_option; } + if (strncmp(cp1, "shaper", 6) == 0) { + cp3 = cp1 + 6; + if (*cp3 != '=') + goto bad_option; + cp3 = cp1 + 7; + shapers = xrealloc(shapers, (nShapers + 1) * sizeof(char *)); + shapers[nShapers++] = strndup(cp3, cp2 - cp3); + goto next_option; + } + i = readCommonFeatures(cp1, cp2, &extend, &slant, &embolden, &letterspace, &rgbValue); if (i == 1) goto next_option; else if (i == -1) goto bad_option; + + if (getReqEngine() == 'G') { + int value = 0; + if (readFeatureNumber(cp1, cp2, &tag, &value) + || findGraphiteFeature(engine, cp1, cp2, &tag, &value)) { + features = xrealloc(features, (nFeatures + 1) * sizeof(hb_feature_t)); + features[nFeatures].tag = tag; + features[nFeatures].start = 0; + features[nFeatures].end = (unsigned int) -1; + if (value == 0) + features[nFeatures].value = 1; + else + features[nFeatures].value = value; + nFeatures++; + goto next_option; + } + } if (*cp1 == '+') { - SInt32 param = 0; + int param = 0; tag = read_tag_with_param(cp1 + 1, ¶m); - ++nAdded; - if (nAdded == 1) { - addFeatures = xmalloc(sizeof(UInt32)); - addParams = xmalloc(sizeof(SInt32)); - } - else { - addFeatures = xrealloc(addFeatures, nAdded * sizeof(UInt32)); - addParams = xrealloc(addParams, nAdded * sizeof(SInt32)); - } - addFeatures[nAdded-1] = tag; - addParams[nAdded-1] = param; + features = xrealloc(features, (nFeatures + 1) * sizeof(hb_feature_t)); + features[nFeatures].tag = tag; + features[nFeatures].start = 0; + features[nFeatures].end = (unsigned int) -1; + if (param == 0) + features[nFeatures].value = 1; + else + features[nFeatures].value = param; + nFeatures++; goto next_option; } if (*cp1 == '-') { - tag = read_tag(cp1 + 1, ' '); - ++nRemoved; - if (nRemoved == 1) - removeFeatures = xmalloc(sizeof(UInt32)); - else - removeFeatures = xrealloc(removeFeatures, nRemoved * sizeof(UInt32)); - removeFeatures[nRemoved-1] = tag; + tag = hb_tag_from_string(read_str_tag(cp1 + 1), -1); + features = xrealloc(features, (nFeatures + 1) * sizeof(hb_feature_t)); + features[nFeatures].tag = tag; + features[nFeatures].value = 0; + nFeatures++; goto next_option; } @@ -991,19 +1049,13 @@ loadOTfont(PlatformFontRef fontRef, XeTeXFont font, Fixed scaled_size, const cha next_option: cp1 = cp2; } - - if (addFeatures != 0) { - addFeatures = realloc(addFeatures, (nAdded + 1) * sizeof(UInt32)); - addFeatures[nAdded] = 0; - } - if (removeFeatures != 0) { - removeFeatures = realloc(removeFeatures, (nRemoved + 1) * sizeof(UInt32)); - removeFeatures[nRemoved] = 0; - } } + if (shapers != NULL) + shapers[nShapers] = NULL; + if (embolden != 0.0) - embolden = embolden * Fix2X(scaled_size) / 100.0; + embolden = embolden * Fix2D(scaled_size) / 100.0; if (letterspace != 0.0) loadedfontletterspace = (letterspace / 100.0) * scaled_size; @@ -1014,17 +1066,13 @@ loadOTfont(PlatformFontRef fontRef, XeTeXFont font, Fixed scaled_size, const cha if ((loadedfontflags & FONT_FLAGS_VERTICAL) != 0) setFontLayoutDir(font, 1); - engine = createLayoutEngine(fontRef, font, scriptTag, languageTag, - addFeatures, addParams, removeFeatures, rgbValue, - extend, slant, embolden); + engine = createLayoutEngine(fontRef, font, script, language, + features, nFeatures, shapers, rgbValue, extend, slant, embolden); + if (engine == 0) { // only free these if creation failed, otherwise the engine now owns them - if (addFeatures) - free(addFeatures); - if (addParams) - free(addParams); - if (removeFeatures) - free(removeFeatures); + free(features); + free(shapers); } else nativefonttypeflag = OTGR_FONT_FLAG; @@ -1032,165 +1080,6 @@ loadOTfont(PlatformFontRef fontRef, XeTeXFont font, Fixed scaled_size, const cha return engine; } -static int -readFeatureNumber(const char* s, const char* e, int* f, int* v) -{ - *f = 0; - *v = 0; - if (*s < '0' || *s > '9') - return 0; - while (*s >= '0' && *s <= '9') - *f = *f * 10 + *s++ - '0'; - while ((*s == ' ') || (*s == '\t')) - ++s; - if (*s++ != '=') - return 0; - if (*s < '0' || *s > '9') - return 0; - while (*s >= '0' && *s <= '9') - *v = *v * 10 + *s++ - '0'; - while ((*s == ' ') || (*s == '\t')) - ++s; - if (s != e) - return 0; - return 1; -} - -#ifdef XETEX_GRAPHITE - -#define MAX_GRAPHITE_FEATURES 64 - -static void* -loadGraphiteFont(PlatformFontRef fontRef, XeTeXFont font, Fixed scaled_size, const char* cp1, const char* faceName) -{ - XeTeXLayoutEngine engine = NULL; - - const char* cp2; - const char* cp3; - - UInt32 rgbValue = 0x000000FF; - UInt32 languageTag = 0; - - float extend = 1.0; - float slant = 0.0; - float embolden = 0.0; - float letterspace = 0.0; - int rtl = 0; - - int featureIDs[MAX_GRAPHITE_FEATURES]; - int featureValues[MAX_GRAPHITE_FEATURES]; - int nFeatures = 0; - int id, val; - - int i; - - /* create a default engine so we can query the font for Graphite features; - because of font caching, it's cheap to discard this and create the real one later */ - engine = createGraphiteEngine(fontRef, font, faceName, rgbValue, rtl, languageTag, - extend, slant, embolden, 0, NULL, NULL); - if (engine == NULL) - return NULL; - - /* scan the feature string (if any) */ - if (cp1 != NULL) { - while (*cp1) { - if ((*cp1 == ':') || (*cp1 == ';') || (*cp1 == ',')) - ++cp1; - while ((*cp1 == ' ') || (*cp1 == '\t')) /* skip leading whitespace */ - ++cp1; - if (*cp1 == 0) /* break if end of string */ - break; - - cp2 = cp1; - while (*cp2 && (*cp2 != ':') && (*cp2 != ';') && (*cp2 != ',')) - ++cp2; - - if (strncmp(cp1, "language", 8) == 0) { - cp3 = cp1 + 8; - if (*cp3 != '=') - goto bad_option; - languageTag = read_tag(cp3 + 1, '\0'); - goto next_option; - } - - i = readCommonFeatures(cp1, cp2, &extend, &slant, &embolden, &letterspace, &rgbValue); - if (i == 1) - goto next_option; - else if (i == -1) - goto bad_option; - - if (readFeatureNumber(cp1, cp2, &id, &val) - || findGraphiteFeature(engine, cp1, cp2, &id, &val)) { - if (nFeatures < MAX_GRAPHITE_FEATURES) { - featureIDs[nFeatures] = id; - featureValues[nFeatures] = val; - ++nFeatures; - } - goto next_option; - } - - if (strncmp(cp1, "rtl", 3) == 0) { - cp3 = cp2; - if (*cp3 == ';' || *cp3 == ':') - --cp3; - while (*cp3 == '\0' || *cp3 == ' ' || *cp3 == '\t') - --cp3; - if (*cp3) - ++cp3; - if (cp3 == cp1 + 3) { - rtl = 1; - goto next_option; - } - } - -/* - if (strncmp(cp1, "vertical", 8) == 0) { - cp3 = cp2; - if (*cp3 == ';' || *cp3 == ':') - --cp3; - while (*cp3 == '\0' || *cp3 == ' ' || *cp3 == '\t') - --cp3; - if (*cp3) - ++cp3; - if (cp3 == cp1 + 8) { - loadedfontflags |= FONT_FLAGS_VERTICAL; - goto next_option; - } - } -*/ - - bad_option: - fontfeaturewarning(cp1, cp2 - cp1, 0, 0); - - next_option: - cp1 = cp2; - } - - } - - if (embolden != 0.0) - embolden = embolden * Fix2X(scaled_size) / 100.0; - - if (letterspace != 0.0) - loadedfontletterspace = (letterspace / 100.0) * scaled_size; - - if ((loadedfontflags & FONT_FLAGS_COLORED) == 0) - rgbValue = 0x000000FF; - - if ((loadedfontflags & FONT_FLAGS_VERTICAL) != 0) - setFontLayoutDir(font, 1); - -// deleteLayoutEngine(engine); - engine = createGraphiteEngine(fontRef, font, faceName, rgbValue, rtl, languageTag, - extend, slant, embolden, nFeatures, &featureIDs[0], &featureValues[0]); - if (engine != NULL) - nativefonttypeflag = OTGR_FONT_FLAG; - - return engine; -} - -#endif /* XETEX_GRAPHITE */ - static void splitFontName(char* name, char** var, char** feat, char** end, int* index) { @@ -1292,7 +1181,7 @@ findnativefont(unsigned char* uname, integer scaled_size) if (scaled_size < 0) { font = createFontFromFile(path, index, 655360L); if (font != NULL) { - Fixed dsize = X2Fix(getDesignSize(font)); + Fixed dsize = D2Fix(getDesignSize(font)); if (scaled_size == -1000) scaled_size = dsize; else @@ -1302,16 +1191,14 @@ findnativefont(unsigned char* uname, integer scaled_size) } font = createFontFromFile(path, index, scaled_size); if (font != NULL) { - loadedfontdesignsize = X2Fix(getDesignSize(font)); -#if XETEX_GRAPHITE - if (varString && strncmp(varString, "/GR", 3) == 0) { - rval = loadGraphiteFont(0, font, scaled_size, featString, nameString); - if (rval == NULL) - graphitewarning(); - } -#endif - if (rval == NULL) /* graphite wasn't requested, or failed to initialize */ - rval = loadOTfont(0, font, scaled_size, featString); + loadedfontdesignsize = D2Fix(getDesignSize(font)); + + if (varString && strncmp(varString, "/GR", 3) == 0) + setReqEngine('G'); + else + setReqEngine(0); + + rval = loadOTfont(0, font, scaled_size, featString); if (rval == NULL) deleteFont(font); if (rval != NULL && gettracingfontsstate() > 0) { @@ -1325,7 +1212,7 @@ findnativefont(unsigned char* uname, integer scaled_size) } } else { - fontRef = findFontByName(nameString, varString, Fix2X(scaled_size)); + fontRef = findFontByName(nameString, varString, Fix2D(scaled_size)); if (fontRef != 0) { /* update nameoffile to the full name of the font, for error messages during font loading */ @@ -1343,7 +1230,7 @@ findnativefont(unsigned char* uname, integer scaled_size) if (scaled_size < 0) { font = createFont(fontRef, scaled_size); if (font != NULL) { - Fixed dsize = X2Fix(getDesignSize(font)); + Fixed dsize = D2Fix(getDesignSize(font)); if (scaled_size == -1000) scaled_size = dsize; else @@ -1360,20 +1247,11 @@ findnativefont(unsigned char* uname, integer scaled_size) font = createFont(fontRef, scaled_size); if (font != 0) { -#ifdef XETEX_GRAPHITE - if (getReqEngine() == 'G') { - rval = loadGraphiteFont(fontRef, font, scaled_size, featString, nameString); - if (rval == NULL) - graphitewarning(); - } -#endif - if (rval == NULL) { #ifdef XETEX_MAC - if (getReqEngine() == 'I' || getReqEngine() == 'G' || - getFontTablePtr(font, kGSUB) != NULL || getFontTablePtr(font, kGPOS) != NULL) + if (getReqEngine() == 'O' || getReqEngine() == 'G' || + getFontTablePtr(font, kGSUB) != NULL || getFontTablePtr(font, kGPOS) != NULL) #endif - rval = loadOTfont(fontRef, font, scaled_size, featString); - } + rval = loadOTfont(fontRef, font, scaled_size, featString); if (rval == NULL) deleteFont(font); } @@ -1431,16 +1309,16 @@ otgetfontmetrics(void* pEngine, scaled* ascent, scaled* descent, scaled* xheight int glyphID; getAscentAndDescent(engine, &a, &d); - *ascent = X2Fix(a); - *descent = X2Fix(d); + *ascent = D2Fix(a); + *descent = D2Fix(d); - *slant = X2Fix(Fix2X(getSlant(getFont(engine))) * getExtendFactor(engine) + *slant = D2Fix(Fix2D(getSlant(getFont(engine))) * getExtendFactor(engine) + getSlantFactor(engine)); glyphID = mapCharToGlyph(engine, 'x'); if (glyphID != 0) { getGlyphHeightDepth(engine, glyphID, &a, &d); - *xheight = X2Fix(a); + *xheight = D2Fix(a); } else *xheight = *ascent / 2; /* arbitrary figure if there's no 'x' in the font */ @@ -1448,7 +1326,7 @@ otgetfontmetrics(void* pEngine, scaled* ascent, scaled* descent, scaled* xheight glyphID = mapCharToGlyph(engine, 'X'); if (glyphID != 0) { getGlyphHeightDepth(engine, glyphID, &a, &d); - *capheight = X2Fix(a); + *capheight = D2Fix(a); } else *capheight = *ascent; /* arbitrary figure if there's no 'X' in the font */ @@ -1464,11 +1342,9 @@ otfontget(integer what, void* pEngine) return countGlyphs(fontInst); break; -#ifdef XETEX_GRAPHITE case XeTeX_count_features: /* ie Graphite features */ return countGraphiteFeatures(engine); break; -#endif case XeTeX_OT_count_scripts: return countScripts(fontInst); @@ -1492,7 +1368,6 @@ otfontget1(integer what, void* pEngine, integer param) return getIndScript(fontInst, param); break; -#ifdef XETEX_GRAPHITE /* for graphite fonts...*/ case XeTeX_feature_code: return getGraphiteFeatureCode(engine, param); @@ -1503,7 +1378,6 @@ otfontget1(integer what, void* pEngine, integer param) case XeTeX_count_selectors: return countGraphiteFeatureSettings(engine, param); break; -#endif } return 0; } @@ -1523,15 +1397,13 @@ otfontget2(integer what, void* pEngine, integer param1, integer param2) return countFeatures(fontInst, param1, param2); break; -#ifdef XETEX_GRAPHITE /* for graphite fonts */ case XeTeX_selector_code: return getGraphiteFeatureSettingCode(engine, param1, param2); break; case XeTeX_is_default_selector: - return getGraphiteFeatureDefaultSetting(engine, param1) == param2; + return getGraphiteFeatureSettingCode(engine, param1, 1) == param2; break; -#endif } return 0; @@ -1555,9 +1427,8 @@ otfontget3(integer what, void* pEngine, integer param1, integer param2, integer void grprintfontname(integer what, void* pEngine, integer param1, integer param2) { -#ifdef XETEX_GRAPHITE - unsigned short name[128]; /* graphite API specifies size 128 */ - int n = 0; + char name[128]; + int n = 0; XeTeXLayoutEngine engine = (XeTeXLayoutEngine)pEngine; switch (what) { case XeTeX_feature_name: @@ -1567,24 +1438,21 @@ grprintfontname(integer what, void* pEngine, integer param1, integer param2) getGraphiteFeatureSettingLabel(engine, param1, param2, &name[0]); break; } - while (name[n] != 0 && n < 128) + while (name[n] != '\0') ++n; - printchars(&name[0], n); -#endif + printchars((unsigned short*) &name[0], n); } integer grfontgetnamed(integer what, void* pEngine) { long rval = -1; -#ifdef XETEX_GRAPHITE XeTeXLayoutEngine engine = (XeTeXLayoutEngine)pEngine; switch (what) { case XeTeX_find_feature_by_name: rval = findGraphiteFeatureNamed(engine, (const char*)nameoffile + 1, namelength); break; } -#endif return rval; } @@ -1592,14 +1460,12 @@ integer grfontgetnamed1(integer what, void* pEngine, integer param) { long rval = -1; -#ifdef XETEX_GRAPHITE XeTeXLayoutEngine engine = (XeTeXLayoutEngine)pEngine; switch (what) { case XeTeX_find_selector_by_name: rval = findGraphiteFeatureSettingNamed(engine, param, (const char*)nameoffile + 1, namelength); break; } -#endif return rval; } @@ -1777,10 +1643,10 @@ makefontdef(integer f) slant = getSlantFactor(engine); embolden = getEmboldenFactor(engine); - size = X2Fix(getPointSize(engine)); + size = D2Fix(getPointSize(engine)); } else { - fprintf(stderr, "\n! Internal error: bad native font flag\n"); + fprintf(stderr, "\n! Internal error: bad native font flag in `make_font_def'\n"); exit(3); } @@ -1889,17 +1755,17 @@ makefontdef(integer f) #endif if (flags & XDV_FLAG_EXTEND) { - Fixed f = X2Fix(extend); + Fixed f = D2Fix(extend); *(UInt32*)(cp) = SWAP32(f); cp += 4; } if (flags & XDV_FLAG_SLANT) { - Fixed f = X2Fix(slant); + Fixed f = D2Fix(slant); *(UInt32*)(cp) = SWAP32(f); cp += 4; } if (flags & XDV_FLAG_EMBOLDEN) { - Fixed f = X2Fix(embolden); + Fixed f = D2Fix(embolden); *(UInt32*)(cp) = SWAP32(f); cp += 4; } @@ -1978,12 +1844,12 @@ getnativecharheightdepth(integer font, integer ch, scaled* height, scaled* depth getGlyphHeightDepth(engine, gid, &ht, &dp); } else { - fprintf(stderr, "\n! Internal error: bad native font flag\n"); + fprintf(stderr, "\n! Internal error: bad native font flag in `get_native_char_height_depth`\n"); exit(3); } - *height = X2Fix(ht); - *depth = X2Fix(dp); + *height = D2Fix(ht); + *depth = D2Fix(dp); /* snap to "known" zones for baseline, x-height, cap-height if within 4% of em-size */ fuzz = QUAD(font) / 25; @@ -2028,12 +1894,12 @@ getnativecharsidebearings(integer font, integer ch, scaled* lsb, scaled* rsb) getGlyphSidebearings(engine, gid, &l, &r); } else { - fprintf(stderr, "\n! Internal error: bad native font flag\n"); + fprintf(stderr, "\n! Internal error: bad native font flag in `get_native_char_side_bearings'\n"); exit(3); } - *lsb = X2Fix(l); - *rsb = X2Fix(r); + *lsb = D2Fix(l); + *rsb = D2Fix(r); } scaled @@ -2060,10 +1926,10 @@ getglyphbounds(integer font, integer edge, integer gid) getGlyphHeightDepth(engine, gid, &a, &b); } else { - fprintf(stderr, "\n! Internal error: bad native font flag\n"); + fprintf(stderr, "\n! Internal error: bad native font flag in `get_glyph_bounds'\n"); exit(3); } - return X2Fix((edge <= 2) ? a : b); + return D2Fix((edge <= 2) ? a : b); } scaled @@ -2085,24 +1951,24 @@ getnativecharwd(integer f, integer c) if (fontarea[f] == AAT_FONT_FLAG) { ATSUStyle style = (ATSUStyle)(fontlayoutengine[f]); int gid = MapCharToGlyph_AAT(style, c); - wd = X2Fix(GetGlyphWidth_AAT(style, gid)); + wd = D2Fix(GetGlyphWidth_AAT(style, gid)); } else #endif if (fontarea[f] == OTGR_FONT_FLAG) { XeTeXLayoutEngine engine = (XeTeXLayoutEngine)fontlayoutengine[f]; int gid = mapCharToGlyph(engine, c); - wd = X2Fix(getGlyphWidthFromEngine(engine, gid)); + wd = D2Fix(getGlyphWidthFromEngine(engine, gid)); } else { - fprintf(stderr, "\n! Internal error: bad native font flag\n"); + fprintf(stderr, "\n! Internal error: bad native font flag in `get_native_char_wd'\n"); exit(3); } return wd; } UInt16 -get_native_glyph_id(void* pNode, unsigned index) +get_native_glyph(void* pNode, unsigned index) { memoryword* node = (memoryword*)pNode; FixedPoint* locations = (FixedPoint*)native_glyph_info_ptr(node); @@ -2138,179 +2004,113 @@ measure_native_node(void* pNode, int use_glyph_metrics) else #endif if (fontarea[f] == OTGR_FONT_FLAG) { + /* using this font in OT Layout mode, so fontlayoutengine[f] is actually a XeTeXLayoutEngine */ + XeTeXLayoutEngine engine = (XeTeXLayoutEngine)(fontlayoutengine[f]); FixedPoint* locations; UInt16* glyphIDs; int realGlyphCount = 0; - if (usingOpenType(engine)) { - /* using this font in OT Layout mode, so fontlayoutengine[f] is actually a XeTeXLayoutEngine */ - - /* need to find direction runs within the text, and call layoutChars separately for each */ - - int nGlyphs; - UBiDiDirection dir; - float x, y; - void* glyph_info = 0; - static float* positions = 0; - static UInt32* glyphs = 0; - static int maxGlyphs = 0; - - UBiDi* pBiDi = ubidi_open(); - - UErrorCode errorCode = (UErrorCode)0; - ubidi_setPara(pBiDi, txtPtr, txtLen, getDefaultDirection(engine), NULL, &errorCode); + /* need to find direction runs within the text, and call layoutChars separately for each */ + + UBiDiDirection dir; + float x, y; + void* glyph_info = 0; + static float* positions = 0; + static UInt32* glyphs = 0; + + UBiDi* pBiDi = ubidi_open(); + + UErrorCode errorCode = (UErrorCode)0; + ubidi_setPara(pBiDi, txtPtr, txtLen, getDefaultDirection(engine), NULL, &errorCode); + + dir = ubidi_getDirection(pBiDi); + if (dir == UBIDI_MIXED) { + /* we actually do the layout twice here, once to count glyphs and then again to get them; + which is inefficient, but i figure that MIXED is a relatively rare occurrence, so i can't be + bothered to deal with the memory reallocation headache of doing it differently + */ + int nRuns = ubidi_countRuns(pBiDi, &errorCode); + double wid = 0; + int i, runIndex; + int32_t logicalStart, length; + for (runIndex = 0; runIndex < nRuns; ++runIndex) { + dir = ubidi_getVisualRun(pBiDi, runIndex, &logicalStart, &length); + realGlyphCount += layoutChars(engine, (UniChar*)txtPtr, logicalStart, length, txtLen, (dir == UBIDI_RTL)); + } - dir = ubidi_getDirection(pBiDi); - if (dir == UBIDI_MIXED) { - /* we actually do the layout twice here, once to count glyphs and then again to get them; - // which is inefficient, but i figure that MIXED is a relatively rare occurrence, so i can't be - // bothered to deal with the memory reallocation headache of doing it differently - */ - int nRuns = ubidi_countRuns(pBiDi, &errorCode); - double wid = 0; - long totalGlyphs = 0; - int i, runIndex; - int32_t logicalStart, length; - OSStatus status = 0; + if (realGlyphCount > 0) { + double x, y; + glyph_info = xmalloc(realGlyphCount * native_glyph_info_size); + locations = (FixedPoint*)glyph_info; + glyphIDs = (UInt16*)(locations + realGlyphCount); + realGlyphCount = 0; + + x = y = 0.0; for (runIndex = 0; runIndex < nRuns; ++runIndex) { + int nGlyphs; dir = ubidi_getVisualRun(pBiDi, runIndex, &logicalStart, &length); - nGlyphs = layoutChars(engine, (UniChar*)txtPtr, logicalStart, length, txtLen, (dir == UBIDI_RTL), 0.0, 0.0, &status); - totalGlyphs += nGlyphs; - - if (nGlyphs >= maxGlyphs) { - if (glyphs != 0) { - free(glyphs); - free(positions); - } - maxGlyphs = nGlyphs + 20; - glyphs = xmalloc(maxGlyphs * sizeof(UInt32)); - positions = xmalloc((maxGlyphs * 2 + 2) * sizeof(float)); - } - - getGlyphs(engine, glyphs, &status); - for (i = 0; i < nGlyphs; ++i) - if (glyphs[i] < 0xfffe) - ++realGlyphCount; - } - - if (realGlyphCount > 0) { - double x, y; - glyph_info = xmalloc(realGlyphCount * native_glyph_info_size); - locations = (FixedPoint*)glyph_info; - glyphIDs = (UInt16*)(locations + realGlyphCount); - realGlyphCount = 0; - - x = y = 0.0; - for (runIndex = 0; runIndex < nRuns; ++runIndex) { - dir = ubidi_getVisualRun(pBiDi, runIndex, &logicalStart, &length); - nGlyphs = layoutChars(engine, (UniChar*)txtPtr, logicalStart, length, txtLen, - (dir == UBIDI_RTL), 0, 0, &status); - - getGlyphs(engine, glyphs, &status); - getGlyphPositions(engine, positions, &status); - - for (i = 0; i < nGlyphs; ++i) { - if (glyphs[i] < 0xfffe) { - glyphIDs[realGlyphCount] = glyphs[i]; - locations[realGlyphCount].x = X2Fix(positions[2*i] + x); - locations[realGlyphCount].y = X2Fix(positions[2*i+1] + y); - ++realGlyphCount; - } - } - x += positions[2*i]; - y += positions[2*i+1]; - } - wid = x; - } - - node_width(node) = X2Fix(wid); - native_glyph_count(node) = realGlyphCount; - native_glyph_info_ptr(node) = glyph_info; - } - else { - int i; - OSStatus status = 0; - float maxRhs = 0.0; - nGlyphs = layoutChars(engine, (UniChar*)txtPtr, 0, txtLen, txtLen, (dir == UBIDI_RTL), 0.0, 0.0, &status); -/* NO -- this is not valid in some Indic split-vowel situations - see http://sourceforge.net/tracker/index.php?func=detail&aid=1951292&group_id=194926&atid=951385 */ -#if 0 - getGlyphPosition(engine, nGlyphs, &x, &y, &status); - node_width(node) = X2Fix(x); -#endif + nGlyphs = layoutChars(engine, (UniChar*)txtPtr, logicalStart, length, txtLen, + (dir == UBIDI_RTL)); - if (nGlyphs >= maxGlyphs) { - if (glyphs != 0) { - free(glyphs); - free(positions); - } - maxGlyphs = nGlyphs + 20; - glyphs = xmalloc(maxGlyphs * sizeof(UInt32)); - positions = xmalloc((maxGlyphs * 2 + 2) * sizeof(float)); - } - getGlyphs(engine, glyphs, &status); - getGlyphPositions(engine, positions, &status); + glyphs = xmalloc(nGlyphs * sizeof(UInt32)); + positions = xmalloc((nGlyphs * 2 + 2) * sizeof(float)); - for (i = 0; i < nGlyphs; ++i) - if (glyphs[i] < 0xfffe) - ++realGlyphCount; - - if (realGlyphCount > 0) { - glyph_info = xmalloc(realGlyphCount * native_glyph_info_size); - locations = (FixedPoint*)glyph_info; - glyphIDs = (UInt16*)(locations + realGlyphCount); - realGlyphCount = 0; + getGlyphs(engine, glyphs); + getGlyphPositions(engine, positions); + for (i = 0; i < nGlyphs; ++i) { - if (glyphs[i] < 0xfffe) { - float rhs = positions[2*i] + getGlyphWidthFromEngine(engine, glyphs[i]); - if (rhs > maxRhs) - maxRhs = rhs; - glyphIDs[realGlyphCount] = glyphs[i]; - locations[realGlyphCount].x = X2Fix(positions[2*i]); - locations[realGlyphCount].y = X2Fix(positions[2*i+1]); - ++realGlyphCount; - } + glyphIDs[realGlyphCount] = glyphs[i]; + locations[realGlyphCount].x = D2Fix(positions[2*i] + x); + locations[realGlyphCount].y = D2Fix(positions[2*i+1] + y); + ++realGlyphCount; } - } + x += positions[2*i]; + y += positions[2*i+1]; - node_width(node) = X2Fix(maxRhs); - native_glyph_count(node) = realGlyphCount; - native_glyph_info_ptr(node) = glyph_info; + free(glyphs); + free(positions); + } + wid = x; } - - ubidi_close(pBiDi); - + + node_width(node) = D2Fix(wid); + native_glyph_count(node) = realGlyphCount; + native_glyph_info_ptr(node) = glyph_info; } - else { - /* using Graphite */ - void* glyph_info = NULL; -#ifdef XETEX_GRAPHITE - realGlyphCount = makeGraphiteSegment(engine, (UniChar*)txtPtr, txtLen); - + else { + int i; + realGlyphCount = layoutChars(engine, (UniChar*)txtPtr, 0, txtLen, txtLen, (dir == UBIDI_RTL)); + + glyphs = xmalloc(realGlyphCount * sizeof(UInt32)); + positions = xmalloc((realGlyphCount * 2 + 2) * sizeof(float)); + + getGlyphs(engine, glyphs); + getGlyphPositions(engine, positions); + if (realGlyphCount > 0) { - int i; glyph_info = xmalloc(realGlyphCount * native_glyph_info_size); locations = (FixedPoint*)glyph_info; glyphIDs = (UInt16*)(locations + realGlyphCount); for (i = 0; i < realGlyphCount; ++i) { - float x, y; - getGraphiteGlyphInfo(engine, i, &(glyphIDs[i]), &x, &y); - locations[i].x = X2Fix(x); - locations[i].y = X2Fix(y); + glyphIDs[i] = glyphs[i]; + locations[i].x = D2Fix(positions[2*i]); + locations[i].y = D2Fix(positions[2*i+1]); } } - - node_width(node) = X2Fix(graphiteSegmentWidth(engine)); -#else - node_width(node) = 0; -#endif + node_width(node) = D2Fix(positions[2*i]); native_glyph_count(node) = realGlyphCount; native_glyph_info_ptr(node) = glyph_info; + + free(glyphs); + free(positions); } + ubidi_close(pBiDi); + + if (fontletterspace[f] != 0) { Fixed lsDelta = 0; Fixed lsUnit = fontletterspace[f]; @@ -2328,7 +2128,7 @@ measure_native_node(void* pNode, int use_glyph_metrics) } } else { - fprintf(stderr, "\n! Internal error: bad native font flag\n"); + fprintf(stderr, "\n! Internal error: bad native font flag in `measure_native_node'\n"); exit(3); } @@ -2348,7 +2148,7 @@ measure_native_node(void* pNode, int use_glyph_metrics) int i; for (i = 0; i < native_glyph_count(node); ++i) { float ht, dp; - float y = Fix2X(-locations[i].y); /* NB negative is upwards in locations[].y! */ + float y = Fix2D(-locations[i].y); /* NB negative is upwards in locations[].y! */ GlyphBBox bbox; if (getCachedGlyphBBox(f, glyphIDs[i], &bbox) == 0) { @@ -2371,13 +2171,13 @@ measure_native_node(void* pNode, int use_glyph_metrics) if (y - dp < yMin) yMin = y - dp; } - node_height(node) = X2Fix(yMax); - node_depth(node) = -X2Fix(yMin); + node_height(node) = D2Fix(yMax); + node_depth(node) = -D2Fix(yMin); } } Fixed -get_native_ital_corr(void* pNode) +get_native_italic_correction(void* pNode) { memoryword* node = pNode; unsigned f = native_font(node); @@ -2388,11 +2188,11 @@ get_native_ital_corr(void* pNode) #ifdef XETEX_MAC if (fontarea[f] == AAT_FONT_FLAG) - return X2Fix(GetGlyphItalCorr_AAT((ATSUStyle)(fontlayoutengine[f]), glyphIDs[n-1])) + return D2Fix(GetGlyphItalCorr_AAT((ATSUStyle)(fontlayoutengine[f]), glyphIDs[n-1])) + fontletterspace[f]; #endif if (fontarea[f] == OTGR_FONT_FLAG) - return X2Fix(getGlyphItalCorr((XeTeXLayoutEngine)(fontlayoutengine[f]), glyphIDs[n-1])) + return D2Fix(getGlyphItalCorr((XeTeXLayoutEngine)(fontlayoutengine[f]), glyphIDs[n-1])) + fontletterspace[f]; } @@ -2401,7 +2201,7 @@ get_native_ital_corr(void* pNode) Fixed -get_native_glyph_ital_corr(void* pNode) +get_native_glyph_italic_correction(void* pNode) { memoryword* node = pNode; UInt16 gid = native_glyph(node); @@ -2409,10 +2209,10 @@ get_native_glyph_ital_corr(void* pNode) #ifdef XETEX_MAC if (fontarea[f] == AAT_FONT_FLAG) - return X2Fix(GetGlyphItalCorr_AAT((ATSUStyle)(fontlayoutengine[f]), gid)); + return D2Fix(GetGlyphItalCorr_AAT((ATSUStyle)(fontlayoutengine[f]), gid)); #endif if (fontarea[f] == OTGR_FONT_FLAG) - return X2Fix(getGlyphItalCorr((XeTeXLayoutEngine)(fontlayoutengine[f]), gid)); + return D2Fix(getGlyphItalCorr((XeTeXLayoutEngine)(fontlayoutengine[f]), gid)); return 0; /* can't actually happen */ } @@ -2434,7 +2234,7 @@ measure_native_glyph(void* pNode, int use_glyph_metrics) OSStatus status = ATSUGlyphGetIdealMetrics(style, 1, &gid, 0, &metrics); /* returns values in Quartz points, so we need to convert to TeX points */ if (status == noErr) { - node_width(node) = X2Fix(metrics.advance.x * 72.27 / 72.0); + node_width(node) = D2Fix(metrics.advance.x * 72.27 / 72.0); if (use_glyph_metrics) GetGlyphHeightDepth_AAT(style, gid, &ht, &dp); } @@ -2444,18 +2244,18 @@ measure_native_glyph(void* pNode, int use_glyph_metrics) if (fontarea[f] == OTGR_FONT_FLAG) { XeTeXLayoutEngine engine = (XeTeXLayoutEngine)fontlayoutengine[f]; XeTeXFont fontInst = getFont(engine); - node_width(node) = X2Fix(getGlyphWidth(fontInst, gid)); + node_width(node) = D2Fix(getGlyphWidth(fontInst, gid)); if (use_glyph_metrics) getGlyphHeightDepth(engine, gid, &ht, &dp); } else { - fprintf(stderr, "\n! Internal error: bad native font flag\n"); + fprintf(stderr, "\n! Internal error: bad native font flag in `measure_native_glyph'\n"); exit(3); } if (use_glyph_metrics) { - node_height(node) = X2Fix(ht); - node_depth(node) = X2Fix(dp); + node_height(node) = D2Fix(ht); + node_depth(node) = D2Fix(dp); } else { node_height(node) = heightbase[f]; @@ -2476,7 +2276,7 @@ mapchartoglyph(integer font, integer ch) if (fontarea[font] == OTGR_FONT_FLAG) return mapCharToGlyph((XeTeXLayoutEngine)(fontlayoutengine[font]), ch); else { - fprintf(stderr, "\n! Internal error: bad native font flag\n"); + fprintf(stderr, "\n! Internal error: bad native font flag in `map_char_to_glyph'\n"); exit(3); } } @@ -2493,7 +2293,7 @@ mapglyphtoindex(integer font) if (fontarea[font] == OTGR_FONT_FLAG) return mapGlyphToIndex((XeTeXLayoutEngine)(fontlayoutengine[font]), (const char*)nameoffile + 1); else { - fprintf(stderr, "\n! Internal error: bad native font flag\n"); + fprintf(stderr, "\n! Internal error: bad native font flag in `map_glyph_to_index'\n"); exit(3); } } @@ -2509,24 +2309,22 @@ getfontcharrange(integer font, int first) if (fontarea[font] == OTGR_FONT_FLAG) return getFontCharRange((XeTeXLayoutEngine)(fontlayoutengine[font]), first); else { - fprintf(stderr, "\n! Internal error: bad native font flag\n"); + fprintf(stderr, "\n! Internal error: bad native font flag in `get_font_char_range'\n"); exit(3); } } -#ifndef XETEX_MAC -Fixed X2Fix(double d) +Fixed D2Fix(double d) { Fixed rval = (int)(d * 65536.0 + 0.5); return rval; } -double Fix2X(Fixed f) +double Fix2D(Fixed f) { double rval = f / 65536.0; return rval; } -#endif /* these are here, not XeTeX_mac.c, because we need stubs on other platforms */ void @@ -2547,29 +2345,29 @@ atsugetfontmetrics(ATSUStyle style, integer* ascent, integer* descent, integer* if (status != noErr) return; /* size from the ATSUStyle is in Quartz points; convert to TeX points here */ - double floatSize = Fix2X(size) * 72.27 / 72.0; + double floatSize = Fix2D(size) * 72.27 / 72.0; ATSFontMetrics metrics; status = ATSFontGetHorizontalMetrics(fontRef, kATSOptionFlagsDefault, &metrics); if (status != noErr) return; - *ascent = X2Fix(metrics.ascent * floatSize); - *descent = X2Fix(metrics.descent * floatSize); + *ascent = D2Fix(metrics.ascent * floatSize); + *descent = D2Fix(metrics.descent * floatSize); if (metrics.italicAngle != 0.0) { if (fabs(metrics.italicAngle) < 0.090) metrics.italicAngle *= 1000.0; /* hack around apparent ATS bug */ - *slant = X2Fix(tan(-metrics.italicAngle * M_PI / 180.0)); + *slant = D2Fix(tan(-metrics.italicAngle * M_PI / 180.0)); } else { /* try to get a (possibly synthetic) POST table, as ATSFontGetHorizontalMetrics doesn't seem to return this value for OT/CFF fonts */ ByteCount tableSize; - if (ATSFontGetTable(fontRef, LE_POST_TABLE_TAG, 0, 0, 0, &tableSize) == noErr) { + if (ATSFontGetTable(fontRef, kPOST, 0, 0, 0, &tableSize) == noErr) { POSTTable* post = xmalloc(tableSize); - ATSFontGetTable(fontRef, LE_POST_TABLE_TAG, 0, tableSize, post, 0); - *slant = X2Fix(tan(Fix2X( - SWAP32(post->italicAngle)) * M_PI / 180.0)); + ATSFontGetTable(fontRef, kPOST, 0, tableSize, post, 0); + *slant = D2Fix(tan(Fix2D( - SWAP32(post->italicAngle)) * M_PI / 180.0)); free(post); } } @@ -2577,21 +2375,21 @@ atsugetfontmetrics(ATSUStyle style, integer* ascent, integer* descent, integer* CGAffineTransform t; ATSUGetAttribute(style, kATSUFontMatrixTag, sizeof(CGAffineTransform), &t, 0); if (t.a != 1.0) - *slant = X2Fix(Fix2X(*slant) * t.a); + *slant = D2Fix(Fix2D(*slant) * t.a); if (t.b != 0.0) - *slant += X2Fix(t.b); + *slant += D2Fix(t.b); if (0 && metrics.xHeight != 0.0) { /* currently not using this, as the values from ATS don't seem quite what I'd expect */ - *xheight = X2Fix(metrics.xHeight * floatSize); - *capheight = X2Fix(metrics.capHeight * floatSize); + *xheight = D2Fix(metrics.xHeight * floatSize); + *capheight = D2Fix(metrics.capHeight * floatSize); } else { int glyphID = MapCharToGlyph_AAT(style, 'x'); float ht, dp; if (glyphID != 0) { GetGlyphHeightDepth_AAT(style, glyphID, &ht, &dp); - *xheight = X2Fix(ht); + *xheight = D2Fix(ht); } else *xheight = *ascent / 2; /* arbitrary figure if there's no 'x' in the font */ @@ -2599,7 +2397,7 @@ atsugetfontmetrics(ATSUStyle style, integer* ascent, integer* descent, integer* glyphID = MapCharToGlyph_AAT(style, 'X'); if (glyphID != 0) { GetGlyphHeightDepth_AAT(style, glyphID, &ht, &dp); - *capheight = X2Fix(ht); + *capheight = D2Fix(ht); } else *capheight = *ascent; /* arbitrary figure if there's no 'X' in the font */ @@ -2622,9 +2420,9 @@ atsufontget(int what, ATSUStyle style) { ByteCount tableSize; ATSFontRef fontRef = FMGetATSFontRefFromFont(fontID); - if (ATSFontGetTable(fontRef, LE_MAXP_TABLE_TAG, 0, 0, 0, &tableSize) == noErr) { + if (ATSFontGetTable(fontRef, kMAXP, 0, 0, 0, &tableSize) == noErr) { MAXPTable* table = xmalloc(tableSize); - ATSFontGetTable(fontRef, LE_MAXP_TABLE_TAG, 0, tableSize, table, 0); + ATSFontGetTable(fontRef, kMAXP, 0, tableSize, table, 0); rval = SWAP16(table->numGlyphs); free(table); } @@ -2915,7 +2713,7 @@ printglyphname(integer font, integer gid) s = (char*)getGlyphName(getFont(engine), gid, &len); } else { - fprintf(stderr, "\n! Internal error: bad native font flag\n"); + fprintf(stderr, "\n! Internal error: bad native font flag in `print_glyph_name'\n"); exit(3); } while (len-- > 0) diff --git a/Build/source/texk/web2c/xetexdir/XeTeX_ext.h b/Build/source/texk/web2c/xetexdir/XeTeX_ext.h index 49eeeb5ec04..7e9fa1390cf 100644 --- a/Build/source/texk/web2c/xetexdir/XeTeX_ext.h +++ b/Build/source/texk/web2c/xetexdir/XeTeX_ext.h @@ -1,9 +1,9 @@ /****************************************************************************\ Part of the XeTeX typesetting system - copyright (c) 1994-2008 by SIL International - copyright (c) 2009, 2011 by Jonathan Kew + Copyright (c) 1994-2008 by SIL International + Copyright (c) 2009, 2011 by Jonathan Kew - Written by Jonathan Kew + SIL Author(s): Jonathan Kew Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -33,6 +33,7 @@ authorization from the copyright holders. #ifndef __XETEXEXT_H #define __XETEXEXT_H +#include #include /* needed for SIZEOF_LONG and NO_DUMP_SHARE */ /***** copied from TeX/texk/web2c/config.h -- difficult to include in C++ source files ******/ #ifndef INTEGER_TYPE @@ -95,6 +96,9 @@ typedef struct { } FixedPoint; #endif +typedef uint32_t OTTag; +typedef uint16_t GlyphID; + /* these are also in xetex-new.ch and must correspond! */ @@ -159,15 +163,17 @@ typedef struct { #define XDV_GLYPH_ARRAY 253 /* OT-related constants we need */ -#define kGSUB 0x47535542 -#define kGPOS 0x47504f53 - -#define kLatin 0x6c61746e -#define kSyriac 0x73797263 -#define kArabic 0x61726162 -#define kThaana 0x74686161 -#define kHebrew 0x68656272 - +#define kGSUB HB_TAG('G','S','U','B') +#define kGPOS HB_TAG('G','P','O','S') +#define kMATH HB_TAG('M','A','T','H') +#define kHEAD HB_TAG('h','e','a','d') +#define kHHEA HB_TAG('h','h','e','a') +#define kVHEA HB_TAG('v','h','e','a') +#define kPOST HB_TAG('p','o','s','t') +#define kHMTX HB_TAG('h','m','t','x') +#define kVMTX HB_TAG('v','m','t','x') +#define kMAXP HB_TAG('m','a','x','p') +#define kOS_2 HB_TAG('O','S','/','2') struct postTable { Fixed format; @@ -182,9 +188,6 @@ struct postTable { UInt32 maxMemType1; }; -#define kPost 0x706f7374 -#define kCmap 0x636d6170 - typedef struct { float xMin; @@ -237,7 +240,7 @@ extern "C" { void setinputfileencoding(unicodefile f, integer mode, integer encodingData); void uclose(unicodefile f); - void linebreakstart(integer localeStrNum, const UniChar* text, integer textLength); + void linebreakstart(int f, integer localeStrNum, const UniChar* text, integer textLength); int linebreaknext(); int getencodingmodeandinfo(integer* info); void printutf8str(const unsigned char* str, int len); @@ -269,14 +272,14 @@ extern "C" { int applymapping(void* cnv, const UniChar* txtPtr, int txtLen); void store_justified_native_glyphs(void* node); void measure_native_node(void* node, int use_glyph_metrics); - Fixed get_native_ital_corr(void* node); - Fixed get_native_glyph_ital_corr(void* node); + Fixed get_native_italic_correction(void* node); + Fixed get_native_glyph_italic_correection(void* node); void measure_native_glyph(void* node, int use_glyph_metrics); integer mapchartoglyph(integer font, integer ch); integer mapglyphtoindex(integer font); integer getfontcharrange(integer font, int first); void printglyphname(integer font, integer gid); - UInt16 get_native_glyph_id(void* pNode, unsigned index); + UInt16 get_native_glyph(void* pNode, unsigned index); void grprintfontname(integer what, void* pEngine, integer param1, integer param2); integer grfontgetnamed(integer what, void* pEngine); @@ -348,17 +351,14 @@ typedef void* ATSUStyle; /* dummy declaration just so the stubs can compile */ }; #endif -/* some Mac OS X functions that we provide ourselves for other platforms */ -#ifndef XETEX_MAC #ifdef __cplusplus extern "C" { #endif - double Fix2X(Fixed f); - Fixed X2Fix(double d); + double Fix2D(Fixed f); + Fixed D2Fix(double d); #ifdef __cplusplus }; #endif -#endif // copied from xetex-hz.ch #define LEFT_SIDE 0 diff --git a/Build/source/texk/web2c/xetexdir/XeTeX_mac.c b/Build/source/texk/web2c/xetexdir/XeTeX_mac.c index 20b3a6dcbfc..bef5ef3c8ac 100644 --- a/Build/source/texk/web2c/xetexdir/XeTeX_mac.c +++ b/Build/source/texk/web2c/xetexdir/XeTeX_mac.c @@ -1,9 +1,9 @@ /****************************************************************************\ Part of the XeTeX typesetting system - copyright (c) 1994-2008 by SIL International - copyright (c) 2009 by Jonathan Kew + Copyright (c) 1994-2008 by SIL International + Copyright (c) 2009 by Jonathan Kew - Written by Jonathan Kew + SIL Author(s): Jonathan Kew Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -84,13 +84,13 @@ PStoTeXPoints(double pts) static inline Fixed FixedTeXtoPSPoints(Fixed pts) { - return X2Fix(TeXtoPSPoints(Fix2X(pts))); + return D2Fix(TeXtoPSPoints(Fix2D(pts))); } static inline Fixed FixedPStoTeXPoints(Fixed pts) { - return X2Fix(PStoTeXPoints(Fix2X(pts))); + return D2Fix(PStoTeXPoints(Fix2D(pts))); } void @@ -469,12 +469,12 @@ int MapGlyphToIndex_AAT(ATSUStyle style, const char* glyphName) ATSFontRef fontRef = FMGetATSFontRefFromFont(fontID); ByteCount length; - OSStatus status = ATSFontGetTable(fontRef, kPost, 0, 0, 0, &length); + OSStatus status = ATSFontGetTable(fontRef, kPOST, 0, 0, 0, &length); if (status != noErr) goto ats_failed; void* table = xmalloc(length); - status = ATSFontGetTable(fontRef, kPost, 0, length, table, &length); + status = ATSFontGetTable(fontRef, kPOST, 0, length, table, &length); if (status != noErr) { free(table); goto ats_failed; @@ -530,12 +530,12 @@ GetGlyphName_AAT(ATSUStyle style, UInt16 gid, int* len) ATSFontRef fontRef = FMGetATSFontRefFromFont(fontID); ByteCount length; - OSStatus status = ATSFontGetTable(fontRef, kPost, 0, 0, 0, &length); + OSStatus status = ATSFontGetTable(fontRef, kPOST, 0, 0, 0, &length); if (status != noErr) goto ats_failed; void* table = xmalloc(length); - status = ATSFontGetTable(fontRef, kPost, 0, length, table, &length); + status = ATSFontGetTable(fontRef, kPOST, 0, length, table, &length); if (status != noErr) { free(table); goto ats_failed; @@ -591,7 +591,6 @@ GetGlyphNameFromCGFont(ATSFontRef atsFontRef, UInt16 gid, int* len) return &buffer[0]; } -/* int GetFontCharRange_AAT(ATSUStyle style, int reqFirst) { @@ -608,7 +607,6 @@ GetFontCharRange_AAT(ATSUStyle style, int reqFirst) return ch; } } -*/ ATSUFontVariationAxis find_axis_by_name(ATSUFontID fontID, const char* name, int nameLength) @@ -862,7 +860,7 @@ loadAATfont(ATSFontRef fontRef, long scaled_size, const char* cp1) values = xrealloc(values, allocVars * sizeof(SInt32)); } axes[numVariations] = axis; - values[numVariations] = value * 65536.0; // X2Fix(value); + values[numVariations] = value * 65536.0; // D2Fix(value); ++numVariations; goto next_option; @@ -882,7 +880,7 @@ loadAATfont(ATSFontRef fontRef, long scaled_size, const char* cp1) goto bad_option; ++cp3; double val = read_double(&cp3); - tracking = X2Fix(val); + tracking = D2Fix(val); goto next_option; } @@ -948,7 +946,7 @@ loadAATfont(ATSFontRef fontRef, long scaled_size, const char* cp1) } if (embolden != 0.0) { - embolden = embolden * Fix2X(scaled_size) / 100.0; + embolden = embolden * Fix2D(scaled_size) / 100.0; tags[0] = kXeTeXEmboldenTag; sizes[0] = sizeof(float); attrs[0] = &embolden; @@ -1090,8 +1088,8 @@ find_pic_file(char** path, realrect* bounds, int pdfBoxType, int page) result = GraphicsImportGetImageDescription(ci, &desc); bounds->x = 0; bounds->y = 0; - bounds->wd = (*desc)->width * 72.27 / Fix2X((*desc)->hRes); - bounds->ht = (*desc)->height * 72.27 / Fix2X((*desc)->vRes); + bounds->wd = (*desc)->width * 72.27 / Fix2D((*desc)->hRes); + bounds->ht = (*desc)->height * 72.27 / Fix2D((*desc)->vRes); DisposeHandle((Handle)desc); (void)CloseComponent(ci); } diff --git a/Build/source/texk/web2c/xetexdir/XeTeX_pic.c b/Build/source/texk/web2c/xetexdir/XeTeX_pic.c index 0d6d8f8b8d3..9481dce5f54 100644 --- a/Build/source/texk/web2c/xetexdir/XeTeX_pic.c +++ b/Build/source/texk/web2c/xetexdir/XeTeX_pic.c @@ -1,9 +1,9 @@ /****************************************************************************\ Part of the XeTeX typesetting system - copyright (c) 1994-2008 by SIL International - copyright (c) 2009 by Jonathan Kew + Copyright (c) 1994-2008 by SIL International + Copyright (c) 2009 by Jonathan Kew - Written by Jonathan Kew + SIL Author(s): Jonathan Kew Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/Build/source/texk/web2c/xetexdir/XeTeXswap.h b/Build/source/texk/web2c/xetexdir/XeTeXswap.h index c39aeff1302..f51dd0d6101 100644 --- a/Build/source/texk/web2c/xetexdir/XeTeXswap.h +++ b/Build/source/texk/web2c/xetexdir/XeTeXswap.h @@ -1,9 +1,9 @@ /****************************************************************************\ Part of the XeTeX typesetting system - copyright (c) 1994-2008 by SIL International - copyright (c) 2009 by Jonathan Kew + Copyright (c) 1994-2008 by SIL International + Copyright (c) 2009 by Jonathan Kew - Written by Jonathan Kew + SIL Author(s): Jonathan Kew Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -33,7 +33,7 @@ authorization from the copyright holders. #ifndef __XeTeXswap_H #define __XeTeXswap_H -#include "unicode/platform.h" // ICU's platform.h defines U_IS_BIG_ENDIAN for us +#include // ICU's platform.h defines U_IS_BIG_ENDIAN for us static inline UInt16 SWAP16(const UInt16 p) diff --git a/Build/source/texk/web2c/xetexdir/am/xetex.am b/Build/source/texk/web2c/xetexdir/am/xetex.am index b0970ce0c12..5250fd4dc88 100644 --- a/Build/source/texk/web2c/xetexdir/am/xetex.am +++ b/Build/source/texk/web2c/xetexdir/am/xetex.am @@ -24,9 +24,11 @@ xetex_cppflags += $(ICU_INCLUDES) ## freetype1/freetype2 confusion -- what a mess. xetex_cppflags += $(FREETYPE2_INCLUDES) xetex_cppflags += $(TECKIT_INCLUDES) -xetex_ldadd = $(libxetex) $(ICU_LIBS) $(TECKIT_LIBS) +xetex_cppflags += $(HARFBUZZ_INCLUDES) +xetex_cppflags += $(GRAPHITE2_INCLUDES) +xetex_ldadd = $(libxetex) $(HARFBUZZ_LIBS) $(GRAPHITE2_LIBS) $(ICU_LIBS) $(TECKIT_LIBS) xetex_dependencies = $(proglib) $(KPATHSEA_DEPEND) -xetex_dependencies += $(ICU_DEPEND) $(TECKIT_DEPEND) +xetex_dependencies += $(ICU_DEPEND) $(TECKIT_DEPEND) $(HARFBUZZ_DEPEND) $(GRAPHITE2_DEPEND) if XETEX_MACOSX @@ -42,14 +44,6 @@ xetex_dependencies += $(POPPLER_DEPEND) $(LIBPNG_DEPEND) endif !XETEX_MACOSX -if XETEX_GRAPHITE - -xetex_cppflags += -DXETEX_GRAPHITE $(GRAPHITE_INCLUDES) -xetex_ldadd += $(GRAPHITE_LIBS) -xetex_dependencies += $(GRAPHITE_DEPEND) - -endif XETEX_GRAPHITE - xetex_cppflags += $(ZLIB_INCLUDES) xetex_ldadd += $(FREETYPE2_LIBS) $(ZLIB_LIBS) xetex_dependencies += $(FREETYPE2_DEPEND) $(ZLIB_DEPEND) @@ -183,15 +177,11 @@ libxetex_a_SOURCES = \ xetexdir/XeTeXFontMgr.h \ xetexdir/XeTeXLayoutInterface.cpp \ xetexdir/XeTeXLayoutInterface.h \ - xetexdir/XeTeXOTLayoutEngine.cpp \ - xetexdir/XeTeXOTLayoutEngine.h \ xetexdir/XeTeXOTMath.cpp \ xetexdir/XeTeXOTMath.h \ xetexdir/XeTeX_ext.c \ xetexdir/XeTeX_ext.h \ xetexdir/XeTeXswap.h \ - xetexdir/cmaps.cpp \ - xetexdir/cmaps.h \ xetexdir/sfnt.h \ xetexdir/trans.c \ xetexdir/trans.h \ @@ -220,10 +210,6 @@ libxetex_a_SOURCES += \ xetexdir/bmpimage.h \ xetexdir/jpegimage.c \ xetexdir/jpegimage.h \ - xetexdir/mfileio.c \ - xetexdir/mfileio.h \ - xetexdir/numbers.c \ - xetexdir/numbers.h \ xetexdir/pdfimage.cpp \ xetexdir/pdfimage.h \ xetexdir/pngimage.c \ @@ -231,14 +217,6 @@ libxetex_a_SOURCES += \ endif !XETEX_MACOSX -if XETEX_GRAPHITE - -libxetex_a_SOURCES += \ - xetexdir/XeTeXGrLayout.cpp \ - xetexdir/XeTeXGrLayout.h - -endif XETEX_GRAPHITE - # We must create xetexd.h etc. before building the libxetex_a_OBJECTS. libxetex_prereq = xetexd.h $(xetex_dependencies) $(libxetex_a_OBJECTS): $(libxetex_prereq) @@ -257,5 +235,5 @@ endif XETEX ## Not used ## -EXTRA_DIST += xetexdir/LICENSE.txt +EXTRA_DIST += xetexdir/COPYING diff --git a/Build/source/texk/web2c/xetexdir/appleGlyphNames.c b/Build/source/texk/web2c/xetexdir/appleGlyphNames.c index 4c303bcc5ee..59a38fdff61 100644 --- a/Build/source/texk/web2c/xetexdir/appleGlyphNames.c +++ b/Build/source/texk/web2c/xetexdir/appleGlyphNames.c @@ -1,9 +1,9 @@ /****************************************************************************\ Part of the XeTeX typesetting system - copyright (c) 1994-2008 by SIL International - copyright (c) 2009 by Jonathan Kew + Copyright (c) 1994-2008 by SIL International + Copyright (c) 2009 by Jonathan Kew - Written by Jonathan Kew + SIL Author(s): Jonathan Kew Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/Build/source/texk/web2c/xetexdir/bmpimage.c b/Build/source/texk/web2c/xetexdir/bmpimage.c index 03846e4b932..27310327e36 100644 --- a/Build/source/texk/web2c/xetexdir/bmpimage.c +++ b/Build/source/texk/web2c/xetexdir/bmpimage.c @@ -1,7 +1,8 @@ /****************************************************************************\ Part of the XeTeX typesetting system - copyright (c) 1994-2006 by SIL International - written by Jonathan Kew + Copyright (c) 1994-2006 by SIL International + + SIL Author(s): Jonathan Kew This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/Build/source/texk/web2c/xetexdir/bmpimage.h b/Build/source/texk/web2c/xetexdir/bmpimage.h index c2d248b001e..1f5cacd00bd 100644 --- a/Build/source/texk/web2c/xetexdir/bmpimage.h +++ b/Build/source/texk/web2c/xetexdir/bmpimage.h @@ -1,7 +1,8 @@ /****************************************************************************\ Part of the XeTeX typesetting system - copyright (c) 1994-2006 by SIL International - written by Jonathan Kew + Copyright (c) 1994-2006 by SIL International + + SIL Author(s): Jonathan Kew This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -53,8 +54,6 @@ #include #endif -#include "mfileio.h" - struct bmp_info { int width; int height; diff --git a/Build/source/texk/web2c/xetexdir/cmaps.cpp b/Build/source/texk/web2c/xetexdir/cmaps.cpp deleted file mode 100644 index 9ae49372d94..00000000000 --- a/Build/source/texk/web2c/xetexdir/cmaps.cpp +++ /dev/null @@ -1,242 +0,0 @@ -/****************************************************************************\ - Part of the XeTeX typesetting system - copyright (c) 1994-2008 by SIL International - copyright (c) 2009 by Jonathan Kew - - Written by Jonathan Kew - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE -FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF -CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of the copyright holders -shall not be used in advertising or otherwise to promote the sale, -use or other dealings in this Software without prior written -authorization from the copyright holders. -\****************************************************************************/ - -/* from ICU sample code, extended by JK for XeTeX */ - -/*************************************************************************** -* -* Copyright (C) 1998-2003, International Business Machines -* Corporation and others. All Rights Reserved. -* -************************************************************************/ - -#include "layout/LETypes.h" -#include "layout/LESwaps.h" - -#include "sfnt.h" -#include "cmaps.h" - -#define SWAPU16(code) ((LEUnicode16) SWAPW(code)) -#define SWAPU32(code) ((LEUnicode32) SWAPL(code)) - -// read a 32-bit value that might only be 16-bit-aligned in memory -#define READ_LONG(code) (le_uint32)((SWAPW(*(le_uint16*)&code) << 16) + SWAPW(*(((le_uint16*)&code) + 1))) - -// -// Finds the high bit by binary searching -// through the bits in value. -// -le_int8 highBit(le_uint32 value) -{ - le_uint8 bit = 0; - - if (value >= 1 << 16) { - value >>= 16; - bit += 16; - } - - if (value >= 1 << 8) { - value >>= 8; - bit += 8; - } - - if (value >= 1 << 4) { - value >>= 4; - bit += 4; - } - - if (value >= 1 << 2) { - value >>= 2; - bit += 2; - } - - if (value >= 1 << 1) { - value >>= 1; - bit += 1; - } - - return bit; -} - -CMAPMapper *CMAPMapper::createUnicodeMapper(const CMAPTable *cmap) -{ - le_uint16 i; - le_uint16 nSubtables = SWAPW(cmap->numberSubtables); - const CMAPEncodingSubtable *subtable = NULL; - le_uint32 offset1 = 0, offset10 = 0; - - for (i = 0; i < nSubtables; i += 1) { - const CMAPEncodingSubtableHeader *esh = &cmap->encodingSubtableHeaders[i]; - - switch (SWAPW(esh->platformID)) { - case 3: // Microsoft encodings - switch (SWAPW(esh->platformSpecificID)) { - case 1: // Unicode (really UCS-2?) - offset1 = READ_LONG(esh->encodingOffset); - break; - - case 10: // UCS-4 - offset10 = READ_LONG(esh->encodingOffset); - break; - } - break; - - case 0: // Apple Unicode - offset10 = READ_LONG(esh->encodingOffset); // we ignore the unicode version - break; - } - } - - - if (offset10 != 0) { - subtable = (const CMAPEncodingSubtable *) ((const char *) cmap + offset10); - } else if (offset1 != 0) { - subtable = (const CMAPEncodingSubtable *) ((const char *) cmap + offset1); - } else { - return NULL; - } - - switch (SWAPW(subtable->format)) { - case 4: - return new CMAPFormat4Mapper(cmap, (const CMAPFormat4Encoding *) subtable); - - case 12: - { - const CMAPFormat12Encoding *encoding = (const CMAPFormat12Encoding *) subtable; - - return new CMAPGroupMapper(cmap, encoding->groups, READ_LONG(encoding->nGroups)); - } - - default: - break; - } - - return NULL; -} - -CMAPFormat4Mapper::CMAPFormat4Mapper(const CMAPTable *cmap, const CMAPFormat4Encoding *header) - : CMAPMapper(cmap) -{ - le_uint16 segCount = SWAPW(header->segCountX2) / 2; - - fEntrySelector = SWAPW(header->entrySelector); - fRangeShift = SWAPW(header->rangeShift) / 2; - fEndCodes = &header->endCodes[0]; - fStartCodes = &header->endCodes[segCount + 1]; // + 1 for reservedPad... - fIdDelta = &fStartCodes[segCount]; - fIdRangeOffset = &fIdDelta[segCount]; -} - -LEGlyphID CMAPFormat4Mapper::unicodeToGlyph(LEUnicode32 unicode32) const -{ - if (unicode32 >= 0x10000) { - return 0; - } - - LEUnicode16 unicode = (LEUnicode16) unicode32; - le_uint16 index = 0; - le_uint16 probe = 1 << fEntrySelector; - TTGlyphID result = 0; - - if (SWAPU16(fStartCodes[fRangeShift]) <= unicode) { - index = fRangeShift; - } - - while (probe > (1 << 0)) { - probe >>= 1; - - if (SWAPU16(fStartCodes[index + probe]) <= unicode) { - index += probe; - } - } - - if (unicode >= SWAPU16(fStartCodes[index]) && unicode <= SWAPU16(fEndCodes[index])) { - if (fIdRangeOffset[index] == 0) { - result = (TTGlyphID) unicode; - } else { - le_uint16 offset = unicode - SWAPU16(fStartCodes[index]); - le_uint16 rangeOffset = SWAPW(fIdRangeOffset[index]); - le_uint16 *glyphIndexTable = (le_uint16 *) ((char *) &fIdRangeOffset[index] + rangeOffset); - - result = SWAPW(glyphIndexTable[offset]); - } - - result += SWAPW(fIdDelta[index]); - } else { - result = 0; - } - - return LE_SET_GLYPH(0, result); -} - -CMAPFormat4Mapper::~CMAPFormat4Mapper() -{ - // parent destructor does it all -} - -CMAPGroupMapper::CMAPGroupMapper(const CMAPTable *cmap, const CMAPGroup *groups, le_uint32 nGroups) - : CMAPMapper(cmap), fGroups(groups) -{ - le_uint8 bit = highBit(nGroups); - fPower = 1 << bit; - fRangeOffset = nGroups - fPower; -} - -LEGlyphID CMAPGroupMapper::unicodeToGlyph(LEUnicode32 unicode32) const -{ - le_int32 probe = fPower; - le_int32 range = 0; - - if (READ_LONG(fGroups[fRangeOffset].startCharCode) <= unicode32) { - range = fRangeOffset; - } - - while (probe > (1 << 0)) { - probe >>= 1; - - if (READ_LONG(fGroups[range + probe].startCharCode) <= unicode32) { - range += probe; - } - } - - if (READ_LONG(fGroups[range].startCharCode) <= unicode32 && READ_LONG(fGroups[range].endCharCode) >= unicode32) { - return (LEGlyphID) (READ_LONG(fGroups[range].startGlyphCode) + unicode32 - READ_LONG(fGroups[range].startCharCode)); - } - - return 0; -} - -CMAPGroupMapper::~CMAPGroupMapper() -{ - // parent destructor does it all -} - diff --git a/Build/source/texk/web2c/xetexdir/cmaps.h b/Build/source/texk/web2c/xetexdir/cmaps.h deleted file mode 100644 index 9236eccd169..00000000000 --- a/Build/source/texk/web2c/xetexdir/cmaps.h +++ /dev/null @@ -1,114 +0,0 @@ -/****************************************************************************\ - Part of the XeTeX typesetting system - copyright (c) 1994-2008 by SIL International - copyright (c) 2009 by Jonathan Kew - - Written by Jonathan Kew - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE -FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF -CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of the copyright holders -shall not be used in advertising or otherwise to promote the sale, -use or other dealings in this Software without prior written -authorization from the copyright holders. -\****************************************************************************/ - -/* from ICU sample code, extended by JK for XeTeX */ - -/*************************************************************************** -* -* Copyright (C) 1998-2003, International Business Machines -* Corporation and others. All Rights Reserved. -* -************************************************************************/ - - -#ifndef __CMAPS_H -#define __CMAPS_H - -#include "layout/LETypes.h" -#include "sfnt.h" - -class CMAPMapper -{ -public: - virtual LEGlyphID unicodeToGlyph(LEUnicode32 unicode32) const = 0; - - virtual ~CMAPMapper() - { - LE_DELETE_ARRAY(fcmap); - } - - static CMAPMapper *createUnicodeMapper(const CMAPTable *cmap); - -protected: - CMAPMapper(const CMAPTable *cmap) - : fcmap(cmap) - { - // nothing else to do - } - - CMAPMapper() {}; - -private: - const CMAPTable *fcmap; -}; - -class CMAPFormat4Mapper : public CMAPMapper -{ -public: - CMAPFormat4Mapper(const CMAPTable *cmap, const CMAPFormat4Encoding *header); - - virtual ~CMAPFormat4Mapper(); - - virtual LEGlyphID unicodeToGlyph(LEUnicode32 unicode32) const; - -protected: - CMAPFormat4Mapper() {}; - -private: - le_uint16 fEntrySelector; - le_uint16 fRangeShift; - const le_uint16 *fEndCodes; - const le_uint16 *fStartCodes; - const le_uint16 *fIdDelta; - const le_uint16 *fIdRangeOffset; -}; - -class CMAPGroupMapper : public CMAPMapper -{ -public: - CMAPGroupMapper(const CMAPTable *cmap, const CMAPGroup *groups, le_uint32 nGroups); - - virtual ~CMAPGroupMapper(); - - virtual LEGlyphID unicodeToGlyph(LEUnicode32 unicode32) const; - -protected: - CMAPGroupMapper() {}; - -private: - le_int32 fPower; - le_int32 fRangeOffset; - const CMAPGroup *fGroups; -}; - -#endif - diff --git a/Build/source/texk/web2c/xetexdir/hz.cpp b/Build/source/texk/web2c/xetexdir/hz.cpp index e96de1b97f8..00765bde879 100644 --- a/Build/source/texk/web2c/xetexdir/hz.cpp +++ b/Build/source/texk/web2c/xetexdir/hz.cpp @@ -1,10 +1,6 @@ /****************************************************************************\ Part of the XeTeX typesetting system - copyright (c) 1994-2008 by SIL International - copyright (c) 2009-2012 by Jonathan Kew - copyright (c) 2012 by Khaled Hosny - - Written by Han The Thanh + Copyright (c) 2010-2012 by Han The Thanh Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/Build/source/texk/web2c/xetexdir/jpegimage.c b/Build/source/texk/web2c/xetexdir/jpegimage.c index 10d8c36a582..491a49656ae 100644 --- a/Build/source/texk/web2c/xetexdir/jpegimage.c +++ b/Build/source/texk/web2c/xetexdir/jpegimage.c @@ -1,7 +1,8 @@ /****************************************************************************\ Part of the XeTeX typesetting system - copyright (c) 1994-2009 by SIL International - written by Jonathan Kew + Copyright (c) 1994-2009 by SIL International + + SIL Author(s): Jonathan Kew This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -74,9 +75,6 @@ * Level 2. */ -#include "mfileio.h" -#include "numbers.h" - #include "jpegimage.h" #include @@ -99,6 +97,30 @@ static void JPEG_info_clear (struct JPEG_info *j_info); #define NEW(n, t) (t*)xmalloc(n * sizeof(t)) #define RENEW(p, n, t) ((p) ? (t*)xrealloc(p, (n) * sizeof(t)) : NEW(n, t)) +static int +get_unsigned_byte (FILE *file) +{ + int ch; + if ((ch = fgetc (file)) < 0) { + fprintf (stderr, "File ended prematurely\n"); + exit(-1); + } + return ch; +} + +static unsigned +get_unsigned_pair (FILE *file) +{ + int i; + int byte; + unsigned pair = 0; + for (i=0; i<2; i++) { + byte = get_unsigned_byte(file); + pair = pair*0x100u + byte; + } + return pair; +} + int check_for_jpeg (FILE *fp) { @@ -422,7 +444,7 @@ read_APP0_JFXX (struct JPEG_info *j_info, FILE *fp, unsigned short length) * 0x11: Thumbnail stored using 1 byte/pixel * 0x13: Thumbnail stored using 3 bytes/pixel */ - seek_relative(fp, length-1); /* Thunbnail image */ + fseek(fp, length-1, SEEK_CUR); /* Thunbnail image */ /* Ignore */ @@ -491,7 +513,7 @@ JPEG_scan_file (struct JPEG_info *j_info, FILE *fp) length -= read_APP0_JFXX(j_info, fp, length); } } - seek_relative(fp, length); + fseek(fp, length, SEEK_CUR); break; case JM_APP1: if (length > 5) { @@ -502,7 +524,7 @@ JPEG_scan_file (struct JPEG_info *j_info, FILE *fp) length -= read_APP1_Exif(j_info, fp, length); } } - seek_relative(fp, length); + fseek(fp, length, SEEK_CUR); break; case JM_APP2: if (length >= 14) { @@ -517,7 +539,7 @@ JPEG_scan_file (struct JPEG_info *j_info, FILE *fp) } } } - seek_relative(fp, length); + fseek(fp, length, SEEK_CUR); break; case JM_APP14: if (length > 5) { @@ -533,10 +555,10 @@ JPEG_scan_file (struct JPEG_info *j_info, FILE *fp) } } } - seek_relative(fp, length); + fseek(fp, length, SEEK_CUR); break; default: - seek_relative(fp, length); + fseek(fp, length, SEEK_CUR); if (marker >= JM_APP0 && marker <= JM_APP15) { if (count < MAX_COUNT) { diff --git a/Build/source/texk/web2c/xetexdir/jpegimage.h b/Build/source/texk/web2c/xetexdir/jpegimage.h index 5099138027e..690acabe133 100644 --- a/Build/source/texk/web2c/xetexdir/jpegimage.h +++ b/Build/source/texk/web2c/xetexdir/jpegimage.h @@ -1,7 +1,8 @@ /****************************************************************************\ Part of the XeTeX typesetting system - copyright (c) 1994-2006 by SIL International - written by Jonathan Kew + Copyright (c) 1994-2006 by SIL International + + SIL Author(s): Jonathan Kew This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -48,7 +49,7 @@ #ifndef _JPEGIMAGE_H_ #define _JPEGIMAGE_H_ -#include "mfileio.h" +#include /* JPEG Markers */ typedef enum { diff --git a/Build/source/texk/web2c/xetexdir/mfileio.c b/Build/source/texk/web2c/xetexdir/mfileio.c deleted file mode 100644 index e6c1a229850..00000000000 --- a/Build/source/texk/web2c/xetexdir/mfileio.c +++ /dev/null @@ -1,126 +0,0 @@ -/* $Header: /home/cvsroot/dvipdfmx/src/mfileio.c,v 1.3 2002/10/30 02:27:11 chofchof Exp $ - - This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks. - - Copyright (C) 2002 by Jin-Hwan Cho and Shunsaku Hirata, - the dvipdfmx project team - - Copyright (C) 1998, 1999 by Mark A. Wicks - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. -*/ - -#include -#include -#include "mfileio.h" - -#ifdef IODEBUG -static FILE *iodebug_file = NULL; -static long event = 0; -static void io_debug_init(void) -{ - if (!iodebug_file) { - iodebug_file = fopen ("fopen.log", "wb"); - fprintf (stderr, "\n*** File IO debugging started ***\n"); - } - if (!iodebug_file) { - fprintf (stderr, "\nError opening io log\n"); - } -} -#endif - -#ifdef IODEBUG -FILE *mfopen(const char *name, const char *mode, const char *function, int line) -{ - FILE *tmp; - io_debug_init(); - tmp = fopen (name, mode); - event += 1; - fprintf(iodebug_file, "%p %07ld [fopen] %s:%d\n", tmp, event, - function, line); - return tmp; -} -int mfclose(FILE *file, const char *function, int line) -{ - io_debug_init(); - event += 1; - fprintf(iodebug_file, "%p %07ld [fclose] %s:%d\n", file, event, - function, line); - return fclose(file); -} -#endif - -static void os_error() -{ - fprintf (stderr, "io: An OS command failed that should not have.\n"); - exit(-1); -} - -void seek_absolute (FILE *file, long pos) -{ - if (fseek(file, pos, SEEK_SET)) { - os_error(); - } -} - -void seek_relative (FILE *file, long pos) -{ - if (fseek(file, pos, SEEK_CUR)) { - os_error(); - } -} - - -void seek_end (FILE *file) -{ - if (fseek(file, 0L, SEEK_END)) { - os_error(); - } -} - -long tell_position (FILE *file) -{ - long size; - if ((size = ftell (file)) < 0) { - os_error(); - } - return size; -} - -long file_size (FILE *file) -{ - long size; - /* Seek to end */ - seek_end (file); - size = tell_position (file); - rewind (file); - return (size); -} - -/* Unlike fgets, mfgets works with \r, \n, or \r\n end of lines. */ -char *mfgets (char *buffer, unsigned long length, FILE *file) -{ - int ch = 0, i = 0; - while (i < length-1 && (ch = fgetc (file)) >= 0 && ch != '\n' && ch != '\r') - buffer[i++] = ch; - buffer[i] = 0; - if (ch < 0 && i == 0) - return NULL; - if (ch == '\r' && (ch = fgetc (file)) >= 0 && (ch != '\n')) - ungetc (ch, file); - return buffer; -} - -char work_buffer[WORK_BUFFER_SIZE]; diff --git a/Build/source/texk/web2c/xetexdir/mfileio.h b/Build/source/texk/web2c/xetexdir/mfileio.h deleted file mode 100644 index e31fef23244..00000000000 --- a/Build/source/texk/web2c/xetexdir/mfileio.h +++ /dev/null @@ -1,61 +0,0 @@ -/* $Header: /home/cvsroot/dvipdfmx/src/mfileio.h,v 1.3 2002/10/30 02:27:12 chofchof Exp $ - - This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks. - - Copyright (C) 2002 by Jin-Hwan Cho and Shunsaku Hirata, - the dvipdfmx project team - - Copyright (C) 1998, 1999 by Mark A. Wicks - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. -*/ - -#ifndef _MFILEIO_H_ -#define _MFILEIO_H_ - -#include -#include "numbers.h" - -#ifdef IODEBUG -FILE *mfopen (const char *name, const char *mode, - const char *function, int line); -int mfclose (FILE *file, const char *function, int line); -#define MFOPEN(name,mode) \ - mfopen((name),(mode),__FUNCTION__,__LINE__) -#define MFCLOSE(file) \ - mfclose((file),__FUNCTION__,__LINE__) -#else -#define MFOPEN(name,mode) fopen((name),(mode)) -#define MFCLOSE(file) fclose(file) -#endif - -extern UNSIGNED_BYTE read_byte (FILE *); - -extern void seek_absolute (FILE *file, long pos); -extern void seek_relative (FILE *file, long pos); - -extern void seek_end (FILE *file); - -extern long tell_position (FILE *file); - -extern long file_size (FILE *file); - -extern char *mfgets (char *buffer, unsigned long size, FILE *file); - -extern char work_buffer[]; - -#define WORK_BUFFER_SIZE 1024 - -#endif /* _MFILEIO_H_ */ diff --git a/Build/source/texk/web2c/xetexdir/numbers.c b/Build/source/texk/web2c/xetexdir/numbers.c deleted file mode 100644 index 06864f1e2bb..00000000000 --- a/Build/source/texk/web2c/xetexdir/numbers.c +++ /dev/null @@ -1,227 +0,0 @@ -/* $Header: /home/cvsroot/dvipdfmx/src/numbers.c,v 1.8 2004/03/03 13:19:00 hirata Exp $ - - This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks. - - Copyright (C) 2002 by Jin-Hwan Cho and Shunsaku Hirata, - the dvipdfmx project team - - Copyright (C) 1998, 1999 by Mark A. Wicks - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. -*/ - -#include - -#include "mfileio.h" -#include "numbers.h" - -UNSIGNED_BYTE get_unsigned_byte (FILE *file) -{ - int ch; - if ((ch = fgetc (file)) < 0) { - fprintf (stderr, "File ended prematurely\n"); - exit(-1); - } - return (UNSIGNED_BYTE) ch; -} - -UNSIGNED_BYTE sget_unsigned_byte (char *s) -{ - return *((unsigned char *) s); -} - -SIGNED_BYTE get_signed_byte (FILE *file) -{ - int byte; - byte = get_unsigned_byte(file); - if (byte >= 0x80) - byte -= 0x100; - return (SIGNED_BYTE) byte; -} - -UNSIGNED_PAIR get_unsigned_pair (FILE *file) -{ - int i; - UNSIGNED_BYTE byte; - UNSIGNED_PAIR pair = 0; - for (i=0; i<2; i++) { - byte = get_unsigned_byte(file); - pair = pair*0x100u + byte; - } - return pair; -} - -UNSIGNED_PAIR sget_unsigned_pair (unsigned char *s) -{ - int i; - UNSIGNED_BYTE byte; - UNSIGNED_PAIR pair = 0; - for (i=0; i<2; i++) { - byte = *(s++); - pair = pair*0x100u + byte; - } - return pair; -} - -SIGNED_PAIR get_signed_pair (FILE *file) -{ - int i; - long pair = 0; - for (i=0; i<2; i++) { - pair = pair*0x100 + get_unsigned_byte(file); - } - if (pair >= 0x8000) { - pair -= 0x10000l; - } - return (SIGNED_PAIR) pair; -} - - -UNSIGNED_TRIPLE get_unsigned_triple(FILE *file) -{ - int i; - long triple = 0; - for (i=0; i<3; i++) { - triple = triple*0x100u + get_unsigned_byte(file); - } - return (UNSIGNED_TRIPLE) triple; -} - -SIGNED_TRIPLE get_signed_triple(FILE *file) -{ - int i; - long triple = 0; - for (i=0; i<3; i++) { - triple = triple*0x100 + get_unsigned_byte(file); - } - if (triple >= 0x800000l) - triple -= 0x1000000l; - return (SIGNED_TRIPLE) triple; -} - -SIGNED_QUAD get_signed_quad(FILE *file) -{ - int byte, i; - long quad = 0; - - /* Check sign on first byte before reading others */ - byte = get_unsigned_byte(file); - quad = byte; - if (quad >= 0x80) - quad = byte - 0x100; - for (i=0; i<3; i++) { - quad = quad*0x100 + get_unsigned_byte(file); - } - return (SIGNED_QUAD) quad; -} - -UNSIGNED_QUAD get_unsigned_quad(FILE *file) -{ - int i; - unsigned long quad = 0; - for (i=0; i<4; i++) { - quad = quad*0x100u + get_unsigned_byte(file); - } - return (UNSIGNED_QUAD) quad; -} - -#if 0 -SIGNED_QUAD sqxfw (SIGNED_QUAD sq, fixword fw) -{ - int sign = 1; - unsigned long a, b, c, d, ad, bd, bc, ac; - unsigned long e, f, g, h, i, j, k; - unsigned long result; - /* Make positive. */ - if (sq < 0) { - sign = -sign; - sq = -sq; - } - if (fw < 0) { - sign = -sign; - fw = -fw; - } - a = ((unsigned long) sq) >> 16u; - b = ((unsigned long) sq) & 0xffffu; - c = ((unsigned long) fw) >> 16u; - d = ((unsigned long) fw) & 0xffffu; - ad = a*d; bd = b*d; bc = b*c; ac = a*c; - e = bd >> 16u; - f = ad >> 16u; - g = ad & 0xffffu; - h = bc >> 16u; - i = bc & 0xffffu; - j = ac >> 16u; - k = ac & 0xffffu; - result = (e+g+i + (1<<3)) >> 4u; /* 1<<3 is for rounding */ - result += (f+h+k) << 12u; - result += j << 28u; - return (sign > 0) ? result : result * -1L; -} - -SIGNED_QUAD axboverc (SIGNED_QUAD n1, SIGNED_QUAD n2, SIGNED_QUAD divide) -{ - int sign = 1; - unsigned long a, b, c, d, ad, bd, bc, ac, e, f, g, h, i, j, o; - unsigned long high, low; - SIGNED_QUAD result = 0; - /* Make positive. */ - if (n1 < 0) { - sign = -sign; - n1 = -n1; - } - if (n2 < 0) { - sign = -sign; - n2 = -n2; - } - if (divide < 0) { - sign = -sign; - divide = -divide; - } - a = ((unsigned long) n1) >> 16u; - b = ((unsigned long) n1) & 0xffffu; - c = ((unsigned long) n2) >> 16u; - d = ((unsigned long) n2) & 0xffffu; - ad = a*d; bd = b*d; bc = b*c; ac = a*c; - e = bd >> 16u; f = bd & 0xffffu; - g = ad >> 16u; h = ad & 0xffffu; - i = bc >> 16u; j = bc & 0xffffu; - o = e+h+j; - high = g+i+(o>>16u)+ac; o &= 0xffffu; - low = (o << 16) + f; - if (high >= divide) - ERROR ("Overflow in axboc"); - { - int k; - for (k=0; k<32; k++) { - high *= 2; - result *= 2; - if (low >= 0x80000000) { - low -= 0x80000000; - high += 1; - } - low *= 2; - if (high > divide) { - high -= divide; - result += 1; - } - } - } - high *= 2; - if (high >= divide) - result += 1; - return (sign>0)?result:-result; -} -#endif diff --git a/Build/source/texk/web2c/xetexdir/numbers.h b/Build/source/texk/web2c/xetexdir/numbers.h deleted file mode 100644 index 1f61607654e..00000000000 --- a/Build/source/texk/web2c/xetexdir/numbers.h +++ /dev/null @@ -1,78 +0,0 @@ -/* $Header: /home/cvsroot/dvipdfmx/src/numbers.h,v 1.9 2005/07/20 10:41:54 hirata Exp $ - - This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks. - - Copyright (C) 2002, 2012 by Jin-Hwan Cho and Shunsaku Hirata, - the dvipdfmx project team - - Copyright (C) 1998, 1999 by Mark A. Wicks - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. -*/ - -#ifndef _NUMBERS_H_ -#define _NUMBERS_H_ - -#include -#include - -typedef unsigned char Ubyte; -typedef int UNSIGNED_BYTE, SIGNED_BYTE, SIGNED_PAIR; -typedef unsigned UNSIGNED_PAIR; -typedef long UNSIGNED_TRIPLE, SIGNED_TRIPLE, SIGNED_QUAD; -typedef unsigned long UNSIGNED_QUAD; - -extern UNSIGNED_BYTE get_unsigned_byte (FILE *); -extern UNSIGNED_BYTE sget_unsigned_byte (char *); -extern SIGNED_BYTE get_signed_byte (FILE *); -extern UNSIGNED_PAIR get_unsigned_pair (FILE *); -extern UNSIGNED_PAIR sget_unsigned_pair (unsigned char *); -extern SIGNED_PAIR get_signed_pair (FILE *); -extern UNSIGNED_TRIPLE get_unsigned_triple (FILE *); -extern SIGNED_TRIPLE get_signed_triple (FILE *); -extern SIGNED_QUAD get_signed_quad (FILE *); -extern UNSIGNED_QUAD get_unsigned_quad (FILE *); - -typedef signed long fixword; - -extern SIGNED_QUAD sqxfw (SIGNED_QUAD sq, fixword fw); -extern SIGNED_QUAD axboverc (SIGNED_QUAD n1, SIGNED_QUAD n2, SIGNED_QUAD divide); - -#ifndef MAX -# define MAX(a,b) ((a)>(b)?(a):(b)) -#endif -#ifndef MIN -# define MIN(a,b) ((a)<(b)?(a):(b)) -#endif -#define ISODD(n) (((n)/2)*2!=(n)) -#define ISEVEN(n) (((n)/2)*2==(n)) - -#define ROUND(n,acc) (floor(((double)n)/(acc)+0.5)*(acc)) - -#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L -# define __C99__ -#endif - -#ifndef __C99__ -# ifndef round -# define round(v) (floor((v) + 0.5)) -# endif -# ifndef trunc -# define trunc(v) ((v) > 0.0 ? floor((v)) : ceil((v))) -# endif -#endif -#define round_at(v,acc) (round(((double)(v))/(acc))*(acc)) - -#endif /* _NUMBERS_H_ */ diff --git a/Build/source/texk/web2c/xetexdir/pdfimage.cpp b/Build/source/texk/web2c/xetexdir/pdfimage.cpp index 911e2d31434..51b740ea06d 100644 --- a/Build/source/texk/web2c/xetexdir/pdfimage.cpp +++ b/Build/source/texk/web2c/xetexdir/pdfimage.cpp @@ -1,9 +1,9 @@ /****************************************************************************\ Part of the XeTeX typesetting system - copyright (c) 1994-2008 by SIL International - copyright (c) 2009, 2011 by Jonathan Kew + Copyright (c) 1994-2008 by SIL International + Copyright (c) 2009, 2011 by Jonathan Kew - Written by Jonathan Kew + SIL Author(s): Jonathan Kew Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/Build/source/texk/web2c/xetexdir/pdfimage.h b/Build/source/texk/web2c/xetexdir/pdfimage.h index 0368bab5aee..97c44c3d152 100644 --- a/Build/source/texk/web2c/xetexdir/pdfimage.h +++ b/Build/source/texk/web2c/xetexdir/pdfimage.h @@ -1,9 +1,9 @@ /****************************************************************************\ Part of the XeTeX typesetting system - copyright (c) 1994-2008 by SIL International - copyright (c) 2009 by Jonathan Kew + Copyright (c) 1994-2008 by SIL International + Copyright (c) 2009 by Jonathan Kew - Written by Jonathan Kew + SIL Author(s): Jonathan Kew Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/Build/source/texk/web2c/xetexdir/pngimage.c b/Build/source/texk/web2c/xetexdir/pngimage.c index 25f7362562c..42279345881 100644 --- a/Build/source/texk/web2c/xetexdir/pngimage.c +++ b/Build/source/texk/web2c/xetexdir/pngimage.c @@ -1,7 +1,8 @@ /****************************************************************************\ Part of the XeTeX typesetting system - copyright (c) 1994-2006 by SIL International - written by Jonathan Kew + Copyright (c) 1994-2006 by SIL International + + SIL Author(s): Jonathan Kew This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/Build/source/texk/web2c/xetexdir/pngimage.h b/Build/source/texk/web2c/xetexdir/pngimage.h index c126986c5c7..bda409dc7d5 100644 --- a/Build/source/texk/web2c/xetexdir/pngimage.h +++ b/Build/source/texk/web2c/xetexdir/pngimage.h @@ -1,7 +1,8 @@ /****************************************************************************\ Part of the XeTeX typesetting system - copyright (c) 1994-2006 by SIL International - written by Jonathan Kew + Copyright (c) 1994-2006 by SIL International + + SIL Author(s): Jonathan Kew This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -53,8 +54,6 @@ #include #endif -#include "mfileio.h" - struct png_info { int width; int height; diff --git a/Build/source/texk/web2c/xetexdir/sfnt.h b/Build/source/texk/web2c/xetexdir/sfnt.h index b9d32133713..6844154c34e 100644 --- a/Build/source/texk/web2c/xetexdir/sfnt.h +++ b/Build/source/texk/web2c/xetexdir/sfnt.h @@ -1,9 +1,9 @@ /****************************************************************************\ Part of the XeTeX typesetting system - copyright (c) 1994-2008 by SIL International - copyright (c) 2009 by Jonathan Kew + Copyright (c) 1994-2008 by SIL International + Copyright (c) 2009 by Jonathan Kew - Written by Jonathan Kew + SIL Author(s): Jonathan Kew Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -42,245 +42,127 @@ authorization from the copyright holders. #ifndef __SFNT_H #define __SFNT_H -#include "layout/LETypes.h" - - #ifndef ANY_NUMBER #define ANY_NUMBER 1 #endif -struct DirectoryEntry -{ - le_uint32 tag; - le_uint32 checksum; - le_uint32 offset; - le_uint32 length; -}; - -struct SFNTDirectory -{ - le_uint32 scalerType; - le_uint16 numTables; - le_uint16 searchRange; - le_uint16 entrySelector; - le_uint16 rangeShift; - DirectoryEntry tableDirectory[ANY_NUMBER]; -}; - - -struct CMAPEncodingSubtableHeader -{ - le_uint16 platformID; - le_uint16 platformSpecificID; - le_uint32 encodingOffset; -}; - -struct CMAPTable -{ - le_uint16 version; - le_uint16 numberSubtables; - CMAPEncodingSubtableHeader encodingSubtableHeaders[ANY_NUMBER]; -}; +typedef int32_t fixed; -struct CMAPEncodingSubtable +typedef struct { - le_uint16 format; - le_uint16 length; - le_uint16 language; -}; - -struct CMAPFormat0Encoding : CMAPEncodingSubtable -{ - le_uint8 glyphIndexArray[256]; -}; - -struct CMAPFormat2Subheader -{ - le_uint16 firstCode; - le_uint16 entryCount; - le_int16 idDelta; - le_uint16 idRangeOffset; -}; - -struct CMAPFormat2Encoding : CMAPEncodingSubtable -{ - le_uint16 subHeadKeys[256]; - CMAPFormat2Subheader subheaders[ANY_NUMBER]; -}; - -struct CMAPFormat4Encoding : CMAPEncodingSubtable -{ - le_uint16 segCountX2; - le_uint16 searchRange; - le_uint16 entrySelector; - le_uint16 rangeShift; - le_uint16 endCodes[ANY_NUMBER]; -// le_uint16 reservedPad; -// le_uint16 startCodes[ANY_NUMBER]; -// le_uint16 idDelta[ANY_NUMBER]; -// le_uint16 idRangeOffset[ANY_NUMBER]; -// le_uint16 glyphIndexArray[ANY_NUMBER]; -}; - -struct CMAPFormat6Encoding : CMAPEncodingSubtable -{ - le_uint16 firstCode; - le_uint16 entryCount; - le_uint16 glyphIndexArray[ANY_NUMBER]; -}; - -struct CMAPEncodingSubtable32 -{ - le_uint16 format; - le_uint16 reserved; - le_uint32 length; - le_uint32 language; -}; - -struct CMAPGroup -{ - le_uint32 startCharCode; - le_uint32 endCharCode; - le_uint32 startGlyphCode; -}; - -struct CMAPFormat8Encoding : CMAPEncodingSubtable32 -{ - le_uint32 is32[65536/32]; - le_uint32 nGroups; - CMAPGroup groups[ANY_NUMBER]; -}; - -struct CMAPFormat10Encoding : CMAPEncodingSubtable32 -{ - le_uint32 startCharCode; - le_uint32 numCharCodes; - le_uint16 glyphs[ANY_NUMBER]; -}; - -struct CMAPFormat12Encoding : CMAPEncodingSubtable32 -{ - le_uint32 nGroups; - CMAPGroup groups[ANY_NUMBER]; -}; - -typedef le_int32 fixed; - -struct BigDate -{ - le_uint32 bc; - le_uint32 ad; -}; + uint32_t bc; + uint32_t ad; +} BigDate; struct HEADTable { - fixed version; - fixed fontRevision; - le_uint32 checksumAdjustment; - le_uint32 magicNumber; - le_uint16 flags; - le_uint16 unitsPerEm; - BigDate created; - BigDate modified; - le_int16 xMin; - le_int16 yMin; - le_int16 xMax; - le_int16 yMax; - le_uint16 macStyle; - le_uint16 lowestRecPPEM; - le_int16 fontDirectionHint; - le_int16 indexToLocFormat; - le_int16 glyphDataFormat; + fixed version; + fixed fontRevision; + uint32_t checksumAdjustment; + uint32_t magicNumber; + uint16_t flags; + uint16_t unitsPerEm; + BigDate created; + BigDate modified; + int16_t xMin; + int16_t yMin; + int16_t xMax; + int16_t yMax; + uint16_t macStyle; + uint16_t lowestRecPPEM; + int16_t fontDirectionHint; + int16_t indexToLocFormat; + int16_t glyphDataFormat; }; struct MAXPTable { - fixed version; - le_uint16 numGlyphs; - le_uint16 maxPoints; - le_uint16 maxContours; - le_uint16 maxComponentPoints; - le_uint16 maxComponentContours; - le_uint16 maxZones; - le_uint16 maxTwilightPoints; - le_uint16 maxStorage; - le_uint16 maxFunctionDefs; - le_uint16 maxInstructionDefs; - le_uint16 maxStackElements; - le_uint16 maxSizeOfInstructions; - le_uint16 maxComponentElements; - le_uint16 maxComponentDepth; + fixed version; + uint16_t numGlyphs; + uint16_t maxPoints; + uint16_t maxContours; + uint16_t maxComponentPoints; + uint16_t maxComponentContours; + uint16_t maxZones; + uint16_t maxTwilightPoints; + uint16_t maxStorage; + uint16_t maxFunctionDefs; + uint16_t maxInstructionDefs; + uint16_t maxStackElements; + uint16_t maxSizeOfInstructions; + uint16_t maxComponentElements; + uint16_t maxComponentDepth; }; struct HHEATable { - fixed version; - le_int16 ascent; - le_int16 descent; - le_int16 lineGap; - le_uint16 advanceWidthMax; - le_int16 minLeftSideBearing; - le_int16 minRightSideBearing; - le_int16 xMaxExtent; - le_int16 caretSlopeRise; - le_int16 caretSlopeRun; - le_int16 caretOffset; - le_int16 reserved1; - le_int16 reserved2; - le_int16 reserved3; - le_int16 reserved4; - le_int16 metricDataFormat; - le_uint16 numOfLongHorMetrics; -}; - -struct LongHorMetric -{ - le_uint16 advanceWidth; - le_int16 leftSideBearing; -}; + fixed version; + int16_t ascent; + int16_t descent; + int16_t lineGap; + uint16_t advanceWidthMax; + int16_t minLeftSideBearing; + int16_t minRightSideBearing; + int16_t xMaxExtent; + int16_t caretSlopeRise; + int16_t caretSlopeRun; + int16_t caretOffset; + int16_t reserved1; + int16_t reserved2; + int16_t reserved3; + int16_t reserved4; + int16_t metricDataFormat; + uint16_t numOfLongHorMetrics; +}; + +typedef struct +{ + uint16_t advanceWidth; + int16_t leftSideBearing; +} LongHorMetric; struct HMTXTable { LongHorMetric hMetrics[ANY_NUMBER]; // ANY_NUMBER = numOfLongHorMetrics from hhea table -// le_int16 leftSideBearing[ANY_NUMBER]; // ANY_NUMBER = numGlyphs - numOfLongHorMetrics +// int16_t leftSideBearing[ANY_NUMBER]; // ANY_NUMBER = numGlyphs - numOfLongHorMetrics }; struct POSTTable { fixed version; fixed italicAngle; - le_int16 underlinePosition; - le_uint16 underlineThickness; - le_uint32 isFixedPitch; - le_uint32 minMemType42; - le_uint32 maxMemType42; - le_uint32 minMemType1; - le_uint32 maxMemType1; + int16_t underlinePosition; + uint16_t underlineThickness; + uint32_t isFixedPitch; + uint32_t minMemType42; + uint32_t maxMemType42; + uint32_t minMemType1; + uint32_t maxMemType1; }; struct OS2TableHeader { - le_uint16 version; - le_int16 xAvgCharWidth; - le_uint16 usWeightClass; - le_uint16 usWidthClass; - le_int16 fsType; - le_int16 ySubscriptXSize; - le_int16 ySubscriptYSize; - le_int16 ySubscriptXOffset; - le_int16 ySubscriptYOffset; - le_int16 ySuperscriptXSize; - le_int16 ySuperscriptYSize; - le_int16 ySuperscriptXOffset; - le_int16 ySuperscriptYOffset; - le_int16 yStrikeoutSize; - le_int16 yStrikeoutPosition; - le_int16 sFamilyClass; - le_uint8 panose[10]; - le_uint8 ulCharRange[16]; // spec'd as 4 longs, but do this to keep structure packed - le_int8 achVendID[4]; - le_uint16 fsSelection; - le_uint16 fsFirstCharIndex; - le_uint16 fsLastCharIndex; + uint16_t version; + int16_t xAvgCharWidth; + uint16_t usWeightClass; + uint16_t usWidthClass; + int16_t fsType; + int16_t ySubscriptXSize; + int16_t ySubscriptYSize; + int16_t ySubscriptXOffset; + int16_t ySubscriptYOffset; + int16_t ySuperscriptXSize; + int16_t ySuperscriptYSize; + int16_t ySuperscriptXOffset; + int16_t ySuperscriptYOffset; + int16_t yStrikeoutSize; + int16_t yStrikeoutPosition; + int16_t sFamilyClass; + uint8_t panose[10]; + uint8_t ulCharRange[16]; // spec'd as 4 longs, but do this to keep structure packed + int8_t achVendID[4]; + uint16_t fsSelection; + uint16_t fsFirstCharIndex; + uint16_t fsLastCharIndex; }; #endif diff --git a/Build/source/texk/web2c/xetexdir/tex.ch0 b/Build/source/texk/web2c/xetexdir/tex.ch0 index b25252129e5..ff1d4950cfe 100644 --- a/Build/source/texk/web2c/xetexdir/tex.ch0 +++ b/Build/source/texk/web2c/xetexdir/tex.ch0 @@ -3,14 +3,6 @@ % xetex.web and ../tex.ch % Public domain. -@x [1.2] l.188 -@d TeX_banner=='This is TeX, Version 3.1415926' {printed when \TeX\ starts} -@# -@d banner==XeTeX_banner -@y -@d banner=='This is TeX, Version 3.1415926' {printed when \TeX\ starts} -@z - @x [8.110] l.2422 - increase |max_halfword| @d min_halfword==-@"FFFFFFF {smallest allowable value in a |halfword|} @d max_halfword==@"3FFFFFFF {largest allowable value in a |halfword|} diff --git a/Build/source/texk/web2c/xetexdir/trans.c b/Build/source/texk/web2c/xetexdir/trans.c index 1957239d24d..9e2ab0e5b70 100644 --- a/Build/source/texk/web2c/xetexdir/trans.c +++ b/Build/source/texk/web2c/xetexdir/trans.c @@ -1,9 +1,9 @@ /****************************************************************************\ Part of the XeTeX typesetting system - copyright (c) 1994-2008 by SIL International - copyright (c) 2009 by Jonathan Kew + Copyright (c) 1994-2008 by SIL International + Copyright (c) 2009 by Jonathan Kew - Written by Jonathan Kew + SIL Author(s): Jonathan Kew Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/Build/source/texk/web2c/xetexdir/trans.h b/Build/source/texk/web2c/xetexdir/trans.h index b45ceaa3ebb..70c575fa4b3 100644 --- a/Build/source/texk/web2c/xetexdir/trans.h +++ b/Build/source/texk/web2c/xetexdir/trans.h @@ -1,9 +1,9 @@ /****************************************************************************\ Part of the XeTeX typesetting system - copyright (c) 1994-2008 by SIL International - copyright (c) 2009 by Jonathan Kew + Copyright (c) 1994-2008 by SIL International + Copyright (c) 2009 by Jonathan Kew - Written by Jonathan Kew + SIL Author(s): Jonathan Kew Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/Build/source/texk/web2c/xetexdir/unicode-char-prep.pl b/Build/source/texk/web2c/xetexdir/unicode-char-prep.pl index 4c2bf19e9ae..600ee07e280 100644 --- a/Build/source/texk/web2c/xetexdir/unicode-char-prep.pl +++ b/Build/source/texk/web2c/xetexdir/unicode-char-prep.pl @@ -2,10 +2,10 @@ # /****************************************************************************\ # Part of the XeTeX typesetting system -# copyright (c) 1994-2008 by SIL International -# copyright (c) 2009 by Jonathan Kew +# Copyright (c) 1994-2008 by SIL International +# Copyright (c) 2009 by Jonathan Kew # -# Written by Jonathan Kew +# SIL Author(s): Jonathan Kew # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the diff --git a/Build/source/texk/web2c/xetexdir/xetex.ch b/Build/source/texk/web2c/xetexdir/xetex.ch index 47dc693d2fb..4495d1c5774 100644 --- a/Build/source/texk/web2c/xetexdir/xetex.ch +++ b/Build/source/texk/web2c/xetexdir/xetex.ch @@ -1,10 +1,10 @@ /****************************************************************************\ Part of the XeTeX typesetting system - copyright (c) 1994-2008 by SIL International - copyright (c) 2009-2012 by Jonathan Kew - copyright (c) 2012 by Khaled Hosny + Copyright (c) 1994-2008 by SIL International + Copyright (c) 2009-2012 by Jonathan Kew + Copyright (c) 2012 by Khaled Hosny - Written by Jonathan Kew + SIL Author(s): Jonathan Kew Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -186,9 +186,8 @@ else if stop_at_space and (file_name_quote_char<>0) and (c=file_name_quote_char) file_name_quote_char:=0; more_name:=true; end -else if stop_at_space and (file_name_quote_char=0) and ((c="""") or (c="'") or (c="(")) then begin - if c="(" then file_name_quote_char:=")" - else file_name_quote_char:=c; +else if stop_at_space and (file_name_quote_char=0) and ((c="""") or (c="'")) then begin + file_name_quote_char:=c; quoted_filename:=true; @z @@ -527,12 +526,6 @@ if list_ptr(p)=null then begin end; @z -@x [36.749] l.14638 - MLTeX: avoid substitution in |make_op| - begin c:=rem_byte(cur_i); i:=orig_char_info(cur_f)(c); -@y - begin c:=rem_byte(cur_i); i:=orig_char_info(cur_f)(c); -@z - @x [43.943] l.18348 - bigtrie: Larger hyphenation tries. @!trie_used:array[ASCII_code] of trie_opcode; @y diff --git a/Build/source/texk/web2c/xetexdir/xetex.defines b/Build/source/texk/web2c/xetexdir/xetex.defines index 4f15814a3a3..c854df94519 100644 --- a/Build/source/texk/web2c/xetexdir/xetex.defines +++ b/Build/source/texk/web2c/xetexdir/xetex.defines @@ -1,10 +1,10 @@ { /****************************************************************************\ Part of the XeTeX typesetting system - copyright (c) 1994-2008 by SIL International - copyright (c) 2009 by Jonathan Kew + Copyright (c) 1994-2008 by SIL International + Copyright (c) 2009 by Jonathan Kew - Written by Jonathan Kew + SIL Author(s): Jonathan Kew Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -115,6 +115,7 @@ authorization from the copyright holders. @define function getotassemblyptr(); @define function getotmathitalcorr(); @define function getotmathaccentpos(); +@define function getotmathkern(); @define function otpartcount(); @define function otpartglyph(); @@ -145,8 +146,8 @@ authorization from the copyright holders. @define function deref(); -@define function X2Fix(); -@define function Fix2X(); +@define function D2Fix(); +@define function Fix2D(); @define function findpicfile(); @define function picpathbyte(); diff --git a/Build/source/texk/web2c/xetexdir/xetex.h b/Build/source/texk/web2c/xetexdir/xetex.h index 5b492bbcf38..a797ce8389b 100644 --- a/Build/source/texk/web2c/xetexdir/xetex.h +++ b/Build/source/texk/web2c/xetexdir/xetex.h @@ -1,9 +1,9 @@ /****************************************************************************\ Part of the XeTeX typesetting system - copyright (c) 1994-2008 by SIL International - copyright (c) 2009 by Jonathan Kew + Copyright (c) 1994-2008 by SIL International + Copyright (c) 2009 by Jonathan Kew - Written by Jonathan Kew + SIL Author(s): Jonathan Kew Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -50,19 +50,16 @@ authorization from the copyright holders. #define setjustifiednativeglyphs(p) store_justified_native_glyphs(&(mem[p])) -#define getnativeitaliccorrection(p) get_native_ital_corr(&(mem[p])) -#define getnativeglyphitaliccorrection(p) get_native_glyph_ital_corr(&(mem[p])) +#define getnativeitaliccorrection(p) get_native_italic_correction(&(mem[p])) +#define getnativeglyphitaliccorrection(p) get_native_glyph_italic_correction(&(mem[p])) -#define getnativeglyph(p,i) get_native_glyph_id(&(mem[p]), i) +#define getnativeglyph(p,i) get_native_glyph(&(mem[p]), i) #define makexdvglypharraydata(p) makeXDVGlyphArrayData(&(mem[p])) #define xdvbufferbyte(i) xdvbuffer[i] #define getnativewordcp(p,s) get_native_word_cp(&(mem[p]), s) - -void* get_ot_assembly_ptr(int f, int g, int horiz); /* function in XeTeXOTMath.cpp */ - #define pic_node_size 8 #define deref(p) (*(p)) @@ -94,6 +91,7 @@ void* get_ot_assembly_ptr(int f, int g, int horiz); /* function in XeTeXOTMath.c #define getotassemblyptr get_ot_assembly_ptr #define getotmathitalcorr get_ot_math_ital_corr #define getotmathaccentpos get_ot_math_accent_pos +#define getotmathkern get_ot_math_kern #define otpartcount ot_part_count #define otpartglyph ot_part_glyph #define otpartisextender ot_part_is_extender @@ -123,3 +121,9 @@ void* get_ot_assembly_ptr(int f, int g, int horiz); /* function in XeTeXOTMath.c #include "trans.h" /* functions for affine transform operations */ #include /* include this before XeTeX_ext.h */ #include "XeTeX_ext.h" /* other extension functions */ + +#include +/* apparently M_PI isn't defined by under VC++ */ +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif diff --git a/Build/source/texk/web2c/xetexdir/xetex.web b/Build/source/texk/web2c/xetexdir/xetex.web index 24bf496e34a..f8de399a567 100644 --- a/Build/source/texk/web2c/xetexdir/xetex.web +++ b/Build/source/texk/web2c/xetexdir/xetex.web @@ -1,3 +1,34 @@ +% Copyright (c) 1994-2008 by SIL International +% Copyright (c) 2009-2012 by Jonathan Kew +% Copyright (c) 2010-2012 Han Han The Thanh +% Copyright (c) 2012 by Khaled Hosny + +% SIL Author(s): Jonathan Kew + +% Part of the XeTeX typesetting system + +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +% IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +% CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +% Except as contained in this notice, the name of the copyright holders shall +% not be used in advertising or otherwise to promote the sale, use or other +% dealings in this Software without prior written authorization from the +% copyright holders. + % e-TeX is copyright (C) 1999-2012 by P. Breitenlohner (1994,98 by the NTS % team); all rights are reserved. Copying of this file is authorized only if % (1) you are P. Breitenlohner, or if (2) you make absolutely no changes to @@ -116,7 +147,10 @@ \def\textindent#1{\hangindent2.5em\noindent\hbox to2.5em{\hss#1 }\ignorespaces} \font\ninerm=cmr9 \let\mc=\ninerm % medium caps for names like SAIL -\def\XeTeX{Xe\TeX} + +\input graphicx % \relectbox for XeTeX logo +\def\XeTeX{X\kern-.125em\lower.5ex\hbox{\reflectbox{E}}\kern-.1667em\TeX} + \def\eTeX{$\varepsilon$-\TeX} \font\revrm=xbmc10 % for right-to-left text % to generate xbmc10 (i.e., reflected cmbx10) use a file @@ -289,9 +323,7 @@ known as `\eTeX'. @d XeTeX_banner=='This is XeTeX, Version 3.1415926',eTeX_version_string,XeTeX_version_string {printed when \XeTeX\ starts} @# -@d TeX_banner=='This is TeX, Version 3.1415926' {printed when \TeX\ starts} -@# -@d banner==XeTeX_banner +@d banner=='This is TeX, Version 3.1415926' {printed when \TeX\ starts} @# @d TEX==XETEX {change program name into |XETEX|} @# @@ -577,15 +609,14 @@ emphasize this distinction. @d hash_prime=1777 {a prime number equal to about 85\pct! of |hash_size|} @d hyph_size=307 {another prime; the number of \.{\\hyphenation} exceptions} @d biggest_char=65535 {the largest allowed character number; - must be |<=max_quarterword|} -{NB: |biggest_char| here refers to UTF16 codepoints that we store in strings, etc; - actual character codes can exceed this range, up to |biggest_usv|.} -@d biggest_usv=@"10FFFF {the largest Unicode Scalar Value} + must be |<=max_quarterword|, this refers to UTF16 codepoints that we store in strings, etc; + actual character codes can exceed this range, up to |biggest_usv|} @d too_big_char=65536 {|biggest_char+1|} @d special_char=65537 {|biggest_char+2|} @d number_chars=65536 {|biggest_char+1|} -@d too_big_usv=@"110000 -@d number_usvs=@"110000 +@d biggest_usv=@"10FFFF {the largest Unicode Scalar Value} +@d too_big_usv=@"110000 {|biggest_usv+1|} +@d number_usvs=@"110000 {|biggest_usv+1|} @d biggest_reg=255 {the largest allowed register number; must be |<=max_quarterword|} @d number_regs=256 {|biggest_reg+1|} @@ -597,8 +628,8 @@ emphasize this distinction. @d text_size=0 {size code for the largest size in a family} @d script_size=number_math_families {size code for the medium size in a family} @d script_script_size=number_math_families+number_math_families {size code for the smallest size in a family} -@d biggest_lang=255 -@d too_big_lang=256 +@d biggest_lang=255 {the largest hyphenation language} +@d too_big_lang=256 {|biggest_lang+1|} @^system dependencies@> @ In case somebody has inadvertently made bad settings of the ``constants,'' @@ -867,7 +898,7 @@ implement \TeX\ can open a file whose external name is specified by @!name_of_file:packed array[1..file_name_size] of char;@;@/ {on some systems this may be a \&{record} variable} @!name_of_file16:array[1..file_name_size] of UTF16_code;@;@/ - {but sometimes we need a utf16 version of the name} + {but sometimes we need a UTF16 version of the name} @!name_length:0..file_name_size;@/{this many characters are actually relevant in |name_of_file| (the rest are blank)} @!name_length16:0..file_name_size; @@ -1420,9 +1451,6 @@ Thus, at least 81 printable characters are needed. @^character set dependencies@> @^system dependencies@> -@= -{ this module is not used } - @ When the \.{WEB} system program called \.{TANGLE} processes the \.{TEX.WEB} description that you are now reading, it outputs the \PASCAL\ program \.{TEX.PAS} and also a string pool file called \.{TEX.POOL}. The \.{INITEX} @@ -1635,7 +1663,7 @@ procedure print_char(@!s:integer); {prints a single character} label exit; var l: small_number; begin if (selector>pseudo) and (not doing_special) then - {"printing" to a new string, encode as UTF-16 rather than UTF-8} + {``printing'' to a new string, encode as UTF-16 rather than UTF-8} begin if s>=@"10000 then begin print_visible_char(@"D800 + (s - @"10000) div @"400); print_visible_char(@"DC00 + (s - @"10000) mod @"400); @@ -1646,8 +1674,8 @@ if @ then if selector= 128: encode as UTF8 } + { |char >= 128|: encode as UTF8 } if s<@"800 then begin print_visible_char(@"C0 + s div @"40); print_visible_char(@"80 + s mod @"40); @@ -3178,7 +3207,7 @@ operation. The |adjust_ptr| field points to the vlist containing this material. @d adjust_node=5 {|type| of an adjust node} -@d adjust_pre == subtype {<>0 => pre-adjustment} +@d adjust_pre == subtype {|if subtype <>0| it is pre-adjustment} @#{|append_list| is used to append a list to |tail|} @d append_list(#) == begin link(tail) := link(#); append_list_end @d append_list_end(#) == tail := #; end @@ -3269,27 +3298,37 @@ discussion of extensions until the end of this program. @d whatsit_node=8 {|type| of special extension nodes} -{ added stuff here for |native_word| and picture nodes } -@d native_word_node=40 {|subtype| in whatsits that hold |native_font| words - (0-3 are used for open, write, close, special; 4 is language; pdfTeX uses up through 30-something) +@ To support ``native'' fonts, we build |native_word_node|s, which are variable +size whatsits. These have the same |width|, |depth|, and |height| fields as a +|box_node|, at offsets 1-3, and then a word containing a size field for the +node, a font number, a length, and a glyph count. Then there is a field +containing a C pointer to a glyph info array; this and the glyph count are set +by |set_native_metrics|. Copying and freeing of these nodes needs to take +account of this! This is followed by |2*length| bytes, for the actual +characters of the string (in UTF-16). + +So |native_node_size|, which does not include any space for the actual text, is +6. -To support ``native'' fonts, we build |native_word_nodes|, which are variable size whatsits. -These have the same |width|, |depth|, and |height| fields as a |box_node|, at offsets 1-3, -and then a word containing a size field for the node, a font number, a length, and a glyph count. -Then there is a field containing a C pointer to a glyph info array; -this and the glyph count are set by |set_native_metrics|. -Copying and freeing of these nodes needs to take account of this! -This is followed by |2*length| bytes, for the actual characters of the string (in UTF-16). +0-3 whatsits subtypes are used for open, write, close, special; 4 is language; +pdf\TeX\ uses up through 30-something, so we use subtypes starting from 40. -So |native_node_size|, which does not include any space for the actual text, is 6.} +There are also |glyph_node|s; these are like |native_word_node|s in having +|width|, |depth|, and |height| fields, but then they contain a glyph ID rather +than size and length fields, and there's no subsidiary C pointer. -@d native_node_size=6 {size of a |native_word| node (plus the actual chars) -- see also xetex.h} +@d native_word_node=40 {|subtype| of whatsits that hold |native_font| words} +@d glyph_node=41 {|subtype| in whatsits that hold glyph numbers} + +@d native_node_size=6 {size of a |native_word| node (plus the actual chars) -- see also \.{xetex.h}} +@d glyph_node_size=5 @d native_size(#)==mem[#+4].qqqq.b0 @d native_font(#)==mem[#+4].qqqq.b1 @d native_length(#)==mem[#+4].qqqq.b2 @d native_glyph_count(#)==mem[#+4].qqqq.b3 @d native_glyph_info_ptr(#)==mem[#+5].ptr -@d native_glyph_info_size=10 { number of bytes of info per glyph: 16-bit glyph ID, 32-bit x and y coords } +@d native_glyph_info_size=10 {number of bytes of info per glyph: 16-bit glyph ID, 32-bit x and y coords} +@d native_glyph==native_length {in |glyph_node|s, we store the glyph number here} @d free_native_glyph_info(#) == begin @@ -3311,24 +3350,7 @@ begin end end; -@ There are also |glyph_nodes|; these are like |native_word_nodes| in having |width|, |depth|, and |height| fields, -but then they contain a glyph ID rather than size and length fields, and there's no subsidiary C pointer. - -@d glyph_node_size=5 -@d native_glyph==native_length {in |glyph_node|s, we store the glyph number here} - -@d pic_node=42 {|subtype| in whatsits that hold picture file references} -@d pdf_node=43 {|subtype| in whatsits that hold PDF page references} -@d glyph_node=44 {|subtype| in whatsits that hold glyph numbers} - -@d pdfbox_crop = 1 { |pic_box_type| values in PDF nodes } -@d pdfbox_media = 2 -@d pdfbox_bleed = 3 -@d pdfbox_trim = 4 -@d pdfbox_art = 5 - - -{Picture files are handled with nodes that include fields for the transform associated +@ Picture files are handled with nodes that include fields for the transform associated with the picture, and a pathname for the picture file itself. They also have the |width|, |depth|, and |height| fields of a |box_node| at offsets 1-3. (|depth| will @@ -3336,12 +3358,21 @@ always be zero, as it happens.) So |pic_node_size|, which does not include any space for the picture file pathname, is 7. -|pdf_nodes| are just like |pic_nodes|, but generate a different xdv file code.} +A |pdf_node| is just like |pic_node|, but generate a different \.{XDV} file code. -@d pic_node_size=8 { must sync with xetex.h } +@d pic_node=42 {|subtype| in whatsits that hold picture file references} +@d pdf_node=43 {|subtype| in whatsits that hold PDF page references} +@# +@d pdfbox_crop=1 {|pic_box_type| values in PDF nodes} +@d pdfbox_media=2 +@d pdfbox_bleed=3 +@d pdfbox_trim=4 +@d pdfbox_art=5 +@# +@d pic_node_size=8 {must sync with \.{xetex.h}} @d pic_path_length(#)==mem[#+4].hh.b0 @d pic_page(#)==mem[#+4].hh.b1 -@d pic_box_type(#)==mem[#+4].hh.rh { for PDF, unused in picfile } +@d pic_box_type(#)==mem[#+4].hh.rh {for PDF, unused in picfile} @d pic_transform1(#)==mem[#+5].hh.lh @d pic_transform2(#)==mem[#+5].hh.rh @d pic_transform3(#)==mem[#+6].hh.lh @@ -3521,17 +3552,6 @@ inserted from \.{\\mkern} specifications in math formulas). @d explicit=1 {|subtype| of kern nodes from \.{\\kern} and \.{\\/}} @d acc_kern=2 {|subtype| of kern nodes from accents} -@ The |new_kern| function creates a kern node having a given width. - -@p function new_kern(@!w:scaled):pointer; -var p:pointer; {the new node} -begin p:=get_node(small_node_size); type(p):=kern_node; -subtype(p):=normal; -width(p):=w; -new_kern:=p; -end; - -@ Some stuff for character protrusion. @# {memory structure for marginal kerns} @d margin_kern_node = 40 @d margin_kern_node_size = 3 @@ -3550,7 +3570,17 @@ end; @d max_hlist_stack = 512 {maximum fill level for |hlist_stack|} {maybe good if larger than |2 * max_quarterword|, so that box nesting level would overflow first} -@= +@ The |new_kern| function creates a kern node having a given width. + +@p function new_kern(@!w:scaled):pointer; +var p:pointer; {the new node} +begin p:=get_node(small_node_size); type(p):=kern_node; +subtype(p):=normal; +width(p):=w; +new_kern:=p; +end; + +@ @= @!last_leftmost_char: pointer; @!last_rightmost_char: pointer; @!hlist_stack:array[0..max_hlist_stack] of pointer; {stack for |find_protchar_left()| and |find_protchar_right()|} @@ -3828,7 +3858,6 @@ gubed @ Some stuff for character protrusion. -@d pdf_debug_on == true {change to |false| to suppress debugging info} @p procedure pdf_error(t, p: str_number); begin @@ -3843,27 +3872,6 @@ begin succumb; end; -procedure pdf_DEBUG(s: str_number); -begin - if not pdf_debug_on then - return; - print_ln; print("DEBUG: "); print(s); -end; - -procedure pdf_DEBUG_int(s: str_number; i: integer); -begin - if not pdf_debug_on then - return; - print_ln; print("DEBUG: "); print(s); print_int(i); -end; - -procedure pdf_DEBUG_str(s, s2: str_number); -begin - if not pdf_debug_on then - return; - print_ln; print("DEBUG: "); print(s); print(s2); -end; - function prev_rightmost(s, e: pointer): pointer; {finds the node preceding the rightmost node |e|; |s| is some node before |e|} @@ -4371,7 +4379,6 @@ begin while p<>null do end; kern_node,math_node,penalty_node: do_nothing; margin_kern_node: begin -{ free_avail(margin_char(p)); } free_node(p, margin_kern_node_size); goto done; end; @@ -4463,9 +4470,6 @@ kern_node,math_node,penalty_node: begin r:=get_node(small_node_size); end; margin_kern_node: begin r := get_node(margin_kern_node_size); -{ fast_get_avail(margin_char(r)); } -{ font(margin_char(r)) := font(margin_char(p)); } -{ character(margin_char(r)) := character(margin_char(p)); } words := margin_kern_node_size; end; ligature_node: begin r:=get_node(small_node_size); @@ -4591,7 +4595,7 @@ expanded by `\.{\\the}'. @d min_internal=68 {the smallest code that can follow \.{\\the}} @d char_given=68 {character code defined by \.{\\chardef}} @d math_given=69 {math code defined by \.{\\mathchardef}} -@d XeTeX_math_given=70 +@d XeTeX_math_given=70 {extended math code defined by \.{\\Umathchardef}} @d last_item=71 {most recent item ( \.{\\lastpenalty}, \.{\\lastkern}, \.{\\lastskip} )} @d max_non_prefixed_command=71 {largest command code that can't be \.{\\global}} @@ -4620,7 +4624,7 @@ that might be expanded by `\.{\\the}'. @d set_shape=85 {specify fancy paragraph shape ( \.{\\parshape} )} {(or \.{\\interlinepenalties}, etc.~)} @d def_code=86 {define a character code ( \.{\\catcode}, etc.~)} -@d XeTeX_def_code=87 {\.{\\XeTeXmathcode}, \.{\\XeTeXdelcode}} +@d XeTeX_def_code=87 {\.{\\Umathcode}, \.{\\Udelcode}} @d def_family=88 {declare math fonts ( \.{\\textfont}, etc.~)} @d set_font=89 {set current font ( font identifiers )} @d def_font=90 {define a font file ( \.{\\font} )} @@ -5631,15 +5635,7 @@ language_code:print_esc("language"); left_hyphen_min_code:print_esc("lefthyphenmin"); right_hyphen_min_code:print_esc("righthyphenmin"); holding_inserts_code:print_esc("holdinginserts"); -@{ -print_esc("errorcontextlines"); -print_esc("XeTeXlinebreakpenalty"); -print_esc("XeTeXlinebreakpenalty"); -print_esc("XeTeXprotrudechars"); -print_esc("XeTeXprotrudechars"); -@} error_context_lines_code:print_esc("errorcontextlines"); -{XeTeX\_linebreak\_locale\_code:print\_esc("XeTeXlinebreaklocale");} XeTeX_linebreak_penalty_code:print_esc("XeTeXlinebreakpenalty"); XeTeX_protrude_chars_code:print_esc("XeTeXprotrudechars"); @/@@/ @@ -5767,7 +5763,6 @@ primitive("XeTeXlinebreakpenalty",assign_int,int_base+XeTeX_linebreak_penalty_co @!@:XeTeX_linebreak_penalty_}{\.{\\XeTeXlinebreakpenalty} primitive@> primitive("XeTeXprotrudechars",assign_int,int_base+XeTeX_protrude_chars_code);@/ @!@:XeTeX_protrude_chars_}{\.{\\XeTeXprotrudechars} primitive@> -@{ @} @{ @} @{ @} @ @= assign_int: if chr_code; p:=h+hash_base; {we start searching here; note that |0<=h=@"10000 then incr(ll); @@ -6336,7 +6331,8 @@ primitive("csname",cs_name,0);@/ primitive("delimiter",delim_num,0);@/ @!@:delimiter_}{\.{\\delimiter} primitive@> primitive("XeTeXdelimiter",delim_num,1);@/ -@!@:XeTeX_delimiter_}{\.{\\XeTeXdelimiter} primitive@> +primitive("Udelimiter",delim_num,1);@/ +@!@:U_delimiter_}{\.{\\Udelimiter} primitive@> primitive("divide",divide,0);@/ @!@:divide_}{\.{\\divide} primitive@> primitive("endcsname",end_cs_name,0);@/ @@ -6363,13 +6359,16 @@ primitive("mark",mark,0);@/ primitive("mathaccent",math_accent,0);@/ @!@:math_accent_}{\.{\\mathaccent} primitive@> primitive("XeTeXmathaccent",math_accent,1);@/ -@!@:XeTeX_math_accent_}{\.{\\XeTeXmathaccent} primitive@> +primitive("Umathaccent",math_accent,1);@/ +@!@:U_math_accent_}{\.{\\Umathaccent} primitive@> primitive("mathchar",math_char_num,0);@/ @!@:math_char_}{\.{\\mathchar} primitive@> primitive("XeTeXmathcharnum",math_char_num,1);@/ -@!@:XeTeX_math_char_num_}{\.{\\XeTeXmathcharnum} primitive@> +primitive("Umathcharnum",math_char_num,1);@/ +@!@:U_math_char_num_}{\.{\\Umathcharnum} primitive@> primitive("XeTeXmathchar",math_char_num,2);@/ -@!@:XeTeX_math_char_}{\.{\\XeTeXmathchar} primitive@> +primitive("Umathchar",math_char_num,2);@/ +@!@:U_math_char_}{\.{\\Umathchar} primitive@> primitive("mathchoice",math_choice,0);@/ @!@:math_choice_}{\.{\\mathchoice} primitive@> primitive("multiply",multiply,0);@/ @@ -6395,7 +6394,8 @@ primitive("prevgraf",set_prev_graf,0);@/ primitive("radical",radical,0);@/ @!@:radical_}{\.{\\radical} primitive@> primitive("XeTeXradical",radical,1);@/ -@!@:XeTeX_radical_}{\.{\\XeTeXradical} primitive@> +primitive("Uradical",radical,1);@/ +@!@:U_radical_}{\.{\\Uradical} primitive@> primitive("read",read_to_cs,0);@/ @!@:read_}{\.{\\read} primitive@> primitive("relax",relax,too_big_usv); {cf.\ |scan_file_name|} @@ -6433,7 +6433,7 @@ break_penalty: print_esc("penalty"); char_num: print_esc("char"); cs_name: print_esc("csname"); def_font: print_esc("font"); -delim_num: if chr_code=1 then print_esc("XeTeXdelimiter") +delim_num: if chr_code=1 then print_esc("Udelimiter") else print_esc("delimiter"); divide: print_esc("divide"); end_cs_name: print_esc("endcsname"); @@ -6449,10 +6449,10 @@ ital_corr: print_esc("/"); mark: begin print_esc("mark"); if chr_code>0 then print_char("s"); end; -math_accent: if chr_code=1 then print_esc("XeTeXmathaccent") +math_accent: if chr_code=1 then print_esc("Umathaccent") else print_esc("mathaccent"); -math_char_num: if chr_code=2 then print_esc("XeTeXmathchar") - else if chr_code=1 then print_esc("XeTeXmathcharnum") +math_char_num: if chr_code=2 then print_esc("Umathchar") + else if chr_code=1 then print_esc("Umathcharnum") else print_esc("mathchar"); math_choice: print_esc("mathchoice"); multiply: print_esc("multiply"); @@ -6462,7 +6462,7 @@ no_expand: if chr_code=0 then print_esc("noexpand") else print_esc("primitive"); non_script: print_esc("nonscript"); omit: print_esc("omit"); -radical: if chr_code=1 then print_esc("XeTeXradical") else print_esc("radical"); +radical: if chr_code=1 then print_esc("Uradical") else print_esc("radical"); read_to_cs: if chr_code=0 then print_esc("read") @; relax: print_esc("relax"); @@ -6888,10 +6888,10 @@ A \TeX\ token is either a character or a control sequence, and it is @^token@> represented internally in one of two ways: (1)~A character whose ASCII code number is |c| and whose command code is |m| is represented as the -number $2^16m+c$; the command code is in the range |1<=m<=14|. (2)~A control +number $2^{21}m+c$; the command code is in the range |1<=m<=14|. (2)~A control sequence whose |eqtb| address is |p| is represented as the number -|cs_token_flag+p|. Here |cs_token_flag=@t$2^{20}-1$@>| is larger than -$2^8m+c$, yet it is small enough that |cs_token_flag+p< max_halfword|; +|cs_token_flag+p|. Here |cs_token_flag=@t$2^{25}-1$@>| is larger than +$2^{21}m+c$, yet it is small enough that |cs_token_flag+p< max_halfword|; thus, a token fits comfortably in a halfword. A token |t| represents a |left_brace| command if and only if @@ -6901,23 +6901,23 @@ we have |left_brace_limit<=t= if cs_token_flag+undefined_control_sequence>max_halfword then bad:=21; @@ -9317,17 +9317,17 @@ XeTeX_def_code: scanned_result(ho(math_code(cur_val)))(int_val) end else if m=math_code_base+1 then begin - print_err("Can't use \XeTeXmathcode as a number (try \XeTeXmathcodenum)"); - help2("\XeTeXmathcode is for setting a mathcode from separate values;")@/ - ("use \XeTeXmathcodenum to access them as single values."); error; + print_err("Can't use \Umathcode as a number (try \Umathcodenum)"); + help2("\Umathcode is for setting a mathcode from separate values;")@/ + ("use \Umathcodenum to access them as single values."); error; scanned_result(0)(int_val) end else if m=del_code_base then begin scanned_result(ho(del_code(cur_val)))(int_val) end else begin - print_err("Can't use \XeTeXdelcode as a number (try \XeTeXdelcodenum)"); - help2("\XeTeXdelcode is for setting a delcode from separate values;")@/ - ("use \XeTeXdelcodenum to access them as single values."); error; + print_err("Can't use \Udelcode as a number (try \Udelcodenum)"); + help2("\Udelcode is for setting a delcode from separate values;")@/ + ("use \Udelcodenum to access them as single values."); error; scanned_result(0)(int_val); end; end; @@ -9445,7 +9445,6 @@ the codes for its extensions: |eTeX_version_code|, \dots\ . @# @d XeTeX_version_code=XeTeX_int {code for \.{\\XeTeXversion}} -{ these are also in xetexmac.c and must correspond! } @d XeTeX_count_glyphs_code=XeTeX_int+1 @d XeTeX_count_variations_code=XeTeX_int+2 @@ -10474,7 +10473,7 @@ end; @d eTeX_revision_code=etex_convert_base {command code for \.{\\eTeXrevision}} @d XeTeX_revision_code=6 -@d XeTeX_variation_name_code=7 { must match codes in xetexmac.c } +@d XeTeX_variation_name_code=7 @d XeTeX_feature_name_code=8 @d XeTeX_selector_name_code=9 @d XeTeX_glyph_name_code=10 @@ -11581,7 +11580,7 @@ and |cur_ext|. @d pack_cur_name==pack_file_name(cur_name,cur_area,cur_ext) -@p procedure pack_job_name(@!s:str_number); {|s = ".log"|, |".dvi"|, or +@p procedure pack_job_name(@!s:str_number); {|s = ".log"|, |output_file_extension|, or |format_extension|} begin cur_area:=""; cur_ext:=s; cur_name:=job_name; pack_cur_name; @@ -12338,8 +12337,7 @@ precise details about why it rejects a particular \.{TFM} file. @d start_font_error_message==print_err("Font "); sprint_cs(u); print_char("="); - if file_name_quote_char=")" then print_char("(") - else if file_name_quote_char<>0 then print_char(file_name_quote_char); + if file_name_quote_char<>0 then print_char(file_name_quote_char); print_file_name(nom,aire,cur_ext); if file_name_quote_char<>0 then print_char(file_name_quote_char); if s>=0 then @@ -13454,6 +13452,10 @@ dvi_out(qo(font_check[f].b3));@/ dvi_four(font_size[f]); dvi_four(font_dsize[f]);@/ dvi_out(length(font_area[f])); +@; +end; + +@ @= l:=0; k:=str_start_macro(font_name[f]); {search for colon; we will truncate the name there} while (l=0) and (k= -for k:=str_start_macro(font_area[f]) to str_start_macro(font_area[f]+1)-1 do - dvi_out(so(str_pool[k])); -for k:=str_start_macro(font_name[f]) to str_start_macro(font_name[f]+1)-1 do - dvi_out(so(str_pool[k])) @ Versions of \TeX\ intended for small computers might well choose to omit the ideas in the next few parts of this program, since it is not really @@ -13853,7 +13848,7 @@ var base_line: scaled; {the baseline coordinate for this box} @!outer_doing_leaders:boolean; {were we doing leaders?} @!edge:scaled; {right edge of sub-box or leader space} @!prev_p:pointer; {one step behind |p|} -@!len: integer; { length of scratch string for native word output } +@!len: integer; {length of scratch string for native word output} @!q,@!r: pointer; @!k,@!j: integer; @!glue_temp:real; {glue value before rounding} @@ -13910,7 +13905,6 @@ check_next: end; goto end_node_run; end; - {@@;} if (q <> null) and is_native_word_node(q) and (native_font(q) = native_font(r)) then begin p := q; {record new tail of run in |p|} q := link(q); @@ -14014,11 +14008,7 @@ rule_node: begin rule_ht:=height(p); rule_dp:=depth(p); rule_wd:=width(p); whatsit_node: @; glue_node: @; margin_kern_node: begin -{ if subtype(p) = right_side then } -{ pdf_DEBUG_int("right margin kern:", width(p)) } -{ else } -{ pdf_DEBUG_int("left margin kern:", width(p)); } - cur_h:=cur_h+width(p); + cur_h:=cur_h+width(p); end; kern_node:cur_h:=cur_h+width(p); math_node: @; @@ -14631,11 +14621,6 @@ begin type(k) := margin_kern_node; subtype(k) := side; width(k) := w; -{ if p = null then } -{ pdf_error("margin kerning", "invalid pointer to marginal char node"); } -{ fast_get_avail(margin_char(k)); } -{ character(margin_char(k)) := character(p); } -{ font(margin_char(k)) := font(p); } new_margin_kern := k; end; @@ -15725,10 +15710,11 @@ define_mathex_accessor(big_op_spacing5)(13)(big_op_spacing5); @ Native font support requires these additional subroutines. +|new_native_word_node| creates the node, but does not actually set its metrics; +call |set_native_metrics(node)| if that is required. + @= function new_native_word_node(@!f:internal_font_number;@!n:integer):pointer; - { note that this function creates the node, but does not actually set its metrics; - call |set_native_metrics(node)| if that is required! } var l: integer; q: pointer; @@ -15964,8 +15950,7 @@ begin height_base[font_ptr] := ascent; depth_base[font_ptr] := -descent; - font_params[font_ptr] := num_font_dimens; { we add an extra fontdimen: \#8 -> |cap_height|; - then OT math fonts have a bunch more } + font_params[font_ptr] := num_font_dimens; {we add an extra \.{\\fontdimen8} |:= cap_height|; then OT math fonts have a bunch more} font_bc[font_ptr] := 0; font_ec[font_ptr] := 65535; font_used[font_ptr] := false; @@ -15974,10 +15959,10 @@ begin param_base[font_ptr] := fmem_ptr-1; font_layout_engine[font_ptr] := font_engine; - font_mapping[font_ptr] := 0; { don't use the mapping, if any, when measuring space here } + font_mapping[font_ptr] := 0; {don't use the mapping, if any, when measuring space here} font_letter_space[font_ptr] := loaded_font_letter_space; - {measure the width of the space character and set up font parameters} +@# {measure the width of the space character and set up font parameters} p := new_native_character(font_ptr, " "); s := width(p) + loaded_font_letter_space; free_node(p, native_size(p)); @@ -16000,7 +15985,7 @@ begin incr(fmem_ptr); if num_font_dimens = first_math_fontdimen + lastMathConstant then begin - font_info[fmem_ptr].int := num_font_dimens; { \fontdimen9 = number of assigned fontdimens } + font_info[fmem_ptr].int := num_font_dimens; { \.{\\fontdimen9} |:=| number of assigned fontdimens } incr(fmem_ptr); for k := 0 to lastMathConstant do begin font_info[fmem_ptr].sc := get_ot_math_constant(font_ptr, k); @@ -16029,48 +16014,25 @@ begin end else begin use_skip := XeTeX_linebreak_skip <> zero_glue; use_penalty := XeTeX_linebreak_penalty <> 0 or not use_skip; - if (is_gr_font(main_f)) and (str_eq_str(XeTeX_linebreak_locale, "G")) then begin - initGraphiteBreaking(font_layout_engine[main_f], native_text + s, len); - offs := 0; - repeat - prevOffs := offs; - offs := findNextGraphiteBreak(offs, 15); {klbWordBreak = 15} - if offs > 0 then begin - if prevOffs <> 0 then begin - if use_penalty then - tail_append(new_penalty(XeTeX_linebreak_penalty)); - if use_skip then - tail_append(new_param_glue(XeTeX_linebreak_skip_code)); - end; - link(tail) := new_native_word_node(main_f, offs - prevOffs); - tail := link(tail); - for i := prevOffs to offs - 1 do - set_native_char(tail, i - prevOffs, native_text[s + i]); - set_native_metrics(tail, XeTeX_use_glyph_metrics); - end; - until offs < 0; - end - else begin - linebreak_start(XeTeX_linebreak_locale, native_text + s, len); - offs := 0; - repeat - prevOffs := offs; - offs := linebreak_next; - if offs > 0 then begin - if prevOffs <> 0 then begin - if use_penalty then - tail_append(new_penalty(XeTeX_linebreak_penalty)); - if use_skip then - tail_append(new_param_glue(XeTeX_linebreak_skip_code)); - end; - link(tail) := new_native_word_node(main_f, offs - prevOffs); - tail := link(tail); - for i := prevOffs to offs - 1 do - set_native_char(tail, i - prevOffs, native_text[s + i]); - set_native_metrics(tail, XeTeX_use_glyph_metrics); + linebreak_start(main_f, XeTeX_linebreak_locale, native_text + s, len); + offs := 0; + repeat + prevOffs := offs; + offs := linebreak_next; + if offs > 0 then begin + if prevOffs <> 0 then begin + if use_penalty then + tail_append(new_penalty(XeTeX_linebreak_penalty)); + if use_skip then + tail_append(new_param_glue(XeTeX_linebreak_skip_code)); end; - until offs < 0; - end + link(tail) := new_native_word_node(main_f, offs - prevOffs); + tail := link(tail); + for i := prevOffs to offs - 1 do + set_native_char(tail, i - prevOffs, native_text[s + i]); + set_native_metrics(tail, XeTeX_use_glyph_metrics); + end; + until offs < 0; end end; @@ -17512,9 +17474,21 @@ We set |shift_down| and |shift_up| to the minimum amounts to shift the baseline of subscripts and superscripts based on the given nucleus. @= +function attach_hkern_to_new_hlist(@!q:pointer;@!delta:scaled):pointer; +var y,@!z:pointer; {temporary registers for box construction} +begin z:=new_kern(delta); +if new_hlist(q)=null then new_hlist(q):=z +else begin y:=new_hlist(q); + while link(y)<>null do y:=link(y); + link(y):=z; + end; +attach_hkern_to_new_hlist:=new_hlist(q); +end; + procedure make_scripts(@!q:pointer;@!delta:scaled); -var p,@!x,@!y,@!z:pointer; {temporary registers for box construction} -@!shift_up,@!shift_down,@!clr:scaled; {dimensions in the calculation} +var p,@!s,@!x,@!y,@!z:pointer; {temporary registers for box construction} +@!shift_up,@!shift_down,@!clr,@!sub_kern,@!sup_kern:scaled; {dimensions in the calculation} +@!g:quarterword; {temporary register for native glyph id} @!t:integer; {subsidiary size code} @!save_f:internal_font_number; begin p:=new_hlist(q); @@ -17557,6 +17531,7 @@ else clr:=height(x)-(abs(math_x_height(cur_size)*4) div 5); if shift_down end @ The bottom of a superscript should never descend below the baseline plus @@ -17577,6 +17552,7 @@ if is_new_mathfont(cur_f) then else clr:=depth(x)+(abs(math_x_height(cur_size)) div 4); if shift_up end @ When both subscript and superscript are present, the subscript must be @@ -17607,11 +17583,49 @@ if clr>0 then shift_down:=shift_down-clr; end; end; -shift_amount(x):=delta; {superscript is |delta| to the right of the subscript} +if is_new_mathfont(cur_f) then begin + @@/ + @ + end; +shift_amount(x):=sup_kern+delta-sub_kern; {superscript is |delta| to the right of the subscript} p:=new_kern((shift_up-depth(x))-(height(y)-shift_down)); link(x):=p; link(p):=y; x:=vpack(x,natural); shift_amount(x):=shift_down; end +@ OpenType math fonts provide an additional adjustment for the horizontal +position of sub/superscripts called math kerning. + +The following definitions should be kept in sync with \.{XeTeXOTMath.cpp}. + +@d sup_cmd=0 {superscript kern type for |get_ot_math_kern|} +@d sub_cmd=1 {subscript kern type for |get_ot_math_kern|} + +@= +begin save_f:=cur_f;@/ +fetch(subscr(q)); +if is_new_mathfont(cur_f) then begin + s:=new_native_character(cur_f, qo(cur_c)); + g:=get_native_glyph(s, 0); + end; +sub_kern:=get_ot_math_kern(native_font(p), native_glyph(p), cur_f, g, sub_cmd, shift_down); +if sub_kern<>0 then p:=attach_hkern_to_new_hlist(q, sub_kern); +cur_f:=save_f; +end; + +@ @= +begin save_f:=cur_f;@/ +fetch(supscr(q)); +if is_new_mathfont(cur_f) then begin + s:=new_native_character(cur_f, qo(cur_c)); + g:=get_native_glyph(s, 0); + end; +sup_kern:=get_ot_math_kern(native_font(p), native_glyph(p), cur_f, g, sup_cmd, shift_up); +if (sup_kern<>0) and (math_type(subscr(q))=empty) then + {if there is a superscript the kern will be added to |shift_amount(x)|} + p:=attach_hkern_to_new_hlist(q, sup_kern); +cur_f:=save_f; +end; + @ We have now tied up all the loose ends of the first pass of |mlist_to_hlist|. The second pass simply goes through and hooks everything together with the proper glue and penalties. It also handles the |left_noad| and |right_noad| that @@ -20250,7 +20264,6 @@ done: of a discretionary break with non-empty |pre_break|, then |q| has been changed to the last node of the |pre_break| list} if XeTeX_protrude_chars > 0 then begin -{ short_display_n(q, 5); } if disc_break and (is_char_node(q) or (type(q) <> disc_node)) {|q| has been reset to the last node of |pre_break|} then begin @@ -20261,11 +20274,9 @@ if XeTeX_protrude_chars > 0 then begin ptmp := p; p := find_protchar_right(link(temp_head), p); end; -{ short_display_n(p, 5); } w := right_pw(p); if w <> 0 then {we have found a marginal kern, append it after |ptmp|} begin -{ pdf_DEBUG_int("right margin:", w); } k := new_margin_kern(-w, last_rightmost_char, right_side); link(k) := link(ptmp); link(ptmp) := k; @@ -20480,7 +20491,7 @@ nodes $p_{a-1}$ and~$p_b$ in the description above are placed into variables @= @!hc:array[0..66] of 0..number_usvs; {word to be hyphenated} { note that element 0 needs to be a full UnicodeScalar, even though we - basically work in utf16 } + basically work in UTF16 } @!hn:small_number; {the number of positions occupied in |hc|} @!ha,@!hb:pointer; {nodes |ha..hb| should be replaced by the hyphenated result} @!hf:internal_font_number; {font number of the letters in |hc|} @@ -24845,7 +24856,6 @@ while link(tail) <> null do begin r := link(tail); if not is_char_node(r) and (type(r) = margin_kern_node) then begin link(tail) := link(r); -{ free_avail(margin_char(r)); } free_node(r, margin_kern_node_size); end; tail:=link(tail); @@ -25428,11 +25438,11 @@ char_num: begin scan_char_num; cur_chr:=cur_val; cur_cmd:=char_given; goto reswitch; end; math_char_num: - if cur_chr = 2 then begin { XeTeXmathchar } + if cur_chr = 2 then begin {\.{\\Umathchar}} scan_math_class_int; c := set_class_field(cur_val); scan_math_fam_int; c := c + set_family_field(cur_val); scan_usv_num; c := c + cur_val; - end else if cur_chr = 1 then begin { XeTeXmathcharnum } + end else if cur_chr = 1 then begin {\.{\\Umathcharnum}} scan_xetex_math_char_int; c := cur_val; end else begin scan_fifteen_bit_int; c := set_class_field(cur_val div @"1000) + @@ -25446,16 +25456,16 @@ math_given: begin end; XeTeX_math_given: c:=cur_chr; delim_num: begin - if cur_chr=1 then begin {XeTeXdelimiter } + if cur_chr=1 then begin {\.{\\Udelimiter }} scan_math_class_int; c := set_class_field(cur_val); scan_math_fam_int; c := c + set_family_field(cur_val); scan_usv_num; c := c + cur_val; - end else begin {delimiter <27-bit delcode>} + end else begin {\.{\\delimiter <27-bit delcode>}} scan_delimiter_int; - c := cur_val div @'10000; {get the 'small' delimiter field} + c := cur_val div @'10000; {get the `small' delimiter field} c := set_class_field(c div @"1000) + set_family_field((c mod @"1000) div @"100) + - (c mod @"100); {and convert it to a xetex mathchar code} + (c mod @"100); {and convert it to a \XeTeX\ mathchar code} end; end; othercases @ @@ -25495,12 +25505,12 @@ mmode+letter,mmode+other_char,mmode+char_given: mmode+char_num: begin scan_char_num; cur_chr:=cur_val; set_math_char(ho(math_code(cur_chr))); end; -mmode+math_char_num: if cur_chr = 2 then begin { XeTeXmathchar } +mmode+math_char_num: if cur_chr = 2 then begin {\.{\\Umathchar}} scan_math_class_int; t := set_class_field(cur_val); scan_math_fam_int; t := t + set_family_field(cur_val); scan_usv_num; t := t + cur_val; set_math_char(t); - end else if cur_chr = 1 then begin { XeTeXmathcharnum } + end else if cur_chr = 1 then begin {\.{\\Umathcharnum}} scan_xetex_math_char_int; set_math_char(cur_val); end else begin scan_fifteen_bit_int; set_math_char(set_class_field(cur_val div @"1000) + @@ -25514,7 +25524,7 @@ mmode+math_given: begin end; mmode+XeTeX_math_given: set_math_char(cur_chr); mmode+delim_num: begin - if cur_chr=1 then begin {XeTeXdelimiter} + if cur_chr=1 then begin {\.{\\Udelimiter}} scan_math_class_int; t := set_class_field(cur_val); scan_math_fam_int; t := t + set_family_field(cur_val); scan_usv_num; t := t + cur_val; @@ -25628,8 +25638,8 @@ delimiter is to be placed; the second tells if this delimiter follows procedure scan_delimiter(@!p:pointer;@!r:boolean); begin if r then begin - if cur_chr=1 then begin {XeTeXradical} - cur_val1 := @"40000000; {extended delcode flag} + if cur_chr=1 then begin {\.{\\Uradical}} + cur_val1 := @"40000000; {extended delimiter code flag} scan_math_fam_int; cur_val1 := cur_val1 + cur_val * @"200000; scan_usv_num; cur_val := cur_val1 + cur_val; end else {radical} @@ -25640,8 +25650,8 @@ else begin @; letter,other_char: begin cur_val:=del_code(cur_chr); end; - delim_num: if cur_chr=1 then begin {XeTeXdelimiter} - cur_val1 := @"40000000; {extended delcode flag} + delim_num: if cur_chr=1 then begin {\.{\\Udelimiter}} + cur_val1 := @"40000000; {extended delimiter code flag} scan_math_class_int; {discarded} scan_math_fam_int; cur_val1 := cur_val1 + cur_val * @"200000; scan_usv_num; cur_val := cur_val1 + cur_val; @@ -25652,13 +25662,13 @@ else begin @; if cur_val<0 then begin @; end; -if cur_val>=@"40000000 then begin {extended delcode, only one size} +if cur_val>=@"40000000 then begin {extended delimiter code, only one size} small_plane_and_fam_field(p) := ((cur_val mod @"200000) div @"10000) * @"100 {plane} + (cur_val div @"200000) mod @"100; {family} small_char_field(p) := qi(cur_val mod @"10000); large_plane_and_fam_field(p) := 0; large_char_field(p) := 0; -end else begin {standard delcode, 4-bit families and 8-bit char codes} +end else begin {standard delimiter code, 4-bit families and 8-bit char codes} small_plane_and_fam_field(p) := (cur_val div @'4000000) mod 16; small_char_field(p) := qi((cur_val div @'10000) mod 256); large_plane_and_fam_field(p) := (cur_val div 256) mod 16; @@ -26568,9 +26578,11 @@ primitive("chardef",shorthand_def,char_def_code);@/ primitive("mathchardef",shorthand_def,math_char_def_code);@/ @!@:math_char_def_}{\.{\\mathchardef} primitive@> primitive("XeTeXmathcharnumdef",shorthand_def,XeTeX_math_char_num_def_code);@/ -@!@:XeTeX_math_char_num_def_}{\.{\\XeTeXmathcharnumdef} primitive@> +primitive("Umathcharnumdef",shorthand_def,XeTeX_math_char_num_def_code);@/ +@!@:U_math_char_num_def_}{\.{\\Umathcharnumdef} primitive@> primitive("XeTeXmathchardef",shorthand_def,XeTeX_math_char_def_code);@/ -@!@:XeTeX_math_char_def_}{\.{\\XeTeXmathchardef} primitive@> +primitive("Umathchardef",shorthand_def,XeTeX_math_char_def_code);@/ +@!@:U_math_char_def_}{\.{\\Umathchardef} primitive@> primitive("countdef",shorthand_def,count_def_code);@/ @!@:count_def_}{\.{\\countdef} primitive@> primitive("dimendef",shorthand_def,dimen_def_code);@/ @@ -26586,8 +26598,8 @@ primitive("toksdef",shorthand_def,toks_def_code);@/ shorthand_def: case chr_code of char_def_code: print_esc("chardef"); math_char_def_code: print_esc("mathchardef"); - XeTeX_math_char_def_code: print_esc("XeTeXmathchardef"); - XeTeX_math_char_num_def_code: print_esc("XeTeXmathcharnumdef"); + XeTeX_math_char_def_code: print_esc("Umathchardef"); + XeTeX_math_char_num_def_code: print_esc("Umathcharnumdef"); count_def_code: print_esc("countdef"); dimen_def_code: print_esc("dimendef"); skip_def_code: print_esc("skipdef"); @@ -26598,7 +26610,7 @@ char_given: begin print_esc("char"); print_hex(chr_code); end; math_given: begin print_esc("mathchar"); print_hex(chr_code); end; -XeTeX_math_given: begin print_esc("XeTeXmathchar"); print_hex(chr_code); +XeTeX_math_given: begin print_esc("Umathchar"); print_hex(chr_code); end; @ We temporarily define |p| to be |relax|, so that an occurrence of |p| @@ -26759,9 +26771,11 @@ primitive("catcode",def_code,cat_code_base); primitive("mathcode",def_code,math_code_base); @!@:math_code_}{\.{\\mathcode} primitive@> primitive("XeTeXmathcodenum",XeTeX_def_code,math_code_base); -@!@:XeTeX_math_code_num_}{\.{\\XeTeXmathcodenum} primitive@> +primitive("Umathcodenum",XeTeX_def_code,math_code_base); +@!@:U_math_code_num_}{\.{\\Umathcodenum} primitive@> primitive("XeTeXmathcode",XeTeX_def_code,math_code_base+1); -@!@:XeTeX_math_code_}{\.{\\XeTeXmathcode} primitive@> +primitive("Umathcode",XeTeX_def_code,math_code_base+1); +@!@:U_math_code_}{\.{\\Umathcode} primitive@> primitive("lccode",def_code,lc_code_base); @!@:lc_code_}{\.{\\lccode} primitive@> primitive("uccode",def_code,uc_code_base); @@ -26769,13 +26783,15 @@ primitive("uccode",def_code,uc_code_base); primitive("sfcode",def_code,sf_code_base); @!@:sf_code_}{\.{\\sfcode} primitive@> primitive("XeTeXcharclass",XeTeX_def_code,sf_code_base); -@!@:XeTeX_char_class_}{\.{\\XeTeXcharclass} primitive@> +@!@:U_char_class_}{\.{\\XeTeXcharclass} primitive@> primitive("delcode",def_code,del_code_base); @!@:del_code_}{\.{\\delcode} primitive@> primitive("XeTeXdelcodenum",XeTeX_def_code,del_code_base); -@!@:XeTeX_del_code_num_}{\.{\\XeTeXdelcodenum} primitive@> +primitive("Udelcodenum",XeTeX_def_code,del_code_base); +@!@:U_del_code_num_}{\.{\\Udelcodenum} primitive@> primitive("XeTeXdelcode",XeTeX_def_code,del_code_base+1); -@!@:XeTeX_del_code_}{\.{\\XeTeXdelcode} primitive@> +primitive("Udelcode",XeTeX_def_code,del_code_base+1); +@!@:U_del_code_}{\.{\\Udelcode} primitive@> primitive("textfont",def_family,math_font_base); @!@:text_font_}{\.{\\textfont} primitive@> primitive("scriptfont",def_family,math_font_base+script_size); @@ -26792,10 +26808,10 @@ def_code: if chr_code=cat_code_base then print_esc("catcode") else print_esc("delcode"); XeTeX_def_code: if chr_code=sf_code_base then print_esc("XeTeXcharclass") - else if chr_code=math_code_base then print_esc("XeTeXmathcodenum") - else if chr_code=math_code_base+1 then print_esc("XeTeXmathcode") - else if chr_code=del_code_base then print_esc("XeTeXdelcodenum") - else print_esc("XeTeXdelcode"); + else if chr_code=math_code_base then print_esc("Umathcodenum") + else if chr_code=math_code_base+1 then print_esc("Umathcode") + else if chr_code=del_code_base then print_esc("Udelcodenum") + else print_esc("Udelcode"); def_family: print_size(chr_code-math_font_base); @ The different types of code values have different legal ranges; the @@ -26834,19 +26850,12 @@ XeTeX_def_code: begin scan_int; {|scan_xetex_del_code_int|; !!FIXME!!} word_define(p,hi(cur_val)); end else begin -{ -bit usage in delcode values: -original layout: @@"00cffCFF small/LARGE family \& char -extended: @@"40000000 FLAG - + ff << 21 (mult by @@"200000) FAMILY - + 1ccccc (21 bits) USV -} p:=cur_chr-1; scan_usv_num; p:=p+cur_val; scan_optional_equals; - n := @"40000000; {extended delcode flag} - scan_math_fam_int; n := n + cur_val * @"200000; - scan_usv_num; n := n + cur_val; + n := @"40000000; {extended delimiter code flag} + scan_math_fam_int; n := n + cur_val * @"200000; {extended delimiter code family} + scan_usv_num; n := n + cur_val; {extended delimiter code USV} word_define(p,hi(n)); end; end; @@ -28692,10 +28701,6 @@ begin old_setting:=selector; selector:=new_string; show_token_list(link(p),null,pool_size-pool_ptr); selector:=old_setting; -{ - last_tokens_string := make_string; - tokens_to_string := last_tokens_string; -} tokens_to_string := make_string; end; @@ -28908,7 +28913,7 @@ begin { now pp points to the non-|native_word| node that ended the chain, or null } { we can just check type(p)=|whatsit_node| below, as we know that the chain - contains only discretionaries and |native_word| nodes, no other whatsits or |char_nodes| } + contains only discretionaries and |native_word| nodes, no other whatsits or |char_node|s } if (pp <> link(p)) then begin { found a chain of at least two pieces starting at p } @@ -29474,11 +29479,11 @@ begin print("size ("); print_scaled(cur_val); print("pt) will be ignored"); - help2("I can't scale images to zero or negative sizes, ") + help2("I can't scale images to zero or negative sizes,")@/ ("so I'm ignoring this."); error; end else - x_size_req := Fix2X(cur_val); + x_size_req := Fix2D(cur_val); end else if scan_keyword("height") then begin scan_normal_dimen; if cur_val <= 0 then begin @@ -29486,15 +29491,15 @@ begin print("size ("); print_scaled(cur_val); print("pt) will be ignored"); - help2("I can't scale images to zero or negative sizes, ") + help2("I can't scale images to zero or negative sizes,")@/ ("so I'm ignoring this."); error; end else - y_size_req := Fix2X(cur_val); + y_size_req := Fix2D(cur_val); end else if scan_keyword("rotated") then begin scan_decimal; if (x_size_req <> 0.0) or (y_size_req <> 0.0) then do_size_requests; - make_rotation(addressof(t2), Fix2X(cur_val) * 3.141592653589793 / 180.0); + make_rotation(addressof(t2), Fix2D(cur_val) * 3.141592653589793 / 180.0); update_corners; calc_min_and_max; setPoint(corners[0], xmin, ymin); @@ -29522,16 +29527,16 @@ begin pic_path_length(tail) := strlen(pic_path); pic_page(tail) := page; - width(tail) := X2Fix(xmax - xmin); - height(tail) := X2Fix(ymax - ymin); + width(tail) := D2Fix(xmax - xmin); + height(tail) := D2Fix(ymax - ymin); depth(tail) := 0; - pic_transform1(tail) := X2Fix(aField(t)); - pic_transform2(tail) := X2Fix(bField(t)); - pic_transform3(tail) := X2Fix(cField(t)); - pic_transform4(tail) := X2Fix(dField(t)); - pic_transform5(tail) := X2Fix(txField(t)); - pic_transform6(tail) := X2Fix(tyField(t)); + pic_transform1(tail) := D2Fix(aField(t)); + pic_transform2(tail) := D2Fix(bField(t)); + pic_transform3(tail) := D2Fix(cField(t)); + pic_transform4(tail) := D2Fix(dField(t)); + pic_transform5(tail) := D2Fix(txField(t)); + pic_transform6(tail) := D2Fix(tyField(t)); memcpy(addressof(mem[tail + pic_node_size]), pic_path, strlen(pic_path)); libc_free(pic_path); @@ -29541,11 +29546,11 @@ begin print_err("Unable to load picture or PDF file '"); print_file_name(cur_name,cur_area,cur_ext); print("'"); if result = -43 then begin { Mac OS file not found error } - help2("The requested image couldn't be read because ") + help2("The requested image couldn't be read because")@/ ("the file was not found."); end else begin { otherwise assume GraphicImport failed } - help2("The requested image couldn't be read because ") + help2("The requested image couldn't be read because")@/ ("it was not a recognized image format."); end; error; @@ -29556,35 +29561,31 @@ end; @ @= begin - { scan a filename-like arg for the input encoding } - scan_and_pack_name; + scan_and_pack_name; {scan a filename-like arg for the input encoding} - { convert it to "mode" and "encoding" values, and apply to the current input file } - i := get_encoding_mode_and_info(addressof(j)); + i := get_encoding_mode_and_info(addressof(j)); {convert it to |mode| and |encoding| values} if i = XeTeX_input_mode_auto then begin - print_err("Encoding mode `auto' is not valid for \XeTeXinputencoding."); - help2("You can't use `auto' encoding here, only for \XeTeXdefaultencoding. ") - ("I'll ignore this and leave the current encoding unchanged."); + print_err("Encoding mode `auto' is not valid for \XeTeXinputencoding"); + help2("You can't use `auto' encoding here, only for \XeTeXdefaultencoding.")@/ + ("I'll ignore this and leave the current encoding unchanged.");@/ error; - end else set_input_file_encoding(input_file[in_open], i, j); + end else set_input_file_encoding(input_file[in_open], i, j); {apply them to the current input file} end @ @= begin - { scan a filename-like arg for the input encoding } - scan_and_pack_name; + scan_and_pack_name; {scan a filename-like arg for the input encoding} - { convert it to "mode" and "encoding" values, and store them as defaults for new input files } - XeTeX_default_input_mode := get_encoding_mode_and_info(addressof(j)); + i := get_encoding_mode_and_info(addressof(j)); {convert it to |mode| and |encoding| values} + XeTeX_default_input_mode := i; {store them as defaults for new input files} XeTeX_default_input_encoding := j; end @ @= begin - { scan a filename-like arg for the locale name } - scan_file_name; + scan_file_name; {scan a filename-like arg for the locale name} if length(cur_name) = 0 then XeTeX_linebreak_locale := 0 - else XeTeX_linebreak_locale := cur_name; { we ignore the area and extension! } + else XeTeX_linebreak_locale := cur_name; {we ignore the area and extension!} end @ @= diff --git a/Build/source/texk/web2c/xetexdir/xetexextra.h b/Build/source/texk/web2c/xetexdir/xetexextra.h index 75b77ce26b2..5a56c8117e1 100644 --- a/Build/source/texk/web2c/xetexdir/xetexextra.h +++ b/Build/source/texk/web2c/xetexdir/xetexextra.h @@ -4,10 +4,10 @@ This is included by XeTeX, from xetexextra.c. Part of the XeTeX typesetting system - copyright (c) 1994-2008 by SIL International - copyright (c) 2009 by Jonathan Kew + Copyright (c) 1994-2008 by SIL International + Copyright (c) 2009 by Jonathan Kew - Written by Jonathan Kew + SIL Author(s): Jonathan Kew Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -60,7 +60,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #define COPYRIGHT_HOLDER "SIL International and Jonathan Kew" #define AUTHOR "Jonathan Kew" #define PROGRAM_HELP XETEXHELP -#define BUG_ADDRESS "jfkthame@gmail.com" +#define BUG_ADDRESS "xetex@tug.org" #define DUMP_VAR TEXformatdefault #define DUMP_LENGTH_VAR formatdefaultlength #define DUMP_OPTION "fmt" -- cgit v1.2.3