diff options
author | Jonathan Kew <jfkthame@googlemail.com> | 2007-11-21 12:27:59 +0000 |
---|---|---|
committer | Jonathan Kew <jfkthame@googlemail.com> | 2007-11-21 12:27:59 +0000 |
commit | 888236cb9df7b7d7b5a3e2d784037a9a59511c53 (patch) | |
tree | f4ec376146c1785c0ad24d6e76a0e13836643e7e /Build/source/libs/graphite-engine/include/graphite | |
parent | 2b361a5e7b7a1b88e29aec64e61b640e145691b6 (diff) |
added Graphite engine (see http://scripts.sil.org/RenderingGraphite)
git-svn-id: svn://tug.org/texlive/trunk@5535 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/libs/graphite-engine/include/graphite')
26 files changed, 4197 insertions, 0 deletions
diff --git a/Build/source/libs/graphite-engine/include/graphite/BinTree.h b/Build/source/libs/graphite-engine/include/graphite/BinTree.h new file mode 100644 index 00000000000..a487df03770 --- /dev/null +++ b/Build/source/libs/graphite-engine/include/graphite/BinTree.h @@ -0,0 +1,71 @@ +/*--------------------------------------------------------------------*//*:Ignore this sentence. +Copyright (C) 1999, 2001 SIL International. All rights reserved. + +Distributable under the terms of either the Common Public License or the +GNU Lesser General Public License, as specified in the LICENSING.txt file. + +File: BinTree.h +Responsibility: Darrell Zook +Last reviewed: 9/8/99 + +Description: + This file provides declarations of binary tree class(es). +----------------------------------------------------------------------------------------------*/ +#ifdef _MSC_VER +#pragma once +#endif +#ifndef BINTREE_H_INCLUDED +#define BINTREE_H_INCLUDED + +/*---------------------------------------------------------------------------------------------- + This template class implements a balanced tree, which is a binary tree where the height of + the two children of any node in the tree can only be different by +/- 1 or 0. + + The class of objects to be stored in the tree should be derived from BalTreeBase, because + the constructor of BalTreeBase adds an object to the tree in sorted order without + allocating any memory. + + Classes that derive from BalTreeBase must have a CompareKey member function that compares + a given key with this->key to determine which should be first when sorting the tree. + The declaration of CompareKey should be as follows: + int CompareKey(const Key & key); + and it should return: + <0 if key is less than the key in the current node (this->key) + 0 if key is equal to the key in the current node (this->key) + >0 if key is greater than the key in the current node (this->key) + + CAUTION: Classes that use this template should never be dynamically instantiated (by using + local variables or new/NewObj). This class is meant to be used only for global + instances of a class. The reason for this restriction is that the tree is never + destroyed, so using dynamic instantiations of objects would result in stale pointers + in the tree. + + Hungarian: btb +----------------------------------------------------------------------------------------------*/ + +template<typename Obj, typename Key> class BalTreeBase +{ +protected: + // Pointers to the left and right subtrees. + Obj * m_rgpobj[2]; + + // The difference between the height of the right sub tree and the height of the left + // sub tree. This should be -1, 0, or +1. Insert may temporarily set it to -2 or +2. + short m_dht; + + // Which way we went from this node when inserting the new node. + short m_ipobj; + + // Inserts this in the balanced tree. + BalTreeBase(Obj ** ppobjRoot, const Key & key); + + // Returns a node with the given key from the tree rooted at pobjRoot. + static Obj * Find(Obj * pobjRoot, const Key & key); + +private: + // Inserts a node in the tree rooted at *ppobjRoot, sorting it based on key. + void Insert(Obj ** ppobjRoot, const Key & key); +}; + +#endif // !BINTREE_H_INCLUDED + diff --git a/Build/source/libs/graphite-engine/include/graphite/FileFont.h b/Build/source/libs/graphite-engine/include/graphite/FileFont.h new file mode 100644 index 00000000000..cffef0b79bc --- /dev/null +++ b/Build/source/libs/graphite-engine/include/graphite/FileFont.h @@ -0,0 +1,259 @@ +/*--------------------------------------------------------------------*//*:Ignore this sentence. +Copyright (C) 1999, 2001, 2005 SIL International. All rights reserved. + +Distributable under the terms of either the Common Public License or the +GNU Lesser General Public License, as specified in the LICENSING.txt file. + +File: XftFont.h +Responsibility: Keith Stribley +Last reviewed: Not yet. + +Description: + A Font is an object that represents a font-family + bold + italic setting, that contains + Graphite tables. +----------------------------------------------------------------------------------------------*/ +#ifndef FILEFONT_INCLUDED +#define FILEFONT_INCLUDED +#include "Font.h" + + +//:End Ignore + + +namespace gr +{ + +class FontTableCache; +class GrEngine; +/*----------------------------------------------------------------------------- + Stock implementation of an Xft font class. +------------------------------------------------------------------------------*/ +/** +* An implementation of the Graphite gr::Font class for Xft fonts for use on +* systems using X. Freetype is used to retrieve font information. +* If you are using Freetype directly, without Xft, you can pass in a FT_Face +* directly. +*/ +class FileFont : public Font +{ +public: + /** + * The main user constructor. Constructs the font from the supplied FILE pointer. + * @param file the FILE pointer to initialise from (must not be null) + */ + FileFont(FILE * file, float pointSize, unsigned int DPIx, unsigned int DPIy = 0); + + /** + * Alternative user constructor. Constructs the font from the supplied filename. + * @param filename character array + */ + FileFont(char * filename, float pointSize, unsigned int DPIx, unsigned int DPIy = 0); + + /** + * Alternative user constructor. Constructs the font from the supplied filename. + * @param filename as a string + */ + FileFont(std::string filename, float pointSize, + unsigned int DPIx, unsigned int DPIy = 0); + + + /** + * Destructor - cleans up the tables that it has allocated if all other copies + * of this font have been deleted. + */ + virtual ~FileFont(); + + /** + * Returns a copy of the recipient. Specifically needed to store the Font + * in a segment. + * @internal + */ + virtual Font * copyThis(); + + /** + * Copy constructor - note the tables are shared between the copy and the + * original font for efficiency reasons. + * The last copy to be deleted will delete the tables. + * @param font the XftGrFont object to copy from. + * @internal + */ + FileFont(const FileFont & font, float pointSize = 0, unsigned int DPIx = 0, unsigned int DPIy = 0); + + //virtual FontErrorCode isValidForGraphite(int * pnVersion = NULL, int * pnSubVersion = NULL); + /** + * Returns a pointer to the start of a table in the font. The ftblid32 type + * is a 32-bit unsigned integer. + * 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 one of the expected ones (cmap, head, name, Sile, + * Silf, Feat, Gloc, Glat). [If we want to be able to read “non-standard” + * tables, then the caller needs to be responsible for freeing the memory.] + */ + virtual const void * getTable(fontTableId32 tableID, size_t * pcbSize); + + /** + * Returns the basic metrics of the font. It corresponds to the current + * GrGraphics::get_FontAscent, get_FontDescent and GetFontEmSquare methods. + * @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); + + /** + * Returns true if the given arguments specify a font that contains Graphite + * tables—specfically a “Silf” table. + * @param xftFont XftFont pointer + * @return true if this font has the silf table + */ + bool fontHasGraphiteTables(); + + /** + * Returns true if the given arguments specify a font that contains Graphite + * tables—specfically a “Silf” table. + * @param xftFont XftFont pointer + * @return true if this font has the silf table + */ + static bool FontHasGraphiteTables(FILE * file); + + /** + * Returns true if the given arguments specify a font that contains Graphite + * tables—specfically a “Silf” table. + * @param face FT_Face handle + * @return true if this font has the silf table + */ + static bool FontHasGraphiteTables(char * filename); + + // Temporary, until interface gets thoroughly reworked: + GrEngine * GraphiteEngine(); + + /** + * Returns the font ascent in pixels. Using floating point allows us to + * avoid rounding errors. + * Value is the same as that returned by getFontMetrics() + * @return the font ascent + */ + virtual float ascent() + { + float pixAscent; + getFontMetrics(&pixAscent); + return pixAscent; + } + /** + * Returns the font descent in pixels with a positive sign. + * Value is the same as that returned by getFontMetrics() + * @return the font descent in pixels. + */ + virtual float descent() + { + float pixDescent; + getFontMetrics(NULL, &pixDescent); + return pixDescent; + } + /** + * Returns the total height of the font. + * Equivalent to ascent() + descent(). + * @return font height + */ + virtual float height() + { + float pixAscent; + float pixDescent; + getFontMetrics(&pixAscent, &pixDescent); + return (pixAscent + pixDescent); + } + /** + * @return true if the font is a bold styled one. + */ + virtual bool bold() + { + return m_fBold; + } + /** + * @return true if the font is italic + */ + virtual bool italic() + { + return m_fItalic; + } + /** @return the DPI for the x-axis. + */ + virtual unsigned int getDPIx() + { + return m_dpiX; + } + /** @return Returns the DPI for the y-axis. + */ + virtual unsigned int getDPIy() + { + return m_dpiY; + } + // Specific to XftGrFont: + + /** @return set the DPI for the x-axis. + */ + virtual void setDPIx(unsigned int dpi) + { + m_dpiX = dpi; + m_xScale = scaleFromDpi(dpi); + } + /** @return set the DPI for the y-axis. + */ + virtual void setDPIy(unsigned int dpi) + { + m_dpiY = dpi; + m_yScale = scaleFromDpi(dpi); + } + + bool isValid() { return m_isValid; }; +protected: + /** Default constructor is not used */ + FileFont(); + /** + * Common initialisation between the XftFont and FT_Face constructors. + */ + void initializeFromFace(void); + // this uses an int to avoid having to include TtfUtil.h in the include + // directory + byte * readTable(int /*TableId*/ tableId, size_t & size); + + // pixels-per-em = dpi * point-size / 72 + // pixel-coord = design-coord * pixels-per-em / font-em-square + float scaleFromDpi(int dpi) + { + return (dpi * m_pointSize) / (72.0f * m_emSquare); + } + // Member variables: + FILE *m_file; + + unsigned long m_clrFore; + unsigned long m_clrBack; + bool m_fBold; + bool m_fItalic; + // font table caches: + FontTableCache * m_pTableCache; + + // KRS: I think these should be cached otherwise Segment::LineContextSegment doesn't work + float m_ascent; + float m_descent; + float m_emSquare; + float m_pointSize; + int m_dpiX; + int m_dpiY; + bool m_isValid; + std::wstring m_faceName; + byte * m_pHeader; + byte * m_pTableDir; + float m_xScale; + float m_yScale; +}; + + +} // namespace gr + +#endif + diff --git a/Build/source/libs/graphite-engine/include/graphite/Font.h b/Build/source/libs/graphite-engine/include/graphite/Font.h new file mode 100644 index 00000000000..ef8fead89ec --- /dev/null +++ b/Build/source/libs/graphite-engine/include/graphite/Font.h @@ -0,0 +1,399 @@ +/*--------------------------------------------------------------------*//*:Ignore this sentence. +Copyright (C) 1999, 2001 SIL International. All rights reserved. + +Distributable under the terms of either the Common Public License or the +GNU Lesser General Public License, as specified in the LICENSING.txt file. + +File: Font.h +Responsibility: Sharon Correll +Last reviewed: Not yet. + +Description: + A Font is an object that represents a font-family + bold + italic setting, that contains + Graphite tables. This file also includes related iterators: FeatureIterator, + FeatureSettingIterator, FeatLabelLangIterator, LanguageIterator. +----------------------------------------------------------------------------------------------*/ +#ifdef _MSC_VER +#pragma once +#endif +#ifndef FONT_INCLUDED +#define FONT_INCLUDED + +//:End Ignore + +namespace gr +{ + +class Font; +class FontFace; +class FeatureSettingIterator; +class Segment; +class LayoutEnvironment; +class ITextSource; + +typedef struct tagFontProps +{ + unsigned long clrFore; + unsigned long clrBack; + bool fBold; + bool fItalic; + float pixHeight; + wchar_t szFaceName[ 32 ]; +} FontProps; + + +/*---------------------------------------------------------------------------------------------- + A FontError object is an exception that is thrown when there is an error in initializing + a Graphite font. +----------------------------------------------------------------------------------------------*/ +struct FontException +{ + FontErrorCode errorCode; + int version; + int subVersion; +}; + +/*---------------------------------------------------------------------------------------------- + Iterator to provide access to a font's features. +----------------------------------------------------------------------------------------------*/ +class FeatureIterator +{ + friend class Font; + friend class FeatureSettingIterator; + +public: + FeatureIterator() // needed for creating std::pair of these, and for default FSI + { + m_pfont = NULL; + m_ifeat = 0; + m_cfeat = 0; + } + +protected: + FeatureIterator(Font * pfont, int ifeat, size_t cfeat) + { + m_pfont = pfont; + m_ifeat = ifeat; + m_cfeat = cfeat; + } +public: + featid operator*(); + FeatureIterator operator++(); + FeatureIterator operator+=(int n); + bool operator==(FeatureIterator &); + bool operator!=(FeatureIterator &); + int operator-(FeatureIterator &); + +protected: + Font * m_pfont; + size_t m_ifeat; // feature being pointed at + size_t m_cfeat; // number of features for this font + + FeatureSettingIterator BeginSetting(); + FeatureSettingIterator EndSetting(); +}; + +/*---------------------------------------------------------------------------------------------- + Iterator to provide access to the defined values for a single font feature. +----------------------------------------------------------------------------------------------*/ +class FeatureSettingIterator +{ + friend class Font; + friend class FeatureIterator; + +public: + FeatureSettingIterator() // needed for creating std::pair of these, I think + { + m_ifset = 0; + m_cfset = 0; + } +protected: + FeatureSettingIterator(FeatureIterator fit, int ifset, size_t cfset) + { + m_fit = fit; + m_ifset = ifset; + m_cfset = cfset; + } +public: + int operator*(); + FeatureSettingIterator operator++(); + FeatureSettingIterator operator +=(int n); + bool operator==(FeatureSettingIterator &); + bool operator!=(FeatureSettingIterator &); + int operator-(FeatureSettingIterator); + +protected: + FeatureIterator m_fit; + size_t m_ifset; // which setting being pointed at + size_t m_cfset; // number of settings for this feature +}; + +/*---------------------------------------------------------------------------------------------- + Iterator to provide access to the languages available for the feature label strings. +----------------------------------------------------------------------------------------------*/ +class FeatLabelLangIterator +{ + friend class Font; + +public: + FeatLabelLangIterator() // needed for creating std::pair of these, and for default FSI + { + m_pfont = NULL; + m_ilang = 0; + m_clang = 0; + } + +protected: + FeatLabelLangIterator(Font * pfont, int ilang, size_t clang) + { + m_pfont = pfont; + m_ilang = ilang; + m_clang = clang; + } +public: + data16 operator*(); + FeatLabelLangIterator operator++(); + FeatLabelLangIterator operator+=(int n); + bool operator==(FeatLabelLangIterator &); + bool operator!=(FeatLabelLangIterator &); + int operator-(FeatLabelLangIterator &); + +protected: + Font * m_pfont; + size_t m_ilang; // language being pointed at + size_t m_clang; // number of languages for this font +}; + +/*---------------------------------------------------------------------------------------------- + Iterator to provide access to a font's defined languages--ie, those that have feature + settings associated with them. +----------------------------------------------------------------------------------------------*/ +class LanguageIterator +{ + friend class Font; + +public: + LanguageIterator() // needed for creating std::pair of these, and for default FSI + { + m_pfont = NULL; + m_ilang = 0; + m_clang = 0; + } + +protected: + LanguageIterator(Font * pfont, int ilang, size_t clang) + { + m_pfont = pfont; + m_ilang = ilang; + m_clang = clang; + } +public: + isocode operator*(); // returns a 4-char array + LanguageIterator operator++(); + LanguageIterator operator+=(int n); + bool operator==(LanguageIterator &); + bool operator!=(LanguageIterator &); + int operator-(LanguageIterator &); + +protected: + Font * m_pfont; + size_t m_ilang; // language being pointed at + size_t m_clang; // number of languages for this font +}; + +/*---------------------------------------------------------------------------------------------- + Abstract superclass for Graphite fonts. A font represents a face name, size, and bold and + italic styles. +----------------------------------------------------------------------------------------------*/ +class Font { + + friend class FeatureIterator; + friend class FeatureSettingIterator; + friend class FeatLabelLangIterator; + friend class LanguageIterator; + +public: + virtual ~Font(); + + /** + * Returns a copy of the recipient. Specifically needed to store the + * Font in a segment. + * @internal + * @return pointer to copy + */ + virtual Font * copyThis() = 0; + + /** + * Return wether the font is bold. + * @return true when bold + */ + virtual bool bold() = 0; + /** + * Return wether the font is italic. + * @return true when italic + */ + virtual bool italic() = 0; + + /** + * Returns the slope of the italic (if the font is italic) + * @return ratio of slope from the vertical + */ + virtual float fakeItalicRatio() { return 0; } // no support for fake italic + + /** + * Returns the font ascent. + * Value is the same as that returned by getFontMetrics() + * @return the font ascent in device co-ordinates + */ + virtual float ascent() = 0; + + /** + * Returns the font descent. + * Value is the same as that returned by getFontMetrics() + * @return the font descent in device co-ordinates + */ + virtual float descent() = 0; + + /** + * Returns the total height of the font. + * @return font height in device co-ordinates + */ + virtual float height() = 0; + + /** + * Returns the x and y resolution of the device co-ordinate space. + */ + virtual unsigned int getDPIx() = 0; + virtual unsigned int getDPIy() = 0; + + /** + * 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 as a 32-bit long in native machine byte order + * @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(fontTableId32 tableID, size_t * pcbSize) = 0; + /** + * 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) = 0; + /** + * Converts the point number of a glyph’s on-curve point to a pair of + * x/y coordinates in pixels. The default implementation will read the + * curve information directly from the font and perform a simple + * transformation to pixels. Some subclasses (e.g., WinFont) will use + * a system-level API call to return hinted metrics. + * Note that the coordinates returned are floating point values in the + * device co-ordinate space (normaly pixels). + * @param gid glyph id + * @param pointNum within glyph + * @param xyReturn reference to a Point object to hold the x,y result + */ + virtual void getGlyphPoint(gid16 glyphID, unsigned int pointNum, gr::Point & pointReturn); + + /** + * Returns the metrics of a glyph in the font. The default + * implementation will read the information directly from the font and + * perform a simple transformation to pixels. Some subclasses (e.g., + * WinFont) will use a system-level API call to return hinted metrics. + * Note that the coordinates returned are floating point values in the + * device co-ordinate space (normaly pixels). + * @param glyphID + * @param boundingBox reference to gr::Rect to hold bounding box of glyph + * @param advances refererence to gr::Point to hold the horizontal / vertical advances + */ + virtual void getGlyphMetrics(gid16 glyphID, gr::Rect & boundingBox, gr::Point & advances); + + static void SetFlushMode(int); + static int GetFlushMode(); + + // obsolete: + //virtual FontErrorCode isValidForGraphite(int * pnVersion = NULL, int * pnSubVersion = NULL) = 0; + + // Features: + std::pair<FeatureIterator, FeatureIterator> getFeatures(); + FeatureIterator featureWithID(featid id); + bool getFeatureLabel(FeatureIterator, lgid language, utf16 * label); + FeatureSettingIterator getDefaultFeatureValue(FeatureIterator); + std::pair<FeatureSettingIterator, FeatureSettingIterator> getFeatureSettings(FeatureIterator); + bool getFeatureSettingLabel(FeatureSettingIterator, lgid language, utf16 * label); + + std::pair<FeatLabelLangIterator, FeatLabelLangIterator> getFeatureLabelLanguages(); + + // Languages: + std::pair<LanguageIterator, LanguageIterator> getSupportedLanguages(); + + // Script directions, Verticle, LTR, RTL etc see enum ScriptDirCode + // the posibilities. This returns a bit set where more than one scripts may + // be set, it's up to the app to decide which is the prefered direction to use. + ScriptDirCode getSupportedScriptDirections() const throw(); + + // Debugging: + //static bool DbgCheckFontCache(); + +public: + // For use in segment creation: + void RenderLineFillSegment(Segment * pseg, ITextSource * pts, LayoutEnvironment & layout, + toffset ichStart, toffset ichStop, float xsMaxWidth, bool fBacktracking); + void RenderRangeSegment(Segment * pseg, ITextSource * pts, LayoutEnvironment & layout, + toffset ichStart, toffset ichEnd); + void RenderJustifiedSegment(Segment * pseg, ITextSource * pts, LayoutEnvironment & layout, + toffset ichStart, toffset ichEnd, float xsCurrentWidth, float xsDesiredWidth); + +protected: + Font(); + Font(const Font &); + + FontFace & fontFace(); + + // Feature access: + FeatureIterator BeginFeature(); + FeatureIterator EndFeature(); + + size_t NumberOfFeatures(); + featid FeatureID(size_t ifeat); + size_t FeatureWithID(featid id); + bool GetFeatureLabel(size_t ifeat, lgid language, utf16 * label); + int GetFeatureDefault(size_t ifeat); + size_t NumberOfSettings(size_t ifeat); + int GetFeatureSettingValue(size_t ifeat, size_t ifset); + bool GetFeatureSettingLabel(size_t ifeat, size_t ifset, lgid language, utf16 * label); + + // Feature-label languages: + FeatLabelLangIterator BeginFeatLang(); + FeatLabelLangIterator EndFeatLang(); + + size_t NumberOfFeatLangs(); + short FeatLabelLang(size_t ilang); + + // Language access: + LanguageIterator BeginLanguage(); + LanguageIterator EndLanguage(); + + size_t NumberOfLanguages(); + isocode LanguageCode(size_t ilang); + + virtual void UniqueCacheInfo(std::wstring & stuFace, bool & fBold, bool & fItalic); + +private: + FontFace * m_pfface; // set up with Graphite tables + void initialiseFontFace(); +}; + +inline Font::Font() : m_pfface(0) { } + +} // namespace gr + + +#endif // !FONT_INCLUDED diff --git a/Build/source/libs/graphite-engine/include/graphite/GenericResource.h b/Build/source/libs/graphite-engine/include/graphite/GenericResource.h new file mode 100644 index 00000000000..119c6317bcd --- /dev/null +++ b/Build/source/libs/graphite-engine/include/graphite/GenericResource.h @@ -0,0 +1,86 @@ +/*--------------------------------------------------------------------*//*:Ignore this sentence. +Copyright (C) 1999, 2001 SIL International. All rights reserved. + +Distributable under the terms of either the Common Public License or the +GNU Lesser General Public License, as specified in the LICENSING.txt file. + +File: GenericResource.h +Responsibility: John Thomson +Last reviewed: + + Resources needed by certain generic components (but must be created in app's or AppCore's + resource file). +----------------------------------------------------------------------------------------------*/ +#ifdef _MSC_VER +#pragma once +#endif +#ifndef GenericResource_H +#define GenericResource_H 1 +// Create suitable resources for these if your app uses StackDumper. +// For example +// STRINGTABLE DISCARDABLE +// BEGIN +// "A programming error (%s) has been detected in module %s.\n Please report this to the developers", kstidInternalError +// "Out of memory. To attempt Save, close other apps and click OK. To quit without saving click Cancel", kstidOutOfMemory +// END + + +// Date qualifier string IDs: +#define kstidDateQualBefore 24200 +#define kstidDateQualOn 24201 +#define kstidDateQualAbout 24202 +#define kstidDateQualAfter 24203 +#define kstidDateQualAbt 24204 +#define kstidDateQualBC 24205 +#define kstidDateQualAD 24206 +#define kstidDateBlank 24207 +#define kstidDateBlankM 24208 +#define kstidDateBlankD 24209 + + +#define kstidInternalError 25900 +#define khcidHelpOutOfMemory 25901 +#define khcidNoHelpAvailable 25902 // default help module when there is no specific one. +#define kstidOutOfMemory 25903 +#define kstidUndoFrame 25904 +#define kstidRedoFrame 25905 + +#define kstidFileErrUnknown 25920 +#define kstidFileErrNotFound 25921 +#define kstidFileErrPathNotFound 25922 +#define kstidFileErrTooManyFiles 25923 +#define kstidFileErrAccDenied 25924 +#define kstidFileErrBadHandle 25925 +#define kstidFileErrBadDrive 25926 +#define kstidFileErrWriteProtect 25927 +#define kstidFileErrBadUnit 25928 +#define kstidFileErrNotReady 25929 +#define kstidFileErrSeek 25930 +#define kstidFileErrNotDosDisk 25931 +#define kstidFileErrBadSector 25932 +#define kstidFileErrWriteFault 25933 +#define kstidFileErrReadFault 25934 +#define kstidFileErrGeneral 25935 +#define kstidFileErrSharing 25936 +#define kstidFileErrLock 25937 +#define kstidFileErrEof 25938 +#define kstidFileErrHandleDiskFull 25939 +#define kstidFileErrBadNetPath 25940 +#define kstidFileErrNetworkBusy 25941 +#define kstidFileErrNoDevice 25942 +#define kstidFileErrNoNetAccess 25943 +#define kstidFileErrBadDevice 25944 +#define kstidFileErrBadNetName 25945 +#define kstidFileErrExists 25946 +#define kstidFileErrCantMake 25947 +#define kstidFileErrBadPassword 25948 +#define kstidFileErrNetWriteFault 25949 +#define kstidFileErrDriveLocked 25950 +#define kstidFileErrOpenFailed 25951 +#define kstidFileErrBufOverflow 25952 +#define kstidFileErrDiskFull 25953 +#define kstidFileErrBadName 25954 +#define kstidFileErrNoVolLabel 25955 +#define kstidFileErrAlreadyExists 25956 + +#endif // !GenericResource_H diff --git a/Build/source/libs/graphite-engine/include/graphite/GrAppData.h b/Build/source/libs/graphite-engine/include/graphite/GrAppData.h new file mode 100644 index 00000000000..3a2024b8a10 --- /dev/null +++ b/Build/source/libs/graphite-engine/include/graphite/GrAppData.h @@ -0,0 +1,39 @@ +/*--------------------------------------------------------------------*//*:Ignore this sentence. +Copyright (C) 1999, 2001 SIL International. All rights reserved. + +Distributable under the terms of either the Common Public License or the +GNU Lesser General Public License, as specified in the LICENSING.txt file. + +File: GrAppData.h +Responsibility: Sharon Correll +Last reviewed: not yet + +Description: + Data structures need by applications that use the Graphite engine. +----------------------------------------------------------------------------------------------*/ + + +#ifndef GRAPPDATA_INCLUDED +#define GRAPPDATA_INCLUDED + +#include "GrData.h" + +namespace gr +{ + +typedef unsigned int featid; // font feature IDs +typedef unsigned int lgid; // language ID (for access feature UI strings) +typedef unsigned int toffset; // text-source index + +typedef struct { // ISO-639-3 language code (for mapping onto features) + char rgch[4]; +} isocode; + +} // namespace gr + +#if defined(GR_NO_NAMESPACE) +using namespace gr; +#endif + +#endif // GRAPPDATA_INCLUDED + diff --git a/Build/source/libs/graphite-engine/include/graphite/GrClient.h b/Build/source/libs/graphite-engine/include/graphite/GrClient.h new file mode 100644 index 00000000000..0ef5127c81a --- /dev/null +++ b/Build/source/libs/graphite-engine/include/graphite/GrClient.h @@ -0,0 +1,39 @@ +#ifndef GR_CLIENT_H +#define GR_CLIENT_H + +#include "GrCommon.h" +#include "GrConstants.h" + +#define __RPC_FAR + +namespace gr +{ + +// These are internal classes, whose forward declarations are needed to allow the public interfaces +// to compile but are not intended for client use. +class GrSlotState; +class GrSlotStream; +class GrGlyphTable; +class GrClassTable; +class GrTableManager; +class GrPseudoMap; +class GrFileIStream; +class GrSlotOutput; +class GrCharStream; +class GrIStream; + +// Forward declarations of client APIs and classes. +class Segment; +} + +#include "GrAppData.h" +#include "GrResult.h" +#include "GrFeature.h" + + +#if defined(GR_NO_NAMESPACE) +using namespace gr; +#endif + +#endif //GR_CLIENT_H + diff --git a/Build/source/libs/graphite-engine/include/graphite/GrCommon.h b/Build/source/libs/graphite-engine/include/graphite/GrCommon.h new file mode 100644 index 00000000000..8bb5728ecb3 --- /dev/null +++ b/Build/source/libs/graphite-engine/include/graphite/GrCommon.h @@ -0,0 +1,145 @@ +/*--------------------------------------------------------------------*//*:Ignore this sentence. +Copyright (C) 1999, 2001, 2003 SIL International. All rights reserved. + +Distributable under the terms of either the Common Public License or the +GNU Lesser General Public License, as specified in the LICENSING.txt file. + +File: GrCommon.h +Responsibility: Sharon Correll +Last reviewed: + + Common generic header file. + + This header file checks for the following compile time switches: + + USING_MFC +----------------------------------------------------------------------------------------------*/ + +#ifndef GRCOMMON_INCLUDED +#define GRCOMMON_INCLUDED + + +// Standard Headers. + +#include <cstdlib> +#include <cstdio> +#include <cstdarg> +#include <climits> +//#include <exception> +#include <new> + +#include <fstream> +#include <iostream> +#include <vector> +#include <algorithm> +#include <string> + +// Uncomment this to allow multiple versions of gr to coexist +// in the same program e.g. pangographite with gtk uses namespace gr +// mozilla graphite defines this to gr2moz incase the 2 libraries are +// incompatible. +// Provided the client includes GrClient.h first this #define is +// picked up by all files. + +//#define gr gr2 + +// Project headers +#include "GrPlatform.h" + +#ifndef GrAssert +#include <cassert> +#define GrAssert(exp) assert(exp) +#endif + +using std::max; +using std::min; + +namespace gr +{ + + +/*********************************************************************************************** + Simple types. +***********************************************************************************************/ +typedef char schar; + +// TODO ShonK: Make generic use these where appropriate. +#ifdef UNICODE +typedef utf16 achar; +#else // !UNICODE +typedef schar achar; +#endif // UNICODE + +typedef achar *Psz; +//typedef const achar * Pcsz; + + + +// This is to make a signed isizeof operator, otherwise we get tons of warnings about +// signed / unsigned mismatches. +#define isizeof(T) (sizeof(T)) + +#define SizeOfArray(rgt) (isizeof(rgt) / isizeof(rgt[0])) + + +/*********************************************************************************************** + Tests for valid strings and pointers. +***********************************************************************************************/ +inline bool ValidPsz(const data16 *pszw) +{ + // TODO ShonK: Determine if IsBadStringPtrW is implemented on Win9x. + return pszw != 0 && !GrIsBadStringPtrW(pszw, 0x10000000); +} + +inline bool ValidPsz(const schar *pszs) +{ + return pszs != 0 && !GrIsBadStringPtrA(pszs, 0x10000000); +} + +template<typename T> inline bool ValidReadPtr(T *pt) +{ + return pt != 0 && !GrIsBadReadPtr(pt, isizeof(T)); +} + +template<typename T> inline bool ValidWritePtr(T *pt) +{ + return pt != 0 && !GrIsBadWritePtr(pt, isizeof(T)); +} + +inline bool ValidReadPtrSize(const void *pv, int cb) +{ + if (cb < 0) return false; + if (cb == 0) return true; + + return pv != 0 && !GrIsBadReadPtr(pv, cb); +} + +inline bool ValidWritePtrSize(void *pv, int cb) +{ +// if (!bstr || ::IsBadReadPtr((byte *)bstr - isizeof(int), isizeof(int) + isizeof(OLECHAR))) +// return false; +// int cb = ((int *)bstr)[-1]; +// if (::IsBadReadPtr((byte *)bstr - isizeof(int), isizeof(int) + isizeof(OLECHAR) + cb)) +// return false; + if (cb < 0) return false; + if (cb == 0) return true; + + return pv != 0 && !GrIsBadWritePtr(pv, cb); +} + + +} // namespace gr + + +// TODO Remove these as soon as they are no longer needed by GrCompiler: +//#include "UtilMem.h" +//#include "UtilRect.h" +//#include "UtilString.h" +//#include "UtilVector.h" + +#if defined(GR_NO_NAMESPACE) +using namespace gr; +#endif + +#endif // !GRCOMMON_INCLUDED + diff --git a/Build/source/libs/graphite-engine/include/graphite/GrConstants.h b/Build/source/libs/graphite-engine/include/graphite/GrConstants.h new file mode 100644 index 00000000000..16ddc787beb --- /dev/null +++ b/Build/source/libs/graphite-engine/include/graphite/GrConstants.h @@ -0,0 +1,268 @@ +/*--------------------------------------------------------------------*//*:Ignore this sentence. +Copyright (C) 1999, 2001 SIL International. All rights reserved. + +Distributable under the terms of either the Common Public License or the +GNU Lesser General Public License, as specified in the LICENSING.txt file. + +File: constants.h +Responsibility: Sharon Correll +Last reviewed: Not yet. + +Description: + Various global constants. +----------------------------------------------------------------------------------------------*/ +#ifdef _MSC_VER +#pragma once +#endif +#ifndef GRCONSTANTS_INCLUDED +#define GRCONSTANTS_INCLUDED + +//:End Ignore + +namespace gr +{ + +// Maximum table versions handled by this engine: +enum { + + kSilfVersion = 0x00030000, + kRuleVersion = 0x00030000, + kGlatVersion = 0x00010000, + kGlocVersion = 0x00010000, + kFeatVersion = 0x00020000, + kSileVersion = 0x00010000, + kSillVersion = 0x00010000 + +}; + +enum { + + kMaxFeatures = 64, + kMaxComponentsPerGlyph = 32, + kFieldsPerComponent = 4, + kMaxSlotsPerRule = 64, + kMaxSubTablesInFont = 256, + kMaxUserDefinableSlotAttrs = 64, + kMaxJLevels = 4 + +}; + +// Maxima permitted by the binary format of the TrueType tables. +enum { + + kMaxSubTables = 256, + kMaxRenderingBehavior = 65536, // ie, the maximum value allowed for an ID + kMaxGlyphAttrs = 65536, // Gloc table + kMinGlyphAttrValue =-32768, + kMaxGlyphAttrValue = 32768, + kMaxPasses = 128, // Sil_sub table allows 256 + kMaxPseudos = 65536, + kMaxRendBehaviors = 256, + kMaxReplcmtClasses = 65536, // Class map + kMaxReplcmtClassesV1_2 = 256, + kMaxComponents = 16383 + +}; + + +enum { + + kPosInfinity = 0x3FFFFFF, + kNegInfinity = kPosInfinity * -1, + + kInvalid = kNegInfinity + +}; + +#define kPosInfFloat (float)kPosInfinity +#define kNegInfFloat (float)kNegInfinity + + +enum { + kGpointZero = -2 +}; + + +// for stream processing +enum { + kBacktrack = -2, + kNextPass = -1 +}; + + +// internal justification modes +enum { + kjmodiNormal = 0, + kjmodiMeasure, + kjmodiJustify, + kjmodiCanShrink // like normal, but shrinking is possible +}; + + +enum DirCode { // Hungarian: dirc + + kdircUnknown = -1, + kdircNeutral = 0, // other neutrals (default) - ON + kdircL = 1, // left-to-right, strong - L + kdircR = 2, // right-to-left, strong - R + kdircRArab = 3, // Arabic letter, right-to-left, strong, AR + kdircEuroNum = 4, // European number, left-to-right, weak - EN + kdircEuroSep = 5, // European separator, left-to-right, weak - ES + kdircEuroTerm = 6, // European number terminator, left-to-right, weak - ET + kdircArabNum = 7, // Arabic number, left-to-right, weak - AN + kdircComSep = 8, // Common number separator, left-to-right, weak - CS + kdircWhiteSpace = 9, // white space, neutral - WS + kdircBndNeutral = 10, // boundary neutral - BN + + kdircLRO = 11, // LTR override + kdircRLO = 12, // RTL override + kdircLRE = 13, // LTR embedding + kdircRLE = 14, // RTL embedding + kdircPDF = 15, // pop directional format + + // I think we need this too: + kdircNSM = 16, // non-space mark + + // Special values for internal use: + kdircLlb = 32, // left-to-right line-break + kdircRlb = 33, // right-to-left line-break + kdircPdfL = 34, // PDF marker matching an LRO or LRE + kdircPdfR = 35 // PDF marker matching an RLO or RLE + +}; + + +bool StrongDir(DirCode dirc); +bool WeakDir(DirCode dirc); +bool NeutralDir(DirCode dirc); +bool RightToLeftDir(DirCode dirc); + + +// Unicode characters with special treatments +enum DefinedChars { + + knSpace = 0x0020, // space + knHyphen = 0x002D, // hyphen + + knTab = 0x0009, // tab (horizontal) + knLF = 0x000A, // line feed + knCR = 0x000D, // carriage return + knLineSep = 0x2028, // line separator (soft return) + knParaSep = 0x2029, // paragraph separator + + knLRM = 0x200E, // left-to-right mark + knRLM = 0x200F, // right-to-left mark + knLRE = 0x202A, // left-to-right embedding + knRLE = 0x202B, // right-to-left embedding + knPDF = 0x202C, // pop directional format + knLRO = 0x202D, // left-to-right override + knRLO = 0x202E, // right-to-left override + + knORC = 0xFFFC // Object Replacement Character +}; + +bool BidiCode(int nUnicode); + + +typedef enum SpecialSlots { + + kspslNone = 0, + + kspslLbInitial = 1, + kspslLbFinal = 2, + + kspslLRM = 3, + kspslRLM = 4, + kspslLRO = 5, + kspslRLO = 6, + kspslLRE = 7, + kspslRLE = 8, + kspslPDF = 9 + +} SpecialSlots; + + +// version 1.0 breakweights +enum BreakWeightsV1 +{ + klbv1WordBreak = 1, + klbv1HyphenBreak = 2, + klbv1LetterBreak = 3, + klbv1ClipBreak = 4 +}; + + +typedef enum SlotAttrName { + + kslatAdvX = 0, kslatAdvY, + kslatAttTo, + kslatAttAtX, kslatAttAtY, kslatAttAtGpt, + kslatAttAtXoff, kslatAttAtYoff, + kslatAttWithX, kslatAttWithY, kslatAttWithGpt, + kslatAttWithXoff, kslatAttWithYoff, + kslatAttLevel, + kslatBreak, + kslatCompRef, + kslatDir, + kslatInsert, + kslatPosX, kslatPosY, + kslatShiftX, kslatShiftY, + kslatUserDefnV1, // version 1.0 of the font tables + kslatMeasureSol, kslatMeasureEol, + kslatJStretch, kslatJShrink, kslatJStep, kslatJWeight, kslatJWidth, + // this must be last: + kslatUserDefn = kslatJStretch + 30, + // I think 30 is somewhat arbitrary. We at least need to save 15 slots for more levesl of + // justification attributes. + + kslatMax, + + kslatNoEffect = kslatMax + 1 // for internal use +} SlotAttrName; + + +typedef enum GlyphMetric { + kgmetLsb = 0, kgmetRsb, + kgmetBbTop, kgmetBbBottom, kgmetBbLeft, kgmetBbRight, + kgmetBbHeight, kgmetBbWidth, + kgmetAdvWidth, kgmetAdvHeight, + kgmetAscent, kgmetDescent +} GlyphMetric; + + +enum ProcessStates +{ + kpstatJustifyMode = 1, + kpstatJustifyLevel = 2 +}; + +// user justification modes: these must match the values in stddef.gdh +enum JustifyModes +{ + kjmoduNormal = 0, + kjmoduMeasure = 1, + kjmoduJustify = 2 +}; + +enum TruetypeTableId { + kttiCmap = 0x636D6170, + kttiFeat = 0x46656174, + kttiGlat = 0x476C6174, + kttiGloc = 0x476C6F63, + kttiGlyf = 0x676C7966, + kttiHead = 0x68656164, + kttiHhea = 0x68686561, + kttiHmtx = 0x686D7478, + kttiLoca = 0x6C6F6361, + kttiMaxp = 0x6D617870, + kttiName = 0x6E616D65, + kttiOs2 = 0x4F532F32, + kttiPost = 0x706F7374, + kttiSile = 0x53696C65, + kttiSilf = 0x53696C66, + kttiSill = 0x53696C6C +}; + +} // namespace gr + +#endif // CONSTANTS_INCLUDED diff --git a/Build/source/libs/graphite-engine/include/graphite/GrData.h b/Build/source/libs/graphite-engine/include/graphite/GrData.h new file mode 100644 index 00000000000..3624ca9c271 --- /dev/null +++ b/Build/source/libs/graphite-engine/include/graphite/GrData.h @@ -0,0 +1,226 @@ +/*--------------------------------------------------------------------*//*:Ignore this sentence. +Copyright (C) 1999, 2001 SIL International. All rights reserved. + +Distributable under the terms of either the Common Public License or the +GNU Lesser General Public License, as specified in the LICENSING.txt file. + +File: GrData.h +Responsibility: Sharon Correll +Last reviewed: Not yet. + +Description: + Data structures needed by the Graphite engine, particularly for argument passing. + NOT to be used within FieldWorks. + +Special Note: + This file needs to be used by C files. Please do not use C++ style comments; use + ONLY C style comments in this file to make the C compiler happy. +----------------------------------------------------------------------------------------------*/ +#ifdef _MSC_VER +#pragma once +#endif +#ifndef GRDATA_INCLUDED +#define GRDATA_INCLUDED + +#include "GrCommon.h" + +/* +//:End Ignore + */ + +#include "GrStructs.h" + +namespace gr +{ + +struct Point +{ + float x; + float y; + + Point() + { + x = y = 0; + } + +#if defined(_WIN32) + Point(POINT & p) + { + x = (float)p.x; + y = (float)p.y; + } +#endif +}; + + +struct Rect +{ + float top; + float bottom; + float left; + float right; + + Rect() + { + top = bottom = left = right = 0; + }; + +#if defined(_WIN32) + Rect(RECT & r) + { + top = (float)r.top; + bottom = (float)r.bottom; + left = (float)r.left; + right = (float)r.right; + }; +#endif +}; + +enum { + kttvOff = 0, + kttvForceOn = 1, + kttvInvert = 2 +}; + +//typedef struct tagLgParaRenderProps +//{ +// int dummy; +//} LgParaRenderProps; + +typedef enum tagSegEnd +{ kestNoMore = 0, + kestMoreLines = kestNoMore + 1, + kestHardBreak = kestMoreLines + 1, + kestBadBreak = kestHardBreak + 1, + kestOkayBreak = kestBadBreak + 1, + kestWsBreak = kestOkayBreak + 1, + kestMoreWhtsp = kestWsBreak + 1, + kestNothingFit = kestMoreWhtsp + 1 +} SegEnd; + +typedef enum tagLgIPDrawMode // TODO: remove +{ kdmNormal = 0, + kdmSplitPrimary = kdmNormal + 1, + kdmSplitSecondary = kdmSplitPrimary + 1 +} LgIPDrawMode; + +typedef enum tagLgIpValidResult +{ kipvrOK = 0, + kipvrBad = kipvrOK + 1, + kipvrUnknown = kipvrBad + 1 +} LgIpValidResult; + +typedef enum tagLineBrk +{ klbNoBreak = 0, + klbWsBreak = 10, + klbWordBreak = 15, + klbHyphenBreak = 20, + klbLetterBreak = 30, + klbClipBreak = 40 +} LineBrk; + +typedef enum tagTrWsHandling +{ ktwshAll = 0, + ktwshNoWs = ktwshAll + 1, + ktwshOnlyWs = ktwshNoWs + 1 +} TrWsHandling; + +typedef enum tagUtfType +{ + kutf8 = 0, + kutf16 = kutf8 + 1, + kutf32 = kutf16 + 1 +} UtfType; + +enum tagFlushMode +{ + kflushAuto = 0, + kflushManual = kflushAuto + 1 +}; + +typedef enum ScriptDirCode +{ kfsdcNone = 0, + kfsdcHorizLtr = 1, + kfsdcHorizRtl = 2, + kfsdcVertFromLeft = 4, + kfsdcVertFromRight = 8 +} ScriptDirCode; + +typedef enum tagFwTextColor +{ kclrWhite = 0xffffff, + kclrBlack = 0, + kclrRed = 0x0000ff, + kclrGreen = 0x00ff00, + kclrBlue = 0xff0000, +/* +// kclrYellow = 0x00ffff, +// kclrMagenta = 0xff00ff, +// kclrCyan = 0xffff00, + */ + kclrReserved1 = 0x80000000, + kclrReserved2 = 0x80000001, + kclrTransparent = 0xc0000000 +} FwTextColor; + + +typedef enum FwSuperscriptVal +{ kssvOff = 0, + kssvSuper = 1, + kssvSub = 2 +} FwSuperscriptVal; + + +// Glyph attributes for justification +typedef enum tagJustGlyphAttr +{ + kjgatStretch = 1, + kjgatShrink, + kjgatWeight, + kjgatStep, + kjgatChunk, + kjgatWidth, + kjgatBreak, + // pseudo-attributes for handling steps: + kjgatStretchInSteps, + kjgatWidthInSteps, + // also metrics: + kjgatAdvWidth, + kjgatAdvHeight, + kjgatBbLeft, + kjgatBbRight, + kjgatBbTop, + kjgatBbBottom +} JustGlyphAttr; // Hungarian: jgat + +class GrSlotState; +typedef union { + int nValue; + GrSlotState *pslot; +} u_intslot; + +/***** +#undef ATTACH_GUID_TO_CLASS +#if defined(__cplusplus) +#define ATTACH_GUID_TO_CLASS(type, guid, cls) \ + type __declspec(uuid(#guid)) cls; +#else // !defined(__cplusplus) +#define ATTACH_GUID_TO_CLASS(type, guid, cls) +#endif // !defined(__cplusplus) + +#ifndef DEFINE_COM_PTR +#define DEFINE_COM_PTR(cls) +#endif + +#undef GENERIC_DECLARE_SMART_INTERFACE_PTR +#define GENERIC_DECLARE_SMART_INTERFACE_PTR(cls, iid) \ + ATTACH_GUID_TO_CLASS(interface, iid, cls); \ + DEFINE_COM_PTR(cls); +*****/ + +} // namespace gr + +#if defined(GR_NO_NAMESPACE) +using namespace gr; +#endif + +#endif /* !GRDATA_INCLUDED */ diff --git a/Build/source/libs/graphite-engine/include/graphite/GrDebug.h b/Build/source/libs/graphite-engine/include/graphite/GrDebug.h new file mode 100644 index 00000000000..dc02fac0134 --- /dev/null +++ b/Build/source/libs/graphite-engine/include/graphite/GrDebug.h @@ -0,0 +1,200 @@ +/*--------------------------------------------------------------------*//*:Ignore this sentence. +Copyright (C) 1999, 2001 SIL International. All rights reserved. + +Distributable under the terms of either the Common Public License or the +GNU Lesser General Public License, as specified in the LICENSING.txt file. + +File: debug.h +Responsibility: +Last reviewed: + +Description: + Assert and debug definitions. +----------------------------------------------------------------------------------------------*/ + +#ifndef __DEBUG_H__ +#define __DEBUG_H__ + +#include <cassert> + +namespace gr +{ + +#ifdef _DEBUG + #undef DEBUG + #define DEBUG 1 + #undef NDEBUG + #define DEFINE_THIS_FILE static char THIS_FILE[] = __FILE__; + #undef THIS_FILE + #define THIS_FILE __FILE__ +#else //!_DEBUG + #undef DEBUG + #define DEFINE_THIS_FILE + + //#define Debug(foo) +#endif //!_DEBUG + +#if 0 +//#ifdef DEBUG + +//#include <windows.h> + + typedef void (WINAPI * Pfn_Assert)(const char * pszExp, const char * pszFile, int nLine, + HMODULE hmod); + typedef Pfn_Assert Pfn_Warn; + + /*__declspec(dllimport)*/ void WINAPI WarnProc(const char * pszExp, const char * pszFile, + int nLine, bool fCritical, HMODULE hmod); + /*__declspec(dllimport)*/ void WINAPI AssertProc(const char * pszExp, const char * pszFile, + int nLine, bool fCritical, HMODULE hmod); + + __declspec(dllimport) Pfn_Assert WINAPI SetAssertProc(Pfn_Assert pfnAssert); + __declspec(dllimport) Pfn_Warn WINAPI SetWarnProc(Pfn_Warn pfnWarn); + __declspec(dllimport) int WINAPI HideWarnings(bool f); + __declspec(dllimport) int WINAPI HideAsserts(bool f); + __declspec(dllimport) int WINAPI HideErrors(bool f); + + void WINAPI WarnHrProc(HRESULT hr, const char * pszFile, int nLine, bool fCritical); + void WINAPI WarnProcLocal(const char * pszExp, const char * pszFile, int nLine, + bool fCritical); + void WINAPI AssertProcLocal(const char * pszExp, const char * pszFile, int nLine, + bool fCritical); + + #define Assert(exp) ((exp) || (AssertProcLocal(#exp, THIS_FILE, __LINE__, false), 0)) + #define AssertC(exp) ((exp) || (AssertProcLocal(#exp, THIS_FILE, __LINE__, true), 0)) + #define AssertMsg(exp, msg) ((exp) || (AssertProcLocal(msg, THIS_FILE, __LINE__, false), 0)) + #define AssertMsgC(exp, msg) ((exp) || (AssertProcLocal(msg, THIS_FILE, __LINE__, true), 0)) + + #undef Warn + #define Warn(psz) (void)(WarnProcLocal(psz, THIS_FILE, __LINE__, false)) + #define WarnC(psz) (void)(WarnProcLocal(psz, THIS_FILE, __LINE__, true)) + + #undef WarnIf + #define WarnIf(exp) (void)(!(exp) || (WarnProcLocal("(" #exp ") is true", THIS_FILE, \ + __LINE__, false), 0)) + #define WarnIfC(exp) (void)(!(exp) || (WarnProcLocal("(" #exp ") is true", THIS_FILE, \ + __LINE__, true), 0)) + + #undef WarnUnless + #define WarnUnless(exp) (void)((exp) || (WarnProcLocal("(" #exp ") is false", \ + THIS_FILE, __LINE__, false), 0)) + #define WarnUnlessC(exp) (void)((exp) || (WarnProcLocal("(" #exp ") is false", \ + THIS_FILE, __LINE__, true), 0)) + + #undef WarnHr + #define WarnHr(hr) ((SUCCEEDED(hr) || (WarnHrProc(hr, THIS_FILE, __LINE__, false), 0)), \ + (hr)) + #define WarnHrC(hr) ((SUCCEEDED(hr) || (WarnHrProc(hr, THIS_FILE, __LINE__, true), 0)), \ + (hr)) + + class IgnoreWarnings + { + public: + IgnoreWarnings() + { HideWarnings(true); } + ~IgnoreWarnings() + { HideWarnings(false); } + }; + + class IgnoreAsserts + { + public: + IgnoreAsserts() + { HideAsserts(true); } + ~IgnoreAsserts() + { HideAsserts(false); } + }; + + class IgnoreErrors + { + private: + IgnoreWarnings iw; + IgnoreAsserts ia; + }; + + #define Debug(exp) exp + #define DoAssert(exp) Assert(exp) + #define DoAssertC(exp) AssertC(exp) + #define DoAssertHr(hr) Assert(SUCCEEDED(hr)) + #define DoAssertHrC(hr) AssertC(SUCCEEDED(hr)) +#else + #define Assert(exp) assert(exp) + #define AssertC(exp) + #define AssertMsg(exp, msg) + #define AssertMsgC(exp, msg) + #define Warn(psz) + #define WarnC(psz) + #define WarnIf(exp) + #define WarnIfC(exp) + #define WarnUnless(exp) + #define WarnUnlessC(exp) + #define WarnHr(hr) (hr) + #define WarnHrC(hr) (hr) + #define Debug(exp) + #define DoAssert(exp) (exp) + #define DoAssertC(exp) (exp) + #define DoAssertHr(hr) (hr) + #define DoAssertHrC(hr) (hr) +#endif //DEBUG + +#define AssertPtr(pv) Assert(ValidReadPtr(pv)) +#define AssertPtrN(pv) Assert(!(pv) || ValidReadPtr(pv)) +#define AssertArray(pv, cv) Assert((cv) >= 0 && ValidReadPtrSize((pv), isizeof(*(pv)) * (cv))) +#define AssertArrayN(pv, cv) Assert((cv) >= 0 && (!(pv) || ValidReadPtrSize((pv), isizeof(*(pv)) * (cv)))) +#define AssertPtrSize(pv, cb) Assert((cb) >= 0 && ValidReadPtrSize((pv), cb)) + +#define AssertPfn(pfn) Assert(!IsBadCodePtr((FARPROC)(pfn))) +#define AssertPfnN(pfn) Assert(!(pfn) || !IsBadCodePtr((FARPROC)(pfn))) + +#define AssertPsz(psz) Assert(ValidPsz(psz)) +#define AssertPszN(psz) Assert(!(psz) || ValidPsz(psz)) + +#define AssertBstr(bstr) Assert(ValidBstr(bstr)) +#define AssertBstrN(bstr) Assert(!(bstr) || ValidBstr(bstr)) + +#define AssertObj(pv) Assert(ValidReadPtr(pv) && (pv)->AssertValid()) +#define AssertObjN(pv) Assert(!(pv) || ValidReadPtr(pv) && (pv)->AssertValid()) + +/*---------------------------------------------------------------------------------------------- + This class implements custom output to the debugger. The results of Watch() can be + viewed on a line in the Watch window. Output() writes to the Debugger Output window. + Calls to Output() should be included in the Watch() function as needed. Watch() + is executed every time the debugger displays this class in the Watch window. + To use it: + + 1) Put the following line in: + \program files\Microsoft Visual Studio\Common\MSDev98\bin\AutoExp.dat + in the [AutoExpand] section: + DebugWatch=<WatchNV(),su> + + 2) In the class from which you want custom debug output, add the equivalent of: + #ifdef DEBUG + class Dbw1 : public DebugWatch { virtual OLECHAR * Watch(); ... }; + Dbw1 m_dbw1; + #endif //DEBUG + + 3) Implement the Watch() function to display the data you want to see, bracketed by + #ifdef DEBUG / #endif. Note that Output() is LIMITED to 10 pointer-sized arguments. + If you must have more, then call _CrtDbgReport() directly. Note also that + _CrtDbgReport() is not implemented for wide characters, so neither is Output(). +----------------------------------------------------------------------------------------------*/ +#if 0 +//#ifdef DEBUG +class DebugWatch +{ +public: + int m_nSerial; // increment and display this for positive affirmation of refresh + DebugWatch() { m_nSerial = 0; } + OLECHAR * WatchNV(); // debugger won't find it if it is virtual or inline. + virtual OLECHAR * Watch() { return L"No DebugWatch string implemented"; } + void Output (char *fmt, ...); // LIMITED to 10 pointer-sized arguments +}; +#endif //DEBUG + +} // namespace gr + +#if defined(GR_NO_NAMESPACE) +using namespace gr; +#endif + +#endif diff --git a/Build/source/libs/graphite-engine/include/graphite/GrExt.h b/Build/source/libs/graphite-engine/include/graphite/GrExt.h new file mode 100644 index 00000000000..518683db29e --- /dev/null +++ b/Build/source/libs/graphite-engine/include/graphite/GrExt.h @@ -0,0 +1,13 @@ +/*--------------------------------------------------------------------*//*:Ignore this sentence. +Copyright (C) 1999, 2001, 2003 SIL International. All rights reserved. + +Distributable under the terms of either the Common Public License or the +GNU Lesser General Public License, as specified in the LICENSING.txt file. + +File: GrHelperClases.h +Responsibility: Sharon Correll +Last reviewed: + + External helper classes to be included in the open-source version of the Graphite DLL. + Currently there are none. +----------------------------------------------------------------------------------------------*/ diff --git a/Build/source/libs/graphite-engine/include/graphite/GrFeature.h b/Build/source/libs/graphite-engine/include/graphite/GrFeature.h new file mode 100644 index 00000000000..ee7376fe1c4 --- /dev/null +++ b/Build/source/libs/graphite-engine/include/graphite/GrFeature.h @@ -0,0 +1,200 @@ +/*--------------------------------------------------------------------*//*:Ignore this sentence. +Copyright (C) 1999, 2001 SIL International. All rights reserved. + +Distributable under the terms of either the Common Public License or the +GNU Lesser General Public License, as specified in the LICENSING.txt file. + +File: GrFeature.h +Responsibility: Sharon Correll +Last reviewed: Not yet. + +Description: + +Note: + The body of methods not complete contained in this file are located in GrEngine.cpp. +----------------------------------------------------------------------------------------------*/ +#ifdef _MSC_VER +#pragma once +#endif +#ifndef GR_FEATURE_INCLUDED +#define GR_FEATURE_INCLUDED + +//:End Ignore + +#include "GrAppData.h" + +namespace gr +{ + + +/*---------------------------------------------------------------------------------------------- + A valid setting and its UI labels in potentially various languages. + + Hungarian: fset +----------------------------------------------------------------------------------------------*/ +/**** +class GrFeatureSetting +{ + friend class GrFeature; +public: + GrFeatureSetting() + { + m_hmnstuLabels.Clear(); + } + GrFeatureSetting(GrFeatureSetting & fset) + { + m_hmnstuLabels.Clear(); + } +protected: + int m_nVal; + HashMap<int, std::wstring> m_hmnstuLabels; +}; +****/ + +class GrEngine; + +/*---------------------------------------------------------------------------------------------- + Each Graphite feature defines a way to customize or parameterize the rendering processs. + + Hungarian: feat +----------------------------------------------------------------------------------------------*/ +class GrFeature +{ + //friend class GrFeatureSetting; +public: + enum { + knLangFeatV2 = 1 + }; + + GrFeature() + { + m_vnVal.clear(); + m_vnNameId.clear(); + } + + void Initialize(featid nID, int nNameId, int cfset, int nDefault = 0); + + featid ID() + { + return m_nID; + } + + int DefaultValue() + { + return m_nDefault; + } + + void SetDefault(int nDefault) + { + m_nDefault = nDefault; + } + + int NameId() + { + return m_nNameId; + } + + void SetNameId(int n) + { + m_nNameId = n; + } + + int NumberOfSettings() + { + return (int)m_vnVal.size(); + } + + int Settings(int cMax, int * prgnVal); + void AddSetting(int nVal, int nNameId); + bool IsValidSetting(int nVal); + std::wstring Label(GrEngine * pgreng, int nLang); + std::wstring SettingLabel(GrEngine * pgreng, int nVal, int nLang); + int NthSetting(int ifset); + std::wstring NthSettingLabel(GrEngine * pgreng, int ifset, int nLang); +// void SetSettingLabel(int nVal, std::wstring stuLabel, int nLang); + +protected: + featid m_nID; + int m_nDefault; + int m_nNameId; +// HashMap<int, std::wstrng> m_hmnstuLabels; + + // These are parallel arrays. The first gives the setting value for a given feature, + // the second gives the index into the name table that is used to read UI strings. + std::vector<int> m_vnVal; + std::vector<int> m_vnNameId; +}; + + +/*---------------------------------------------------------------------------------------------- + GrLangTable handles looking up language information. + GrEngine has one instance of this class. + Hungarian: langtbl +----------------------------------------------------------------------------------------------*/ +class GrIStream; + +class GrLangTable +{ +public: + GrLangTable() + { + m_prglang = NULL; + m_clang = 0; + m_prgfset = NULL; + } + ~GrLangTable() + { + delete[] m_prglang; + delete[] m_prgfset; + } + + bool ReadFromFont(GrIStream * pgrstrm, int fxdVersion); + void CreateEmpty(); + + size_t NumberOfLanguages() + { + return m_clang; + } + void LanguageFeatureSettings(isocode lgcode, + std::vector<featid> & vnFeatId, std::vector<int> & vnValues); + isocode LanguageCode(size_t ilang); + +protected: + size_t m_clang; + // constants for fast binary search of language list + data16 m_dilangInit; // (max power of 2 <= m_clang); + // size of initial range to consider + data16 m_cLoop; // log2(max power of 2 <= m_clang); + // indicates how many iterations are necessary + data16 m_ilangStart; // m_clang - m_dilangInit; + // where to start search + + struct LangEntry + { + char rgchCode[4]; + data16 cFeaturesBIG; // big endian + data16 cbOffsetBIG; // big endian + }; + LangEntry * m_prglang; + int m_cbOffset0; // offset of first entry + + struct FeatSet + { + featid featidBIG; // big endian + data16 valueBIG; // big endian + data16 padBIG; + }; + FeatSet * m_prgfset; + + int FindIndex(isocode lgcode); +}; + +} // namespace gr + + +#if defined(GR_NO_NAMESPACE) +using namespace gr; +#endif + + +#endif // !GR_FEATURE_INCLUDED diff --git a/Build/source/libs/graphite-engine/include/graphite/GrMstypes.h b/Build/source/libs/graphite-engine/include/graphite/GrMstypes.h new file mode 100644 index 00000000000..2fc9f108009 --- /dev/null +++ b/Build/source/libs/graphite-engine/include/graphite/GrMstypes.h @@ -0,0 +1,40 @@ +#ifndef _MSTYPES_H +#define _MSTYPES_H +/******** +This header contains the MS Win32 specific types that are still used +throughout the Graphite code. + +It is intended to allow Graphite to build on non-Win32 platforms. + + **Do NOT include this when building against WIN32** + + TSE - 15/07/2003 +********/ + +#if defined(_WIN32) + #error Do not include this header when building against Win32 APIs +#else + +#if defined(GR_NAMESPACE) +namespace gr +{ +#endif + +typedef wchar_t OLECHAR; + +typedef signed long HRESULT; + +inline const long InterlockedIncrement(long *const intr_lck) { + return ++*intr_lck; +} + +inline const long InterlockedDecrement(long *const intr_lck) { + return --*intr_lck; +} + +#if defined(GR_NAMESPACE) +} +#endif + +#endif // defined(_WIN32) +#endif // include guard diff --git a/Build/source/libs/graphite-engine/include/graphite/GrPlatform.h b/Build/source/libs/graphite-engine/include/graphite/GrPlatform.h new file mode 100644 index 00000000000..d72abbc6412 --- /dev/null +++ b/Build/source/libs/graphite-engine/include/graphite/GrPlatform.h @@ -0,0 +1,189 @@ +#ifndef _GR_PLATFORM_H +#define _GR_PLATFORM_H + +/*********************************************************************************************** + Turn off the goofy warnings for MS VisualStudio. +***********************************************************************************************/ +#ifdef _MSC_VER +#pragma warning(disable: 4065) // Switch statement contains default but no case. +#pragma warning(disable: 4097) // typedef-name 'xxx' used as synonym for class-name 'yyy'. +#pragma warning(disable: 4100) // unreferenced formal parameter. +#pragma warning(disable: 4127) // conditional expression is constant +#pragma warning(disable: 4192) // automatically excluding while importing. +#pragma warning(disable: 4201) // nonstandard extension used : nameless struct/union. +#pragma warning(disable: 4290) // exception specification ignored. +#pragma warning(disable: 4310) // cast truncates constant value. +#pragma warning(disable: 4355) // 'this' used in base member initializer list. +#pragma warning(disable: 4505) // unreferenced local function has been removed. +#pragma warning(disable: 4510) // default constructor could not be generated - caused by + // applying ComSmartPtr to a non-interface class. +#pragma warning(disable: 4511) // copy constructor could not be generated. +#pragma warning(disable: 4512) // assignment operator could not be generated. +#pragma warning(disable: 4610) // class 'xxx' can never be instantiated - user defined + // constructor required - caused by applying ComSmartPtr to a non-interface class. +#pragma warning(disable: 4660) // template-class specialization is already instantiated. +#pragma warning(disable: 4701) // local variable 'xxx' may be used without being initialized. + // We would like to keep this warning (4701) enabled but the compiler applies it in + // places that are obviously OK. +#pragma warning(disable: 4702) // unreachable code. We would like to keep this warning (4702) + // enabled but the compiler applies it in places that are obviously OK. +#pragma warning(disable: 4706) // assignment in conditional expression +#pragma warning(disable: 4710) // not inlined. +#pragma warning(disable: 4786) // identifier truncated in debug info. +#pragma warning(disable: 4800) // forcing value to bool 'true' or 'false' (performance warning). +#endif + + +// Standard headers +#include <stddef.h> + +// Platform headers +// +#if defined(_WIN32) +#include <windows.h> +#include <tchar.h> + +#ifdef SIZEOF_WCHAR_T +#define SIZEOF_WCHAR_T 2 +#endif + +#endif + +// Project headers +#if defined(_WIN32) +#include <algorithm> +#endif +#include <iostream> + + +#if defined(_WIN32) +// TSE: We need to define std::max and std::min, because VC6.0 seems to omit +// these from their version of <algorithm> and rely on the macro versions +// to silently take their place. This breaks the use of the name max in any +// other scope e.g. as in std::numeric_limits<..>::max(). + +#undef min +#undef max + +// SJC: Only do this for version 6, otherwise the definitions conflict with the +// built-in STL definitions, and the compiler really struggles. +#if _MSC_VER == 1200 // VC version 6 +namespace std +{ + template<typename T> inline T max(const T a, const T b) { return a < b ? b : a; } + template<typename T> inline T min(const T a, const T b) { return a > b ? b : a; } +} +#endif // _MSC_VER == 1200 +//////using std::max; // SJC moved to GrCommon.h +//////using std::min; +#endif // _WIN32 + + +namespace gr +{ + +// Typedefs +// These are correct for the x86_64 architecture too. +typedef unsigned char byte; +typedef unsigned int utf32; // UTF32 encoded Unicode codepoints +typedef unsigned short int utf16; // UTF16 encoded Unicode codepoints +typedef unsigned char utf8; // UTF-8 encoded Unicode codepoints +typedef unsigned short int gid16; // glyph ID +typedef unsigned int fontTableId32; // ID to pass to getTable() + +typedef unsigned char data8; +typedef unsigned short int data16; // generic 16-bit data +typedef unsigned int data32; // generic 32-bit data +typedef signed char sdata8; +typedef signed short int sdata16; // generic 16-bit data +typedef signed int sdata32; // generic 32-bit data + +#ifndef NO_ASM +#define NO_ASM +#endif + +#ifndef NULL +#define NULL 0 +#endif +// std::_Ios_Openmode isn't defined in the Windows compiler +#if !defined(_WIN32) + typedef std::ios_base::openmode openmode_t; +#else + typedef int openmode_t; +#endif + +/************************************************************************************* + Offsets and addresses. AddrOf is useful for taking the address of an object + that overloads the & operator. +*************************************************************************************/ +#if defined(_WIN32) +#undef offsetof +#define offsetof(cls,fld) ((int)&((cls *)0)->fld) +#endif + +// #ifndef NO_ASM +// #define addrsafe_offsetof(cls,fld) reinterpret_cast<int>(AddrOf(((cls *)0)->fld)) +// +// template<typename T> inline T * AddrOf(T & x) { +// T * pt; +// __asm +// { +// mov eax,x +// mov pt,eax +// } +// return pt; +// } +// #endif + + +inline bool GrIsBadStringPtrW(const utf16 *const pszw, const long) +{ + return !pszw; +} + +inline bool GrIsBadStringPtrA(const char *const psza, const long) +{ + return !psza; +} + +inline bool GrIsBadReadPtr(const void *const, const unsigned int) +{ + return false; +} + +inline bool GrIsBadWritePtr(const void *const, const unsigned int) +{ + return false; +} + + +size_t Platform_UnicodeToANSI(const utf16 * prgchwSrc, size_t cchwSrc, char * prgchsDst, size_t cchsDst); +size_t Platform_AnsiToUnicode(const char * prgchsSrc, size_t cchsSrc, utf16 * prgchwDst, size_t cchwDst); +//size_t Platform_UnicodeToANSI(const wchar * prgchwSrc, size_t cchwSrc, char * prgchsDst, size_t cchsDst); +//size_t Platform_AnsiToUnicode(const char * prgchsSrc, size_t cchsSrc, wchar * prgchwDst, size_t cchwDst); +size_t Platform_8bitToUnicode(int nCodePage, const char * prgchsSrc, int cchsSrc, utf16 * prgchwDst, int cchwDst); + +utf16 *utf16cpy(utf16 *dest, const utf16 *src); +utf16 *utf16cpy(utf16 *dest, const char *src); +utf16 *utf16cpy(utf16 *dest, const utf32 *src); + +utf16 *utf16ncpy(utf16 *dest, const utf16 *src, size_t n); +utf16 *utf16ncpy(utf16 *dest, const char *src, size_t n); + +#ifdef UTF16DEBUG +void utf16Output(const utf16 *input); +#endif + +size_t utf16len(const utf16 *s); + +int utf16cmp(const utf16 *s1, const utf16 *s2); +int utf16ncmp(const utf16 *s1, const utf16 *s2, size_t n); +int utf16cmp(const utf16 *s1, const char *s2); + +} // namespace gr + +#if defined(GR_NO_NAMESPACE) +using namespace gr; +#endif + +#endif diff --git a/Build/source/libs/graphite-engine/include/graphite/GrResult.h b/Build/source/libs/graphite-engine/include/graphite/GrResult.h new file mode 100644 index 00000000000..d2c418dc9df --- /dev/null +++ b/Build/source/libs/graphite-engine/include/graphite/GrResult.h @@ -0,0 +1,171 @@ +/*--------------------------------------------------------------------*//*:Ignore this sentence. +Copyright (C) 1999, 2001 SIL International. All rights reserved. + +Distributable under the terms of either the Common Public License or the +GNU Lesser General Public License, as specified in the LICENSING.txt file. + +File: GrResult.h +Responsibility: Sharon Correll +Last reviewed: Not yet. + +Description: + Support for the GrResult and error handling in the Graphite engine. Also argument + checking. Much of this is set up to parallel standard COM behavior. + +Special Note: + This file needs to be used by C files. Please do not use C++ style comments; use + ONLY C style comments in this file to make the C compiler happy. +----------------------------------------------------------------------------------------------*/ +#ifdef _MSC_VER +#pragma once +#endif +#ifndef GRRESULT_INCLUDED +#define GRRESULT_INCLUDED + +/* +//:End Ignore + */ + + +namespace gr +{ + + + +/*:>********************************************************************************************/ +/*:> Result flags */ +/*:>********************************************************************************************/ + +/* These are return values for the main interface methods to indicate various kinds of */ +/* error conditions. To facilitate COM compatibiliy, they match the standard COM HRESULT codes. */ +enum GrResult +{ + kresOk = 0, // S_OK + kresFalse = 1, // S_FALSE + kresFail = 0x80004005L, // E_FAIL + kresOutOfMemory = 0x8007000EL, // E_OUTOFMEMORY + kresInvalidArg = 0x80000002L, // E_INVALIDARG + kresReadFault = 0x80000001L, // STG_E_READFAULT + kresUnexpected = 0x80000003L, // E_UNEXPECTED + kresNotImpl = 0x80000004L, // E_NOTIMPL + kresPointer = 0x80004003L//, // E_POINTER +}; + +#define ResultFailed(res) (res != kresOk) /* && res != kresFalse */ + +#define ResultSucceeded(res) (res == kresOk) /* || res == kresFalse */ + +enum FontErrorCode +{ + kferrOkay, + kferrUninitialized, + kferrUnknown, + kferrFindHeadTable, + kferrReadDesignUnits, + kferrFindCmapTable, + kferrLoadCmapSubtable, + kferrCheckCmapSubtable, + kferrFindNameTable, + kferrLoadSilfTable, + kferrLoadFeatTable, + kferrLoadGlatTable, + kferrLoadGlocTable, + kferrReadSilfTable, + kferrReadGlocGlatTable, + kferrReadFeatTable, + kferrBadVersion, + kferrSileTableMismatch, + kferrReadSillTable +}; + +/*:>********************************************************************************************/ +/*:> Error handling */ +/*:>********************************************************************************************/ +/* These are set up as #defines so we can easily adjust them once we know how errors should */ +/* be handled. */ + +#define ReturnResult(res) return res + +#ifdef GR_FW +#define THROW(res) ThrowInternalError(res) +#else +#define THROW(res) throw res +#endif /* GR_FW */ + + +// #if !defined(NDEBUG) + +#if (0) // can't get E_POINTER to work so no debugging this way for now + +} // namespace gr + +#include <iostream> + +namespace gr +{ + +#define WARN(warning) (std::cerr << __FILE__ << ':' << __LINE__ << ": WARN: " << #warning, warning) + +/*:>********************************************************************************************/ +/*:> Argument checking */ +/*:>********************************************************************************************/ + +#define ChkGrArgPtr(p) \ +{ \ + AssertPtrN(p); \ + if (!p) \ + THROW(E_POINTER); \ +} \ + +#define ChkGrOutPtr(p) \ +{ \ + AssertPtrN(p); \ + if (!p) \ + THROW(E_POINTER); \ +} \ + +#define ChkGrArgPtrN(p) \ + AssertPtrN(p); \ + +#define ChkGrArrayArg(prgv, cv) \ +{ \ + AssertArray(prgv, cv); \ + if (cv && !prgv) \ + THROW(E_POINTER); \ +} \ + +#define ChkGrBstrArg(bstr) \ + AssertBstr(bstr); \ + +#define ChkGrBstrArgN(bstr) \ + AssertBstrN(bstr); \ + +#else // debugging is off + +#define WARN(warning) (warning) + +/*:>********************************************************************************************/ +/*:> Argument checking */ +/*:>********************************************************************************************/ + +#define ChkGrArgPtr(p) (static_cast<void>(0)) + +#define ChkGrOutPtr(p) (static_cast<void>(0)) + +#define ChkGrArgPtrN(p) (static_cast<void>(0)) + +#define ChkGrArrayArg(prgv, cv) (static_cast<void>(0)) + +#define ChkGrBstrArg(bstr) (static_cast<void>(0)) + +#define ChkGrBstrArgN(bstr) (static_cast<void>(0)) + +#endif // !defined(NDEBUG) + +} // namespace gr + +#if defined(GR_NO_NAMESPACE) +using namespace gr; +#endif + +#endif /* !GRRESULT_INCLUDED */ diff --git a/Build/source/libs/graphite-engine/include/graphite/GrStructs.h b/Build/source/libs/graphite-engine/include/graphite/GrStructs.h new file mode 100644 index 00000000000..a1c9debe238 --- /dev/null +++ b/Build/source/libs/graphite-engine/include/graphite/GrStructs.h @@ -0,0 +1,97 @@ +/*--------------------------------------------------------------------*//*:Ignore this sentence. +Copyright (C) 1999, 2001 SIL International. All rights reserved. + +Distributable under the terms of either the Common Public License or the +GNU Lesser General Public License, as specified in the LICENSING.txt file. + +File: GrStructs.h +Responsibility: Sharon Correll +Last reviewed: Not yet. + +Copyright (C) 1999 by SIL International. All rights reserved. + +Description: + Cross-platform structure definitions. +----------------------------------------------------------------------------------------------*/ +#ifdef _MSC_VER +#pragma once +#endif +#ifndef GRSTRUCTS_INCLUDED +#define GRSTRUCTS_INCLUDED +#include "GrPlatform.h" + +namespace gr +{ + +//:End Ignore + +typedef struct tagGrCharProps +{ + unsigned long clrFore; + unsigned long clrBack; + int dympOffset; + int ws; + int ows; + byte fWsRtl; + int nDirDepth; + byte ssv; + byte ttvBold; + byte ttvItalic; + int dympHeight; + wchar_t szFaceName[ 32 ]; + wchar_t szFontVar[ 64 ]; +} GrCharProps; + +// Used to pass feature information among the Graphite engine and the application. +typedef struct tagFeatureSetting +{ + int id; + int value; +} FeatureSetting; + +/***** +struct Point +{ + float x; + float y; + + Point() + { + x = y = 0; + } + + Point(POINT & p) + { + x = (float)p.x; + y = (float)p.y; + } +}; + + +struct Rect +{ + float top; + float bottom; + float left; + float right; + + Rect() + { + top = bottom = left = right = 0; + }; + + Rect(RECT & r) + { + top = (float)r.top; + bottom = (float)r.bottom; + left = (float)r.left; + right = (float)r.right; + }; +}; +****/ + +} // namespace gr + + +#endif // !STRUCTS_INCLUDED + diff --git a/Build/source/libs/graphite-engine/include/graphite/GrWrappers.h b/Build/source/libs/graphite-engine/include/graphite/GrWrappers.h new file mode 100644 index 00000000000..077b4695d80 --- /dev/null +++ b/Build/source/libs/graphite-engine/include/graphite/GrWrappers.h @@ -0,0 +1,13 @@ +/*--------------------------------------------------------------------*//*:Ignore this sentence. +Copyright (C) 1999, 2001, 2003 SIL International. All rights reserved. + +Distributable under the terms of either the Common Public License or the +GNU Lesser General Public License, as specified in the LICENSING.txt file. + +File: GrWrapperClases.h +Responsibility: Sharon Correll +Last reviewed: + + Wrapper classes to be included in the open-source version of the Graphite DLL. + Currently there are none. +----------------------------------------------------------------------------------------------*/ diff --git a/Build/source/libs/graphite-engine/include/graphite/GraphiteProcess.h b/Build/source/libs/graphite-engine/include/graphite/GraphiteProcess.h new file mode 100644 index 00000000000..60f81860c2e --- /dev/null +++ b/Build/source/libs/graphite-engine/include/graphite/GraphiteProcess.h @@ -0,0 +1,45 @@ +/*--------------------------------------------------------------------*//*:Ignore this sentence. +Copyright (C) 1999, 2001 SIL International. All rights reserved. + +Distributable under the terms of either the Common Public License or the +GNU Lesser General Public License, as specified in the LICENSING.txt file. + +File: GraphiteProcess.h +Responsibility: Sharon Correll +Last reviewed: Not yet. + +Description: + The interface that is needed for the Justifier object to call back to the Graphite engine. +----------------------------------------------------------------------------------------------*/ +#ifdef _MSC_VER +#pragma once +#endif +#ifndef GRAPHITEPROCESS_INCLUDED +#define GRAPHITEPROCESS_INCLUDED + +#include "GrResult.h" +//:End Ignore +namespace gr +{ + +/*---------------------------------------------------------------------------------------------- + + Hungarian: fgje +----------------------------------------------------------------------------------------------*/ +class GraphiteProcess +{ +public: + virtual ~GraphiteProcess() {}; + virtual GrResult getGlyphAttribute(int iGlyph, int jgat, int nLevel, float * pValueRet) = 0; + virtual GrResult getGlyphAttribute(int iGlyph, int jgat, int nLevel, int * pValueRet) = 0; + virtual GrResult setGlyphAttribute(int iGlyph, int jgat, int nLevel, float value) = 0; + virtual GrResult setGlyphAttribute(int iGlyph, int jgat, int nLevel, int value) = 0; +}; + +} // namespace gr + +#if defined(GR_NO_NAMESPACE) +using namespace gr; +#endif + +#endif // !IGR_JENGINE_INCLUDED diff --git a/Build/source/libs/graphite-engine/include/graphite/HashMap.h b/Build/source/libs/graphite-engine/include/graphite/HashMap.h new file mode 100644 index 00000000000..aa925ac608d --- /dev/null +++ b/Build/source/libs/graphite-engine/include/graphite/HashMap.h @@ -0,0 +1,328 @@ +/*--------------------------------------------------------------------*//*:Ignore this sentence. +Copyright (C) 2001 SIL International. All rights reserved. + +Distributable under the terms of either the Common Public License or the +GNU Lesser General Public License, as specified in the LICENSING.txt file. + +File: HashMap.h +Responsibility: Steve McConnel +Last reviewed: Not yet. + +Description: + This provides a set of template collection classes to replace std::map. Their primary + reason to exist is to allow explicit checking for internal memory allocation failures. +----------------------------------------------------------------------------------------------*/ +#pragma once +#ifndef HASHMAP_H_INCLUDED +#define HASHMAP_H_INCLUDED +//:End Ignore + +/*---------------------------------------------------------------------------------------------- + Functor class for computing a hash value from an arbitrary object. + + Hungarian: hsho +----------------------------------------------------------------------------------------------*/ +class HashObj +{ +public: + int operator () (void * pKey, int cbKey); +}; + +/*---------------------------------------------------------------------------------------------- + Functor class for comparing two arbitrary objects (of the same class) for equality. + + Hungarian: eqlo +----------------------------------------------------------------------------------------------*/ +class EqlObj +{ +public: + bool operator () (void * pKey1, void * pKey2, int cbKey); +}; + +/*---------------------------------------------------------------------------------------------- + Hash map template collection class whose keys are objects of an arbitrary class. + + Hungarian: hm[K][T] +----------------------------------------------------------------------------------------------*/ +template<class K, class T, class H = HashObj, class Eq = EqlObj> class HashMap +{ +public: + //:> Member classes + + /*------------------------------------------------------------------------------------------ + This is the basic data structure for storing one key-value pair in a hash map. In + order to handle hash collisions, this structure is a member of a linked list. + Hungarian: hsnd + ------------------------------------------------------------------------------------------*/ + class HashNode + { + public: + //:> Constructors/destructors/etc. + + HashNode(void) + : m_key(K()), m_value(T()), m_nHash(0), m_ihsndNext(0) + { + } + HashNode(K & key, T & value, int nHash, int ihsndNext = -1) + : m_key(key), m_value(value), m_nHash(nHash), m_ihsndNext(ihsndNext) + { + } + ~HashNode() + { + } + + //:> Member variable access + + void PutKey(K & key) + { + m_key = key; + } + K & GetKey() + { + return m_key; + } + void PutValue(T & value) + { + m_value = value; + } + T & GetValue() + { + return m_value; + } + void PutHash(int nHash) + { + m_nHash = nHash; + } + int GetHash() + { + return m_nHash; + } + void PutNext(int ihsndNext) + { + m_ihsndNext = ihsndNext; + } + int GetNext() + { + return m_ihsndNext; + } + + /*-------------------------------------------------------------------------------------- + Check whether the given HashNode is being used. + --------------------------------------------------------------------------------------*/ + bool InUse() + { + return m_ihsndNext >= -1; + } + + protected: + //:> Member variables + + K m_key; + T m_value; + int m_nHash; + int m_ihsndNext; // -1 means end of list, -(ihsnd + 3) for free list members + }; + + /*------------------------------------------------------------------------------------------ + This provides an iterator for stepping through all HashNodes stored in the hash map. + This is useful primarily for saving the contents of a hash map to a file. + + Hungarian: ithm[K][T] + ------------------------------------------------------------------------------------------*/ + class iterator + { + public: + // Constructors/destructors/etc. + + iterator() : m_phmParent(0), m_ihsnd(0) + { + } + iterator(HashMap<K,T,H,Eq> * phm, int ihsnd) : m_phmParent(phm), m_ihsnd(ihsnd) + { + } + iterator(const iterator & v) : m_phmParent(v.m_phmParent), m_ihsnd(v.m_ihsnd) + { + } + ~iterator() + { + } + + // Other public methods + + iterator & operator = (const iterator & ithm) + { + m_phmParent = ithm.m_phmParent; + m_ihsnd = ithm.m_ihsnd; + return *this; + } + T & operator * (void) + { + Assert(m_phmParent); + Assert(m_phmParent->m_prghsnd); + Assert(m_ihsnd < m_phmParent->m_ihsndLim); + return m_phmParent->m_prghsnd[m_ihsnd].GetValue(); + } + HashNode * operator -> (void) + { + Assert(m_phmParent); + Assert(m_phmParent->m_prghsnd); + Assert(m_ihsnd < m_phmParent->m_ihsndLim); + return &m_phmParent->m_prghsnd[m_ihsnd]; + } + iterator & operator ++ (void) + { + Assert(m_phmParent); + ++m_ihsnd; + // make sure that this new HashNode is actually in use + while (m_ihsnd < m_phmParent->m_ihsndLim) + { + if (m_phmParent->m_prghsnd[m_ihsnd].InUse()) + return *this; + // skip to the next one and check it + ++m_ihsnd; + } + if (m_ihsnd > m_phmParent->m_ihsndLim) + m_ihsnd = m_phmParent->m_ihsndLim; + return *this; + } + bool operator == (const iterator & ithm) + { + return (m_phmParent == ithm.m_phmParent) && (m_ihsnd == ithm.m_ihsnd); + } + bool operator != (const iterator & ithm) + { + return (m_phmParent != ithm.m_phmParent) || (m_ihsnd != ithm.m_ihsnd); + } + T & GetValue(void) + { + Assert(m_phmParent); + Assert(m_phmParent->m_prghsnd); + Assert(m_ihsnd < m_phmParent->m_ihsndLim); + Assert(m_phmParent->m_prghsnd[m_ihsnd].InUse()); + return m_phmParent->m_prghsnd[m_ihsnd].GetValue(); + } + K & GetKey(void) + { + Assert(m_phmParent); + Assert(m_phmParent->m_prghsnd); + Assert(m_ihsnd < m_phmParent->m_ihsndLim); + Assert(m_phmParent->m_prghsnd[m_ihsnd].InUse()); + return m_phmParent->m_prghsnd[m_ihsnd].GetKey(); + } + int GetHash() + { + Assert(m_phmParent); + Assert(m_phmParent->m_prghsnd); + Assert(m_ihsnd < m_phmParent->m_ihsndLim); + Assert(m_phmParent->m_prghsnd[m_ihsnd].InUse()); + return m_phmParent->m_prghsnd[m_ihsnd].GetHash(); + } + int GetIndex() + { + Assert(m_phmParent); + Assert(m_phmParent->m_prghsnd); + Assert(m_ihsnd < m_phmParent->m_ihsndLim); + Assert(m_phmParent->m_prghsnd[m_ihsnd].InUse()); + return m_ihsnd; + } + + protected: + //:> Member variables + + HashMap<K,T,H,Eq> * m_phmParent; + int m_ihsnd; + }; + friend class iterator; + + //:> Constructors/destructors/etc. + + HashMap(); + ~HashMap(); + HashMap(HashMap<K,T,H,Eq> & hm); + + //:> Other public methods + + iterator Begin(); + iterator End(); + void Insert(K & key, T & value, bool fOverwrite = false, int * pihsndOut = 0); + bool Retrieve(K & key, T * pvalueRet); + bool Delete(K & key); + void Clear(); + void CopyTo(HashMap<K,T,H,Eq> & hmKT); + void CopyTo(HashMap<K,T,H,Eq> * phmKT); + + bool GetIndex(K & key, int * pihsndRet); + bool IndexKey(int ihsnd, K * pkeyRet); + bool IndexValue(int ihsnd, T * pvalueRet); + + int Size(); + + /*------------------------------------------------------------------------------------------ + The assignment operator allows an entire hashmap to be assigned as the value of another + hashmap. It throws an error if it runs out of memory. + + @return a reference to this hashmap. (That is how the assignment operator is defined!) + + @param hm is a reference to the other hashmap. + ------------------------------------------------------------------------------------------*/ + HashMap<K,T,H,Eq> & operator = (HashMap<K,T,H,Eq> & hm) + { + hm.CopyTo(this); + return *this; + } + + //:Ignore +#ifdef DEBUG + int _BucketCount(); + int _EmptyBuckets(); + int _BucketsUsed(); + int _FullestBucket(); + bool AssertValid() + { + AssertPtrN(m_prgihsndBuckets); + Assert(m_prgihsndBuckets || !m_cBuckets); + Assert(!m_prgihsndBuckets || m_cBuckets); + AssertArray(m_prgihsndBuckets, m_cBuckets); + AssertPtrN(m_prghsnd); + Assert(m_prghsnd || !m_ihsndMax); + Assert(!m_prghsnd || m_ihsndMax); + AssertArray(m_prghsnd, m_ihsndMax); + Assert(0 <= m_ihsndLim && m_ihsndLim <= m_ihsndMax); + Assert(-1 <= FreeListIdx(m_ihsndFirstFree)); + Assert(FreeListIdx(m_ihsndFirstFree) < m_ihsndLim); + return true; + } +#endif + //:End Ignore + +protected: + //:> Member variables + + int * m_prgihsndBuckets; + int m_cBuckets; + HashNode * m_prghsnd; + int m_ihsndLim; + int m_ihsndMax; + int m_ihsndFirstFree; // stores -(ihsnd + 3) + + //:> Protected methods + //:Ignore + + /*------------------------------------------------------------------------------------------ + Map between real index and "free list" index. Note that this mapping is bidirectional. + ------------------------------------------------------------------------------------------*/ + int FreeListIdx(int ihsnd) + { + return -(ihsnd + 3); + } + //:End Ignore +}; + + +// Local Variables: +// mode:C++ +// c-file-style:"cellar" +// tab-width:4 +// End: + +#endif /*HASHMAP_H_INCLUDED*/ diff --git a/Build/source/libs/graphite-engine/include/graphite/IGrEngine.h b/Build/source/libs/graphite-engine/include/graphite/IGrEngine.h new file mode 100644 index 00000000000..481cb534b46 --- /dev/null +++ b/Build/source/libs/graphite-engine/include/graphite/IGrEngine.h @@ -0,0 +1,36 @@ +/*--------------------------------------------------------------------*//*:Ignore this sentence. +Copyright (C) 2003 SIL International. All rights reserved. + +Distributable under the terms of either the Common Public License or the +NU Lesser General Public License, as specified in the LICENSING.txt file. + +File: IGrEngine.h +Responsibility: Sharon Correll +Last reviewed: Not yet. + +Description: + A very minimal interface representing the Graphite engine, for passing to the + GrJustifier. +-------------------------------------------------------------------------------*//*:End Ignore*/ +#ifdef _MSC_VER +#pragma once +#endif +#ifndef IGRENG_INCLUDED +#define IGRENG_INCLUDED + +namespace gr +{ +/*---------------------------------------------------------------------------------------------- + Class: IGrEngine +----------------------------------------------------------------------------------------------*/ +class IGrEngine +{ +}; + +} // namespace gr + +#if defined(GR_NO_NAMESPACE) +using namespace gr; +#endif + +#endif // !IGRENG_INCLUDED diff --git a/Build/source/libs/graphite-engine/include/graphite/IGrJustifier.h b/Build/source/libs/graphite-engine/include/graphite/IGrJustifier.h new file mode 100644 index 00000000000..a9ba6e51c07 --- /dev/null +++ b/Build/source/libs/graphite-engine/include/graphite/IGrJustifier.h @@ -0,0 +1,58 @@ +/*--------------------------------------------------------------------*//*:Ignore this sentence. +Copyright (C) 2003 SIL International. All rights reserved. + +Distributable under the terms of either the Common Public License or the +GNU Lesser General Public License, as specified in the LICENSING.txt file. + +File: IGrJustifier.h +Responsibility: Sharon Correll +Last reviewed: Not yet. + +Description: + An interface for a justification agent that is used by the Graphite engine. +-------------------------------------------------------------------------------*//*:End Ignore*/ +#ifdef _MSC_VER +#pragma once +#endif +#ifndef IGRJUSTIFIER_INCLUDED +#define IGRJUSTIFIER_INCLUDED + +#include "GrResult.h" + +namespace gr +{ + +class GraphiteProcess; + +/*---------------------------------------------------------------------------------------------- + Class: IGrJustifier + This class provides an interface for a justification agent for the Graphite engine. +----------------------------------------------------------------------------------------------*/ +class IGrJustifier +{ +public: + virtual ~IGrJustifier() {}; + virtual GrResult adjustGlyphWidths(GraphiteProcess * pgje, int iGlyphMin, int iGlyphLim, + float dxCurrWidth, float dxDesiredWidth) = 0; + + //virtual GrResult suggestShrinkAndBreak(GraphiteProcess * pfgjwe, + // int iGlyphMin, int iGlyphLim, float dxsWidth, LgLineBreak lbPref, LgLineBreak lbMax, + // float * pdxShrink, LgLineBreak * plbToTry) = 0; + + // Return a Graphite-compatible justifier that can be stored in a Graphite segment. + // TODO: remove + //virtual void JustifierObject(IGrJustifier ** ppgjus) = 0; + + // When a segment is being destroyed, delete this object, which is the wrapper for the + // text source inside of it. + // TODO: remove + //virtual void DeleteJustifierPtr() = 0; +}; + +} // namespace gr + +#if defined(GR_NO_NAMESPACE) +using namespace gr; +#endif + +#endif // !IGRJUSTIFIER_INCLUDED diff --git a/Build/source/libs/graphite-engine/include/graphite/IGraphiteProcess.h b/Build/source/libs/graphite-engine/include/graphite/IGraphiteProcess.h new file mode 100644 index 00000000000..ee84a94cdb1 --- /dev/null +++ b/Build/source/libs/graphite-engine/include/graphite/IGraphiteProcess.h @@ -0,0 +1,44 @@ +/*--------------------------------------------------------------------*//*:Ignore this sentence. +Copyright (C) 1999, 2001 SIL International. All rights reserved. + +Distributable under the terms of either the Common Public License or the +GNU Lesser General Public License, as specified in the LICENSING.txt file. + +File: GraphiteProcess.h +Responsibility: Sharon Correll +Last reviewed: Not yet. + +Description: + The interface that is needed for the Justifier object to call back to the Graphite engine. +----------------------------------------------------------------------------------------------*/ +#ifdef _MSC_VER +#pragma once +#endif +#ifndef IGRAPHITEPROCESS_INCLUDED +#define IGRAPHITEPROCESS_INCLUDED + +#include "GrResult.h" +//:End Ignore +namespace gr +{ + +/*---------------------------------------------------------------------------------------------- + + Hungarian: fgje +----------------------------------------------------------------------------------------------*/ +class GraphiteProcess +{ +public: + virtual GrResult GetGlyphAttribute(int iGlyph, int jgat, int nLevel, float * pValueRet) = 0; + virtual GrResult GetGlyphAttribute(int iGlyph, int jgat, int nLevel, int * pValueRet) = 0; + virtual GrResult SetGlyphAttribute(int iGlyph, int jgat, int nLevel, float value) = 0; + virtual GrResult SetGlyphAttribute(int iGlyph, int jgat, int nLevel, int value) = 0; +}; + +} // namespace gr + +#if defined(GR_NO_NAMESPACE) +using namespace gr; +#endif + +#endif // !IGR_JENGINE_INCLUDED diff --git a/Build/source/libs/graphite-engine/include/graphite/ITextSource.h b/Build/source/libs/graphite-engine/include/graphite/ITextSource.h new file mode 100644 index 00000000000..154d80296e3 --- /dev/null +++ b/Build/source/libs/graphite-engine/include/graphite/ITextSource.h @@ -0,0 +1,69 @@ +/*--------------------------------------------------------------------*//*:Ignore this sentence. +Copyright (C) 1999, 2001 SIL International. All rights reserved. + +Distributable under the terms of either the Common Public License or the +GNU Lesser General Public License, as specified in the LICENSING.txt file. + +File: ITextSource.h +Responsibility: Sharon Correll +Last reviewed: Not yet. + +Description: + An interface for a text source that is used by the Graphite engine. +-------------------------------------------------------------------------------*//*:End Ignore*/ +#ifdef _MSC_VER +#pragma once +#endif +#ifndef IGRTXTSRC_INCLUDED +#define IGRTXTSRC_INCLUDED + + +#include "GrAppData.h" +#include "GrStructs.h" +#include "GrResult.h" + +namespace gr +{ + +/*---------------------------------------------------------------------------------------------- + Class: ITextSource + This class provides an interface for a text source for the Graphite engine. +----------------------------------------------------------------------------------------------*/ +class ITextSource +{ +public: + virtual ~ITextSource() {}; + virtual UtfType utfEncodingForm() = 0; + virtual size_t getLength() = 0; + virtual size_t fetch(toffset ichMin, size_t cch, utf32 * prgchBuffer) = 0; + virtual size_t fetch(toffset ichMin, size_t cch, utf16 * prgchwBuffer) = 0; + virtual size_t fetch(toffset ichMin, size_t cch, utf8 * prgchsBuffer) = 0; + virtual bool getRightToLeft(toffset ich) = 0; + virtual unsigned int getDirectionDepth(toffset ich) = 0; + virtual float getVerticalOffset(toffset ich) = 0; + virtual isocode getLanguage(toffset ich) = 0; + + virtual std::pair<toffset, toffset> propertyRange(toffset ich) = 0; + virtual size_t getFontFeatures(toffset ich, FeatureSetting * prgfset) = 0; + virtual bool sameSegment(toffset ich1, toffset ich2) = 0; +}; + + +/*---------------------------------------------------------------------------------------------- + Class: IColorTextSource + Defines a method to get the color informtion from the text source. + It is needed for SegmentPainters that want to handle color. +----------------------------------------------------------------------------------------------*/ +class IColorTextSource : public ITextSource +{ +public: + virtual void getColors(toffset ich, int * pclrFore, int * pclrBack) = 0; +}; + +} // namespace gr + +#if defined(GR_NO_NAMESPACE) +using namespace gr; +#endif + +#endif // !IGRTXTSRC_INCLUDED diff --git a/Build/source/libs/graphite-engine/include/graphite/Segment.h b/Build/source/libs/graphite-engine/include/graphite/Segment.h new file mode 100644 index 00000000000..4730db6b086 --- /dev/null +++ b/Build/source/libs/graphite-engine/include/graphite/Segment.h @@ -0,0 +1,604 @@ +/*--------------------------------------------------------------------*//*:Ignore this sentence. +Copyright (C) 1999, 2001 SIL International. All rights reserved. + +Distributable under the terms of either the Common Public License or the +GNU Lesser General Public License, as specified in the LICENSING.txt file. + +File: Segment.h +Responsibility: Sharon Correll +Last reviewed: Not yet. + +Description: + Defines the class for a Graphite text segment. +----------------------------------------------------------------------------------------------*/ +#ifdef _MSC_VER +#pragma once +#endif +#ifndef GR_SEGMENT_INCLUDED +#define GR_SEGMENT_INCLUDED + +#include "Font.h" +#include "GrConstants.h" +#include "SegmentAux.h" + +// undo automagic DrawTextA DrawTextW stuff +// #undef DrawText + +//:End Ignore + +class GrEngine; + +namespace gr +{ + + +class IGrJustifier; +class GrTableManager; +class GrSlotStream; +class GrSlotOutput; + +/*---------------------------------------------------------------------------------------------- + A Graphite segment consists of a sequence of well-positioned glyphs all on one line, + Each glyph understands its relationship to the underlying text that was used to generate + the segment. + + Hungarian: seg +----------------------------------------------------------------------------------------------*/ +class Segment +{ + friend class GrEngine; + friend class SegmentPainter; + friend class GlyphInfo; + friend class GlyphIterator; + friend class GlyphSetIterator; + +public: + // Static methods + + // Constructors, destructors, etc. + Segment(); +// Segment(ITextSource * pgts, int ichMin, int ichLim, +// LineBrk lbStart, LineBrk lbEnd, +// bool fStartLine, bool fEndLine, bool fWsRtl); + + virtual ~Segment(); + + // Basic copy constructor: + Segment(Segment & seg); + + // For making modified copies of segments: + static Segment * LineContextSegment(Segment & seg, bool fStartLine, bool fEndLine); + static Segment * JustifiedSegment(Segment & seg, float xsNewWidth); + static Segment * WhiteSpaceSegment(Segment & seg, int newDirDepth); + + static int GetSegmentCount(); + +public: + + long IncRefCount(); + long DecRefCount(); + + Font & getFont(); + ITextSource & getText(); + float advanceWidth(); + Rect boundingRect(); + + bool rightToLeft(); + bool paraRightToLeft() { return m_fParaRtl; } + int directionDepth(bool * pfWeak = NULL); + bool setDirectionDepth(int nNewDepth); + int startCharacter(); + int stopCharacter(); + bool startOfLine(); + bool endOfLine(); + bool hasLineBoundaryContext(); + SegEnd segmentTermination(); + LineBrk startBreakWeight(); + LineBrk endBreakWeight(); + float stretch(); + float maxStretch(); + float maxShrink(); + void setTextSourceOffset(int ichMin) + { + m_ichwMin = ichMin; + } + + //GrResult changeLineEnds(bool fNewStart, bool fNewEnd); + + std::pair<GlyphIterator, GlyphIterator> glyphs(); + std::pair<GlyphSetIterator, GlyphSetIterator> charToGlyphs(toffset ich); + + // OBSOLETE: + GrResult GetCharData(int cchMax, utf16 * prgch, int * pcchRet); + GrResult GlyphToChar(int iginf, bool fFirst, int * pich); + GrResult GlyphToAllChars(int iginf, int cichMax, int * prgich, int *pcichRet); + GrResult CharToGlyph(int ich, bool fFirst, int * pigbb); + + // Not part of FW interface: + + float getRangeWidth(int ichMin, int ichLim, + bool fStartLine = true, bool fEndLine = true, bool fSkipSpace = true); + int findNextBreakPoint(int ichStart, + LineBrk lbPref, LineBrk lbWorst, float dxMaxWidth, + float * pdxBreakWidth, bool fStartLine = true, bool fEndLine = true); + + GrResult getUniscribeClusters( + int * prgigbb1stOfCluster, int cchMax, int * pcch, + bool * pfClusterStart, int cfMax, int * pcf); + + //GrResult GetGlyphsAndPositions( + // Rect rsArg, Rect rdArg, int cgidMax, int * pcgidRet, utf16 * prggid, + // float * prgxd, float * prgyd, float * prgdxdAdv); + //GrResult GetUniscribePositions( + // Rect rs, Rect rd, int cgidMax, int * pcgidRet, + // float * prgxd, float * prgyd, float * prgdxdAdv); + //GrResult GetUniscribeGlyphsAndPositions( + // Rect rsArg, Rect rdArg, int cgidMax, int * pcchRet, utf16 * prgchGlyphs, + // float * prgxd, float * prgyd, float * prgdxdAdv); + + // Other public methods: + + void Initialize(ITextSource * pgts, int ichMin, int ichLim, + LineBrk lbStart, LineBrk lbEnd, SegEnd est, + bool fStartLine, bool fEndLine, bool fWsRtl); + void DestroyContents(); + void SwapWith(Segment * pgrseg); + void ClearAltEndLineSeg(); + + ITextSource * GetString(); // client is responsible to Release() + + // The following three functions handle storing and retrieving information that + // allows us to restart a new segment following a line break. This is necessary + // in case there is some sort of contextualization across the line break. + void StoreRestartInfo(int cslotRestartBackup, std::vector<int>& vnSkipOffsets) + { + m_cslotRestartBackup = cslotRestartBackup; + m_vnSkipOffsets.resize(vnSkipOffsets.size()); + for (size_t i = 0; i < vnSkipOffsets.size(); i++) + m_vnSkipOffsets[i] = vnSkipOffsets[i]; + } + int NextRestartBackup() + { + return m_cslotRestartBackup; + } + int RestartBackup() + { + return (m_psegPrev)? m_psegPrev->NextRestartBackup(): 0; + } + int SkipOffset(int ipass) + { + return m_vnSkipOffsets[ipass]; + } + DirCode PreviousStrongDir() + { + return m_dircPrevStrong; + } + void SetPreviousStrongDir(DirCode dirc) + { + m_dircPrevStrong = dirc; + } + DirCode PreviousTermDir() + { + return m_dircPrevTerm; + } + void SetPreviousTermDir(DirCode dirc) + { + m_dircPrevTerm = dirc; + } + + int NextSegInitBuffer(byte ** ppbDat) + { + *ppbDat = m_prgbNextSegDat; + return m_cbNextSegDat; + } + int ThisSegInitBuffer(byte ** ppbDat) + { + *ppbDat = m_prgInitDat; + return m_cbInitDat; + } + +// void SetNextSeg(Segment * psegNext) +// { +// m_psegNext = psegNext; +// } + + void SetFaceName(std::wstring stu, std::wstring stuBase) + { + m_stuFaceName = stu; + m_stuBaseFaceName = stuBase; + m_fUseSepBase = (m_stuBaseFaceName.size() > 0); + } + + void SetEngine(GrEngine * pgreng); + void SetFont(Font * pfont); + void SwitchFont(Font * pfont); + GrEngine * EngineImpl(); + + void SetJustifier(IGrJustifier * pgjus); + IGrJustifier * Justifier() + { + return m_pgjus; + } + + void SetPreContext(int dich) + { + m_dichPreContext = dich; + } + + //void SetToBaseFont(IGrGraphics * pgg); + //void RestoreFont(IGrGraphics * pgg); + + void SetUpOutputArrays(Font * pfont, GrTableManager * ptm, + GrSlotStream * psstrmFinal, + int cchwUnderlying, int csloutSurface, gid16 chwLB, + TrWsHandling twsh, bool fParaRtl, int nDirDepth, + bool fEmpty = false); + void RecordSurfaceAssoc(int ichw, int islot, int nDir); + void RecordLigature(int ichwUnder, int islotSurface, int iComponent); + void AdjustForOverlapsWithPrevSeg(); + void MarkSlotInPrevSeg(int ichw, int islot); + void MarkSlotInNextSeg(int ichw, int islot); + + GrSlotOutput * OutputSlot(int islout); + + void RecordInitializationForNextSeg(int cbNextSegDat, byte * pbNextSegDat) + { + m_cbNextSegDat = cbNextSegDat; + m_prgbNextSegDat = new byte[m_cbNextSegDat]; + std::copy(pbNextSegDat, pbNextSegDat + cbNextSegDat, m_prgbNextSegDat); + } + void RecordInitializationForThisSeg(int cbDat, byte * pbDat) + { + m_cbInitDat = cbDat; + if (cbDat == 0) + m_prgInitDat = NULL; + else + { + m_prgInitDat = new byte[m_cbInitDat]; + std::copy(pbDat, pbDat + cbDat, m_prgInitDat); + } + } + + void SetWidths(float dxsVisWidth, float dxsTotalWidth) + { + m_dxsVisibleWidth = dxsVisWidth; + m_dxsTotalWidth = dxsTotalWidth; + } + + void SetLayout(LayoutEnvironment & layout) + { + m_layout.setStartOfLine(layout.startOfLine()); + m_layout.setEndOfLine(layout.endOfLine()); + m_layout.setBestBreak(layout.bestBreak()); + m_layout.setWorstBreak(layout.worstBreak()); + m_layout.setRightToLeft(layout.rightToLeft()); + m_layout.setTrailingWs(layout.trailingWs()); + m_layout.setPrevSegment(layout.prevSegment()); + m_layout.setJustifier(layout.justifier()); + m_layout.setLoggingStream(layout.loggingStream()); + m_layout.setDumbFallback(layout.dumbFallback()); + } + LayoutEnvironment & Layout() + { + return m_layout; + } + + bool Erroneous() + { + return m_fErroneous; + } + void SetErroneous(bool f) + { + m_fErroneous = f; + } + + void FixTermination(SegEnd est) + { + m_est = est; + } + + // Convert from em-units to logical units. + float EmToLogUnits(int m); + + Rect ComponentRect(GrSlotOutput * pslout, int icomp); + + // for transduction logging: + // implementations are empty unless TRACING is defined + void LogUnderlyingToSurface(GrTableManager * ptman, std::ostream & strmOut, + GrCharStream * pchstrm); + void LogSurfaceToUnderlying(GrTableManager * ptman, std::ostream & strmOut); + +protected: + // Member variables: + long m_cref; // standard COM ref count + + ITextSource * m_pgts; // the string we are a segment of + int m_dichwLim; // number of characters officially in this segment + int m_ichwMin; // first character relative to the text-source + + Font * m_pfont; + GrEngine * m_preneng; + + bool m_fErroneous; // an error occurred in generating this segment + + IGrJustifier * m_pgjus; + + LayoutEnvironment m_layout; + + bool m_fWsRtl; // writing system direction + bool m_fParaRtl; // paragraph direction; redundant with layout? + + TrWsHandling m_twsh; // // redundant with layout? + int m_nDirDepth; // segment direction (white-space-only segments can switch) + + byte * m_prgbNextSegDat; // for initializing the following segment + int m_cbNextSegDat; // length of above buffer + + byte * m_prgInitDat; // what was used to initialize this segment + int m_cbInitDat; + + int m_dichPreContext; // what part of this segment affects the previous; + // not really used for anything right now + + Segment * m_psegPrev; // OBSOLETE + Segment * m_psegNext; + + // Font information: + std::wstring m_stuFaceName; + std::wstring m_stuBaseFaceName; + bool m_fUseSepBase; + + float m_pixHeight; // character height of font in pixels (NOT = ascent + descent) + bool m_fBold; + bool m_fItalic; + + LineBrk m_lbStart; + LineBrk m_lbEnd; + + bool m_fStartLine; // redundant with layout? + bool m_fEndLine; // redundant with layout? + + SegEnd m_est; + + //Segment * m_psegAltEndLine; // segment having the alternate m_fEndLine value + + int m_mFontEmUnits; + float m_dysFontAscent; + float m_dysFontDescent; + float m_xysEmSquare; // em-square of the font in display units + float m_xsDPI; // DPI of device on which segment was measured + float m_ysDPI; + + float m_dxsStretch; // difference between actual and natural width + float m_dxsWidth; // width in absence of any stretch. -1 if not computed. + float m_dysHeight; + float m_dysAscent; // distance from common baseline to top of this segment, + // including extra ascent + + float m_dysXAscent; // extra for this renderer, beyond what is standard for the font + float m_dysXDescent; + + float m_dysAscentOverhang; // extra height above official top of segment; >= 0 + float m_dysDescentOverhang; // extra height below bottom of segment; <= 0; + float m_dxsLeftOverhang; // <= 0 + float m_dxsRightOverhang; + + float m_dxsVisibleWidth; // not including trailing white space + float m_dxsTotalWidth; // including trailing white space + + int m_isloutVisLim; // lim of visible stuff (to handle trailing ws underlines) + + float m_dysOffset; + + // Index of the first item in the before/after arrays and the ligature/component arrays, + // relative to the start of the segment. Normally == 0, but will be some negative number + // if there are slots "borrowed" from the previous segment (officially located in the + // previous segment but rendered in this one). + int m_ichwAssocsMin; + + // 1 + index of last item in the before/after arrays and the ligature/component arrays, + // relative to the start of the segment. Normally == m_dichwLim, but will be + // larger if there are slots "borrowed" from the following segment. + int m_ichwAssocsLim; + + // Underlying-to-surface associations: + int * m_prgisloutBefore; // logical first + int * m_prgisloutAfter; // logical last + std::vector<int> * m_prgvisloutAssocs; // all; used by range selections + + int * m_prgisloutLigature; // similar to above, index of associated ligature, or kNegInfinity + + int * m_prgiComponent; // component of the ligature that the corresponding character + // represents; only meaningful if corresponding item in + // m_prgisloutLigature is set + + GrSlotStream * m_psstrm; // TODO: rework to remove this + int m_cslout; + GrSlotOutput * m_prgslout; // final output slots + u_intslot * m_prgnSlotVarLenBuf; // var-length buffer for slots--one big buffer managed by the + // segment, but pointed to by the slots + + int m_cnUserDefn; + int m_cnCompPerLig; + int m_cnFeat; + + int m_cginf; + int m_isloutGinf0; // islout index for m_prgginf[0]; + GlyphInfo * m_prgginf; + + // Data structures to hold glyphs for rendering: +////#include "GrSegmentPlatform.h" + + // For initializing the following segment: + int m_cslotRestartBackup; // the number of slots in the underlying + // input that need to be reprocessed when starting + // the next segment + + std::vector<int> m_vnSkipOffsets; // skip offset for each pass when restarting + + DirCode m_dircPrevStrong; // previous strong directionality code + DirCode m_dircPrevTerm; // previous terminator code, if any + + + // Other protected methods: + + void InitLineContextSegment(bool fStartLine, bool fEndLine); + void InitWhiteSpaceSegment(int nNewDepth); + + void ComputeDimensions(); + + void SetUpGlyphInfo(GrTableManager * ptman, gid16 chwLB, int nDirDepth, + int islotMin, int cslot); + void SetUpLigInfo(GrTableManager * ptman, GlyphInfo & ginf, GrSlotOutput * pslout); + + void InitBeforeArrayFromPrevSeg(); // obsolete + void AdjustBeforeArrayFromPrevSeg(); + void AdjustAfterArrayFromNextSeg(); + void EnsureSpaceAtLineBoundaries(int ichwUnder); + + int LogicalSurfaceToUnderlying(int islout, + float xsOffset, float ysOffset, + float dxsGlyphWidth = 0, float dysGlyphHeight = 0, bool * pfAfter = NULL); + int LogicalSurfaceToUnderlying(int islout, bool fBefore); + int PhysicalSurfaceToUnderlying(int iginf, + float xsOffset, float xyOffset, + float dxsGlyphWidth = 0, float dysGlyphHeight = 0, bool * pfAfter = NULL); + int PhysicalSurfaceToUnderlying(int iginf, bool fBefore); + int UnderlyingToLogicalSurface(int ichw, bool fBefore); + int UnderlyingToPhysicalSurface(int ichw, bool fBefore); + int LogicalToPhysicalSurface(int islout); + void UnderlyingToPhysicalAssocs(int ichw, std::vector<int> & viginf); + std::vector<int> * UnderlyingToLogicalAssocs(int ichw); + int UnderlyingToLogicalInThisSeg(int ichw); + bool SameSurfaceGlyphs(int ichw1, int ichw2); + + void ShiftGlyphs(float dxsShift); + + float GlyphLeftEdge(int iginf); + + int DirLevelOfChar(int ichw, bool fBefore); + int CharIsRightToLeft(int ichw, bool fBefore); + int SlotIsRightToLeft(GrSlotOutput * pslout); + int TopDirLevel() + { + if (m_fWsRtl) + return 1; + else + return 0; + } + + void AssertValidClusters(GrSlotStream * psstrm); + + void MergeUniscribeCluster( + std::vector<int> & visloutBefore, std::vector<int> & visloutAfter, + int ich1, int ich2); + + int GlyphHit(float xsClick, float ysClick); + int SelectBb(std::vector<int> & viginf, bool fRTL); + + int RightMostGlyph(); + int LeftMostGlyph(); + + void ComputeOverhangs(float * pdysVisAscent, float * pdysNegVisDescent, + float * pdxsVisLeft, float * pdxsVisRight); + +public: + LineBrk getBreakWeight(int ich, bool fBreakBefore = false); + + // Platform-specific routines: +protected: + //void ShiftGlyphsPlatform(float dxsShift); + //bool SetDirectionDepthPlatform(int nNewDepth); + + //void InitializePlatform(); + //void DestroyContentsPlatform(); + //GrResult GetGlyphsAndPositionsPlatform(float xs, float ys, + // Rect rsArg, Rect rdArg, + // utf16 * prgchGlyphs, float * prgxd, float * prgyd, float * prgdxdAdv); + //void SetUpOutputArraysPlatform(GrTableManager * ptman, gid16 chwLB, int nDirDepth, + // int islotMin, int cslot); + + // Temporary - for WinSegmentPainter +public: + int CSlout() + { + return m_cslout; + } + gid16 LBGlyphID(); + float AscentOffset() + { + if (m_dysAscent == -1) + ComputeDimensions(); + return m_dysAscent - m_dysFontAscent; + } +}; + + +//:>******************************************************************************************** +//:> The purpose of these subclasses is simply to provide meaningful names for the +//:> constructors. Instances of these classes are in every way equivalent to Segment. +//:>******************************************************************************************** + +/*---------------------------------------------------------------------------------------------- + Creating a LineFillSegment fits as much of the text on the line as possible, + finding a reasonable break point if necessary. +----------------------------------------------------------------------------------------------*/ +class LineFillSegment : public Segment +{ +public: + LineFillSegment( + Font * pfont, + ITextSource * pts, + LayoutEnvironment * playout, + toffset ichStart, + toffset ichStop, + float maxWidth, + bool fBacktracking = false); +protected: + // Default constructor: + LineFillSegment() : Segment() + { + } +}; + +/*---------------------------------------------------------------------------------------------- + Creating a RangeSegment makes a segment representing the given range of characters, or + the entire text-source. +----------------------------------------------------------------------------------------------*/ +class RangeSegment : public Segment +{ +public: + RangeSegment( + Font * pfont, + ITextSource * pts, + LayoutEnvironment * playout, + toffset ichStart = 0, + toffset ichStop = kPosInfinity, + Segment * psegInitLike = NULL); +}; + +/*---------------------------------------------------------------------------------------------- + The JustSegmentAux class is used by the factory method that creates a justified segment. + It is called JustSegmentAux to avoid conflicting with the factory method. +----------------------------------------------------------------------------------------------*/ +class JustSegmentAux : public Segment +{ +public: + JustSegmentAux( + Font * pfont, + ITextSource * pts, + LayoutEnvironment * playout, + toffset ichStart, + toffset ichStop, + float xsNaturalWidth, + float xsJustifiedWidth, + Segment * psegInitLike = NULL); +}; + +} // namespace gr + +#if defined(GR_NO_NAMESPACE) +using namespace gr; +#endif + +#endif // !GR_SEGMENT_INCLUDED diff --git a/Build/source/libs/graphite-engine/include/graphite/SegmentAux.h b/Build/source/libs/graphite-engine/include/graphite/SegmentAux.h new file mode 100644 index 00000000000..0b07d8b3e32 --- /dev/null +++ b/Build/source/libs/graphite-engine/include/graphite/SegmentAux.h @@ -0,0 +1,325 @@ +/*--------------------------------------------------------------------*//*:Ignore this sentence. +Copyright (C) 2005 SIL International. All rights reserved. + +Distributable under the terms of either the Common Public License or the +GNU Lesser General Public License, as specified in the LICENSING.txt file. + +File: SegmentAux.h +Responsibility: Sharon Correll +Last reviewed: Not yet. + +Description: + Auxiliary classes for the Segment class: + - GlyphInfo + - GlyphIterator + - LayoutEnvironment +----------------------------------------------------------------------------------------------*/ +#ifdef _MSC_VER +#pragma once +#endif +#ifndef SEGMENTAUX_INCLUDED +#define SEGMENTAUX_INCLUDED + +//:End Ignore + +namespace gr +{ + +class Segment; +class GrSlotOutput; +class IGrJustifier; +class GlyphInfo; +class GlyphIterator; +class GlyphSetIterator; + + +/*---------------------------------------------------------------------------------------------- + The GlyphInfo class provides access to details about a single glyph within a segment. +----------------------------------------------------------------------------------------------*/ +class GlyphInfo // hungarian: ginf +{ + friend class Segment; + +public: + // Default constructor: + GlyphInfo() + { + m_pseg = NULL; + m_pslout = NULL; + m_islout = kInvalid; + } + + gid16 glyphID(); + gid16 pseudoGlyphID(); + + // Index of this glyph in the logical sequence; zero-based. + size_t logicalIndex(); + + // glyph's position relative to the left of the segment + float origin(); + float advanceWidth(); // logical units + float advanceHeight(); // logical units; zero for horizontal fonts + float yOffset(); + gr::Rect bb(); // logical units + bool isSpace(); + + // first char associated with this glyph, relative to start of seg + toffset firstChar(); + // last char associated with this glyph, relative to start of seg + toffset lastChar(); + + // Unicode bidi value + unsigned int directionality(); + // Embedding depth + unsigned int directionLevel(); + bool insertBefore(); + int breakweight(); + + bool isAttached() const throw(); + gr::GlyphIterator attachedClusterBase() const throw(); + float attachedClusterAdvance() const throw(); + std::pair<gr::GlyphSetIterator, gr::GlyphSetIterator> attachedClusterGlyphs() const; + + float maxStretch(size_t level); + float maxShrink(size_t level); + float stretchStep(size_t level); + byte justWeight(size_t level); + float justWidth(size_t level); + float measureStartOfLine(); + float measureEndOfLine(); + + size_t numberOfComponents(); + gr::Rect componentBox(size_t icomp); + toffset componentFirstChar(size_t icomp); + toffset componentLastChar(size_t icomp); + + bool erroneous(); + + const Segment & segment() const throw(); + Segment & segment() throw(); + +protected: + Segment * m_pseg; + GrSlotOutput * m_pslout; + int m_islout; // signed, so it can return kInvalid +}; + +inline Segment & GlyphInfo::segment() throw () { + return *m_pseg; +} + +inline const Segment & GlyphInfo::segment() const throw () { + return *m_pseg; +} + + +/*---------------------------------------------------------------------------------------------- + The GlyphIterator class allows the Graphite client to iterate over a contiguous + range of glyphs for the segment. +----------------------------------------------------------------------------------------------*/ +class GlyphIterator +: public std::iterator<std::random_access_iterator_tag, gr::GlyphInfo> +{ + friend class GlyphInfo; + friend class Segment; + + // Pointers into the glyph infor store + GlyphInfo * _itr; + +protected: + // Constructor + GlyphIterator(Segment & seg, size_t iginf); + +public: + // Default constructor. + GlyphIterator() throw (): _itr(0) {} + + explicit GlyphIterator(const GlyphSetIterator &); + + // Forward iterator requirements. + reference operator*() const { assert(_itr); return *_itr; } + pointer operator->() const { return _itr; } + GlyphIterator & operator++() throw() { ++_itr; return *this; } + GlyphIterator operator++(int) throw() { GlyphIterator tmp = *this; operator++(); return tmp; } + + // Bidirectional iterator requirements + GlyphIterator & operator--() throw() { --_itr; return *this; } + GlyphIterator operator--(int) throw() { GlyphIterator tmp = *this; operator--(); return tmp; } + + // Random access iterator requirements + reference operator[](difference_type n) const { return _itr[n]; } + GlyphIterator & operator+=(difference_type n) throw() { _itr += n; return *this; } + GlyphIterator operator+(difference_type n) const throw() { GlyphIterator r = *this; return r += n; } + GlyphIterator & operator-=(difference_type n) throw() { _itr -= n; return *this; } + GlyphIterator operator-(difference_type n) const throw() { GlyphIterator r = *this; return r += -n; } + + // Relational operators. + // Forward iterator requirements + bool operator==(const GlyphIterator & rhs) const throw() { return _itr == rhs._itr; } + bool operator!=(const GlyphIterator & rhs) const throw() { return !(*this == rhs); } + + // Random access iterator requirements + bool operator<(const GlyphIterator & rhs) const throw() { return _itr < rhs._itr; } + bool operator>(const GlyphIterator & rhs) const throw() { return _itr > rhs._itr; } + bool operator<=(const GlyphIterator & rhs) const throw() { return !(*this > rhs); } + bool operator>=(const GlyphIterator & rhs) const throw() { return !(*this < rhs); } + + difference_type operator-(const GlyphIterator & rhs) const throw() { return _itr - rhs._itr; } +}; + +inline GlyphIterator operator+(const GlyphIterator::difference_type n, const GlyphIterator & rhs) +{ + return rhs + n; +} + + +/*---------------------------------------------------------------------------------------------- + The GlyphSetIterator class allows the Graphite client to iterate over a non-contiguous + set of glyphs for the segment, this is almost always the set of glyphs for a character. +----------------------------------------------------------------------------------------------*/ +class GlyphSetIterator +: public std::iterator<std::random_access_iterator_tag, gr::GlyphInfo> +{ + friend class GlyphInfo; + friend class Segment; + + // Segment containing the glyphs being iterated over. + const Segment * _seg_ptr; + + // Sometimes, in the case of character-to-glyph look-ups or attached + // children, we need to represent a non-contiguous list; in these cases + // we first map through a vector of output-slot objects into the actual + // glyph-info store. + std::vector<int>::const_iterator _itr; + +protected: + // Constructor that includes output-slot mapping list, used for non-contiguous lists: + GlyphSetIterator(Segment & seg, size_t islout, const std::vector<int> & vislout) + : _seg_ptr(&seg), _itr(vislout.begin() + islout) + {} + +public: + // Default constructor--no output-slot mapping: + GlyphSetIterator() throw (): _seg_ptr(0), _itr(std::vector<int>::const_iterator()) + {} + + // Forward iterator requirements. + reference operator*() const; + pointer operator->() const { return &(operator*()); } + GlyphSetIterator & operator++() throw() { ++_itr; return *this; } + GlyphSetIterator operator++(int) throw() { GlyphSetIterator tmp = *this; operator++(); return tmp; } + + // Bidirectional iterator requirements + GlyphSetIterator & operator--() throw() { --_itr; return *this; } + GlyphSetIterator operator--(int) throw() { GlyphSetIterator tmp = *this; operator--(); return tmp; } + + // Random access iterator requirements + reference operator[](difference_type n) const { return *operator+(n); } + GlyphSetIterator & operator+=(difference_type n) throw() { _itr += n; return *this; } + GlyphSetIterator operator+(difference_type n) const throw() { GlyphSetIterator r = *this; return r += n; } + GlyphSetIterator & operator-=(difference_type n) throw() { operator+=(-n); return *this; } + GlyphSetIterator operator-(difference_type n) const throw() { GlyphSetIterator r = *this; return r += -n; } + + // Relational operators. + // Forward iterator requirements + bool operator==(const GlyphSetIterator & rhs) const throw() { return _itr == rhs._itr; } + bool operator!=(const GlyphSetIterator & rhs) const throw() { return !(*this == rhs); } + + // Random access iterator requirements + bool operator<(const GlyphSetIterator & rhs) const throw() { return _itr < rhs._itr; } + bool operator>(const GlyphSetIterator & rhs) const throw() { return _itr > rhs._itr; } + bool operator<=(const GlyphSetIterator & rhs) const throw() { return !(*this > rhs); } + bool operator>=(const GlyphSetIterator & rhs) const throw() { return !(*this < rhs); } + + difference_type operator-(const GlyphSetIterator & rhs) const throw() { return _itr - rhs._itr; } +}; + +inline GlyphSetIterator operator+(const GlyphSetIterator::difference_type n, const GlyphSetIterator & rhs) +{ + return rhs + n; +} + + +/*---------------------------------------------------------------------------------------------- + The GlyphInfo class provides access to details about a single glyph within a segment. +----------------------------------------------------------------------------------------------*/ +class LayoutEnvironment +{ +public: + LayoutEnvironment() + { + // Defaults: + m_fStartOfLine = true; + m_fEndOfLine = true; + m_lbBest = klbWordBreak; + m_lbWorst = klbClipBreak; + m_fRightToLeft = false; + m_twsh = ktwshAll; + m_pstrmLog = NULL; + m_fDumbFallback = false; + m_psegPrev = NULL; + m_psegInit = NULL; + m_pjust = NULL; + } + LayoutEnvironment(LayoutEnvironment & layout) + { + m_fStartOfLine = layout.m_fStartOfLine; + m_fEndOfLine = layout.m_fEndOfLine; + m_lbBest = layout.m_lbBest; + m_lbWorst = layout.m_lbWorst; + m_fRightToLeft = layout.m_fRightToLeft; + m_twsh = layout.m_twsh; + m_pstrmLog = layout.m_pstrmLog; + m_fDumbFallback = layout.m_fDumbFallback; + m_psegPrev = layout.m_psegPrev; + m_psegInit = layout.m_psegInit; + m_pjust = layout.m_pjust; + } + + // Setters: + inline void setStartOfLine(bool f) { m_fStartOfLine = f; } + inline void setEndOfLine(bool f) { m_fEndOfLine = f; } + inline void setBestBreak(LineBrk lb) { m_lbBest = lb; } + inline void setWorstBreak(LineBrk lb) { m_lbWorst = lb; } + inline void setRightToLeft(bool f) { m_fRightToLeft = f; } + inline void setTrailingWs(TrWsHandling twsh) { m_twsh = twsh; } + inline void setLoggingStream(std::ostream * pstrm) { m_pstrmLog = pstrm; } + inline void setDumbFallback(bool f) { m_fDumbFallback = f; } + inline void setPrevSegment(Segment * pseg) { m_psegPrev = pseg; } + inline void setSegmentForInit(Segment * pseg) { m_psegInit = pseg; } + inline void setJustifier(IGrJustifier * pjust) { m_pjust = pjust; } + + // Getters: + inline bool startOfLine() { return m_fStartOfLine; } + inline bool endOfLine() { return m_fEndOfLine; } + inline LineBrk bestBreak() { return m_lbBest; } + inline LineBrk worstBreak() { return m_lbWorst; } + inline bool rightToLeft() { return m_fRightToLeft; } + inline TrWsHandling trailingWs() { return m_twsh; } + inline std::ostream * loggingStream() { return m_pstrmLog; } + inline bool dumbFallback() { return m_fDumbFallback; } + inline Segment * prevSegment() { return m_psegPrev; } + inline Segment * segmentForInit() { return m_psegInit; } + inline IGrJustifier * justifier() { return m_pjust; } + +protected: + bool m_fStartOfLine; + bool m_fEndOfLine; + LineBrk m_lbBest; + LineBrk m_lbWorst; + bool m_fRightToLeft; + TrWsHandling m_twsh; + std::ostream * m_pstrmLog; + bool m_fDumbFallback; + Segment * m_psegPrev; + Segment * m_psegInit; + IGrJustifier * m_pjust; +}; + +} // namespace gr + +#if defined(GR_NO_NAMESPACE) +using namespace gr; +#endif + +#endif // !SEGMENTAUX_INCLUDED diff --git a/Build/source/libs/graphite-engine/include/graphite/SegmentPainter.h b/Build/source/libs/graphite-engine/include/graphite/SegmentPainter.h new file mode 100644 index 00000000000..caa7d445690 --- /dev/null +++ b/Build/source/libs/graphite-engine/include/graphite/SegmentPainter.h @@ -0,0 +1,233 @@ +/*--------------------------------------------------------------------*//*:Ignore this sentence. +Copyright (C) 1999, 2001 SIL International. All rights reserved. + +Distributable under the terms of either the Common Public License or the +GNU Lesser General Public License, as specified in the LICENSING.txt file. + +File: SegmentPainter.h +Responsibility: Sharon Correll +Last reviewed: Not yet. + +Description: + Defines the class for a Graphite text segment. +----------------------------------------------------------------------------------------------*/ +#ifdef _MSC_VER +#pragma once +#endif +#ifndef GR_SEGPAINTER_INCLUDED +#define GR_SEGPAINTER_INCLUDED + +// undo automagic DrawTextA DrawTextW stuff +// #undef DrawText + +//:End Ignore + + +namespace gr +{ + + class Segment; +/*---------------------------------------------------------------------------------------------- + A SegmentPainter handles the UI-related operations on for segment. + + This superclass does not know how to do any actual drawing, because it has no access + to a device. Subclasses are needed to handle drawing on the various platforms. In addition, + it is legitimate to make a subclass to override the behavior of a specific piece of + functionality. + + Hungarian: segp +----------------------------------------------------------------------------------------------*/ +class SegmentPainter +{ +public: + // Static methods + + // Constructors/destructors/etc. + SegmentPainter(Segment * pseg, float xOrigin = 0, float yOrigin = 0); + //SegmentPainter(Segment * pseg, float xOrigin, float yOrigin); + + virtual ~SegmentPainter(); + + virtual void setOrigin(float xsOrigin, float ysOrigin); + virtual void setPosition(float xdPosition, float ydPosition); + virtual void setScalingFactors(float xFactor, float yFactor); + + virtual void setBuggyDisplayFormat(int strategy, long textColor, long backColor, + long underlineColor) + { + // Currently not implemented to do anything useful. + } + + // The paint method must be implemented by a concrete subclass: + virtual void paint() = 0; + + virtual void drawInsertionPoint(int ichwIP, bool fAssocPrev, bool bOn, bool fForceSplit); + virtual void positionsOfIP(int ichwIP, bool fAssocPrev, bool fForceSplit, + Rect * prdPrimary, Rect * prdSecondary); + virtual bool drawSelectionRange(int ichwMin, int ichwLim, + float ydTop, float ydBottom, bool bOn); + virtual bool positionsOfRange(int ichwMin, int ichwLim, + float ydTop, float ydBottom, Rect * prsBounds); + virtual size_t getUnderlinePlacement(int ichwMin, int ichwLim, + bool fSkipSpace, + size_t crgMax, // number of ranges allowed + float * prgxdLefts, float * prgxdRights, float * prgydUnderline); + + virtual void pointToChar(Point zptdClickPosition, int * pichw, bool * pfAssocPrev); + virtual LgIpValidResult isValidInsertionPoint(int ichwIP); + virtual bool doBoundariesCoincide(bool fBoundaryEnd, bool fBoundaryRight); + virtual int arrowKeyPosition(int ichwIP, bool * pfAssocPrev, + bool fRight, bool * pfInThisSeg); + virtual int extendSelectionPosition( + int charIndex, bool assocPrevMatch, bool assocPrevNeeded, + int anchorIndex, bool movingRight, bool * inThisSeg); + + + // For calculating underlines: + struct LineSeg { // hungarian: ls + float left; + float right; + }; + + + static float ScaleX(float xs, Rect rs, Rect rd); + static float ScaleY(float ys, Rect rs, Rect rd); + + float ScaleXToDest(float xs) + { + float xd = ((xs + m_xsOrigin) * m_xFactor) + m_xdPosition; + return xd; + } + //int ScaleXToDest(int xs) + //{ + // int xd = (((xs + m_xsOriginInt) * m_xFactor64) >> 6) + m_xdPositionInt; + // return xd; // >> 6 means div by 64 + //} + float ScaleYToDest(float ys) + { + float yd = ((ys + m_ysOrigin) * m_yFactor) + m_ydPosition; + return yd; + } + + float ScaleXToSource(float xd) + { + float xs = ((xd - m_xdPosition) / m_xFactor) - m_xsOrigin; + return xs; + } + float ScaleYToSource(float yd) + { + float ys = ((yd - m_ydPosition) / m_yFactor) - m_ysOrigin; + return ys; + } + +protected: + // Member variables: + + Segment * m_pseg; + + // transformation factors: + float m_xsOrigin; + float m_ysOrigin; + float m_xdPosition; + float m_ydPosition; + float m_xFactor; // destination / source + float m_yFactor; // destination / source + + // optimizations for when we need integer arithmetic (converting between int and float is + // very slow) - DELETE these. + //int m_xsOriginInt; + //int m_xdPositionInt; + //int m_xFactor64; + + //gr::Rect m_rectSrc; + + // Other methods: + + void CalcOrDrawInsertionPoint( + int ich, bool fAssocPrev, bool bOn, bool fForceSplit, + Rect * prectPrimary, Rect * prectSecondary); + void InvertIBeam(float xs, float ysTop, float ysBottom, bool fAssocPrev, + Rect * prdRet); + void InvertSplitIP(float xs, float ysTop, float ysBottom, + bool fTop, bool fAssocRight, bool fSecondary, float ysMinSplitHt, + Rect * prdRet); + void CalcIP(int ichw, bool fBefore, + float * pxs, float * pysTop, float * pysBottom, bool * pfRtl); + bool CloseIPPositions( + float * pxsBefore, float ysBeforeTop, float ysBeforeBottom, + float * pxsAfter, float ysAfterTop, float ysAfterBottom); + bool AtEdgeOfCluster(GrSlotOutput * pslout, int islout, bool fBefore); + bool CanInsertIntoCluster(GrSlotOutput * pslout, int islout); + + void CalcPartialLigatures(bool * prgfAllSelected, + int ichwMinSeg, int ichwLimSeg, + int ichwMinSel, int ichwLimSel); + void CalcHighlightRect(int ichw, + std::vector<Rect> & vrs, std::vector<bool> & vfEntireLineHt, + bool fJustComponent, bool * rgfHighlighted, bool fSkipTrSpace); + void CalcCompleteCluster(int islout, + std::vector<Rect> & vrs, std::vector<bool> & vfEntireLineHt, bool * prgfHighlighted); + void AddRectWithoutOverlaps(std::vector<Rect> & vrect, Rect rectToAdd); + bool AnyArea(Rect * prect); + bool AdjustRectsToNotOverlap(std::vector<Rect> & vrect, int irect, Rect * prect2, + std::vector<Rect> & vrectMoreToAdd); + void AssertNoOverlaps(std::vector<Rect> & vrect); + + void AddLineSegWithoutOverlaps(std::vector<LineSeg> & vls, LineSeg lsToAdd); + bool AnyLength(LineSeg * pls); + bool AdjustLineSegsToNotOverlap(std::vector<LineSeg> & vls, int ils, LineSeg * pls2, + std::vector<LineSeg> & vlsMoreToAdd); + void AssertNoOverlaps(std::vector<LineSeg> & vls); + + GrResult ArrowKeyPositionAux(int * pichwIP, bool * pfAssocPrev, + bool fRight, bool fMovingIn, + bool fAssocPrevMatch, bool fAssocPrevNeeded, + bool * pfResult); + bool ArrowKeyPositionInternal(int * pichw, bool * pfAssocPrev, + bool fRight, bool fAssocPrevMatch, bool fAssocPrevNeeded, int * nNextOrPrevSeg); + bool AdjacentLigComponent(int * pichw, bool * pfAssocPrev, bool fRight, bool fMove); + + int PointToCharAux(float xsTry, float ysTry, + float * pxsGlyphOffset, float * pxsGlyphWidth); + + // Platform-specific routines: + + GrResult DrawSegmentPlatform(float xs, float ys); + + // Low-level routines--these must be implemented appropriate by subclasses: + + virtual void InvertRect(float xLeft, float yTop, float xRight, float yBottom) + { + GrAssert(false); // no device context + } + + //void SetFontProps(); + virtual void SetFontProps(unsigned long clrFore, unsigned long clrBack); + +}; + +/*---------------------------------------------------------------------------------------------- + This is a subclass of SegmentPainter for which the paint operation is unnecessary. +----------------------------------------------------------------------------------------------*/ +class SegmentNonPainter : public SegmentPainter +{ +public: + SegmentNonPainter(Segment * pseg) + : SegmentPainter(pseg) + { + } + + void paint() + { + GrAssert(false); + throw; + } +}; + +} // namespace gr + +#if defined(GR_NO_NAMESPACE) +using namespace gr; +#endif + +#endif // !GR_SEGPAINTER_INCLUDED |