jpayne@69: /* GRAPHITE2 LICENSING jpayne@69: jpayne@69: Copyright 2010, SIL International jpayne@69: All rights reserved. jpayne@69: jpayne@69: This library is free software; you can redistribute it and/or modify jpayne@69: it under the terms of the GNU Lesser General Public License as published jpayne@69: by the Free Software Foundation; either version 2.1 of License, or jpayne@69: (at your option) any later version. jpayne@69: jpayne@69: This program is distributed in the hope that it will be useful, jpayne@69: but WITHOUT ANY WARRANTY; without even the implied warranty of jpayne@69: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU jpayne@69: Lesser General Public License for more details. jpayne@69: jpayne@69: You should also have received a copy of the GNU Lesser General Public jpayne@69: License along with this library in the file named "LICENSE". jpayne@69: If not, write to the Free Software Foundation, 51 Franklin Street, jpayne@69: Suite 500, Boston, MA 02110-1335, USA or visit their web page on the jpayne@69: internet at http://www.fsf.org/licenses/lgpl.html. jpayne@69: jpayne@69: Alternatively, the contents of this file may be used under the terms jpayne@69: of the Mozilla Public License (http://mozilla.org/MPL) or the GNU jpayne@69: General Public License, as published by the Free Software Foundation, jpayne@69: either version 2 of the License or (at your option) any later version. jpayne@69: */ jpayne@69: #pragma once jpayne@69: jpayne@69: #include "graphite2/Types.h" jpayne@69: #include "graphite2/Font.h" jpayne@69: jpayne@69: #ifdef __cplusplus jpayne@69: extern "C" jpayne@69: { jpayne@69: #endif jpayne@69: jpayne@69: enum gr_break_weight { jpayne@69: gr_breakNone = 0, jpayne@69: /* after break weights */ jpayne@69: gr_breakWhitespace = 10, jpayne@69: gr_breakWord = 15, jpayne@69: gr_breakIntra = 20, jpayne@69: gr_breakLetter = 30, jpayne@69: gr_breakClip = 40, jpayne@69: /* before break weights */ jpayne@69: gr_breakBeforeWhitespace = -10, jpayne@69: gr_breakBeforeWord = -15, jpayne@69: gr_breakBeforeIntra = -20, jpayne@69: gr_breakBeforeLetter = -30, jpayne@69: gr_breakBeforeClip = -40 jpayne@69: }; jpayne@69: jpayne@69: enum gr_justFlags { jpayne@69: /// Indicates that this segment is a complete line jpayne@69: gr_justCompleteLine = 0, jpayne@69: /// Indicates that the start of the slot list is not at the start of a line jpayne@69: gr_justStartInline = 1, jpayne@69: /// Indicates that the end of the slot list is not at the end of a line jpayne@69: gr_justEndInline = 2 jpayne@69: }; jpayne@69: jpayne@69: /** Used for looking up slot attributes. Most are already available in other functions **/ jpayne@69: enum gr_attrCode { jpayne@69: /// adjusted glyph advance in x direction in design units jpayne@69: gr_slatAdvX = 0, jpayne@69: /// adjusted glyph advance in y direction (usually 0) in design units jpayne@69: gr_slatAdvY, jpayne@69: /// returns 0. Deprecated. jpayne@69: gr_slatAttTo, jpayne@69: /// This slot attaches to its parent at the given design units in the x direction jpayne@69: gr_slatAttX, jpayne@69: /// This slot attaches to its parent at the given design units in the y direction jpayne@69: gr_slatAttY, jpayne@69: /// This slot attaches to its parent at the given glyph point (not implemented) jpayne@69: gr_slatAttGpt, jpayne@69: /// x-direction adjustment from the given glyph point (not implemented) jpayne@69: gr_slatAttXOff, jpayne@69: /// y-direction adjustment from the given glyph point (not implemented) jpayne@69: gr_slatAttYOff, jpayne@69: /// Where on this glyph should align with the attachment point on the parent glyph in the x-direction. jpayne@69: gr_slatAttWithX, jpayne@69: /// Where on this glyph should align with the attachment point on the parent glyph in the y-direction jpayne@69: gr_slatAttWithY, jpayne@69: /// Which glyph point on this glyph should align with the attachment point on the parent glyph (not implemented). jpayne@69: gr_slatWithGpt, jpayne@69: /// Adjustment to gr_slatWithGpt in x-direction (not implemented) jpayne@69: gr_slatAttWithXOff, jpayne@69: /// Adjustment to gr_slatWithGpt in y-direction (not implemented) jpayne@69: gr_slatAttWithYOff, jpayne@69: /// Attach at given nesting level (not implemented) jpayne@69: gr_slatAttLevel, jpayne@69: /// Line break breakweight for this glyph jpayne@69: gr_slatBreak, jpayne@69: /// Ligature component reference (not implemented) jpayne@69: gr_slatCompRef, jpayne@69: /// bidi directionality of this glyph (not implemented) jpayne@69: gr_slatDir, jpayne@69: /// Whether insertion is allowed before this glyph jpayne@69: gr_slatInsert, jpayne@69: /// Final positioned position of this glyph relative to its parent in x-direction in pixels jpayne@69: gr_slatPosX, jpayne@69: /// Final positioned position of this glyph relative to its parent in y-direction in pixels jpayne@69: gr_slatPosY, jpayne@69: /// Amount to shift glyph by in x-direction design units jpayne@69: gr_slatShiftX, jpayne@69: /// Amount to shift glyph by in y-direction design units jpayne@69: gr_slatShiftY, jpayne@69: /// attribute user1 jpayne@69: gr_slatUserDefnV1, jpayne@69: /// not implemented jpayne@69: gr_slatMeasureSol, jpayne@69: /// not implemented jpayne@69: gr_slatMeasureEol, jpayne@69: /// Amount this slot can stretch (not implemented) jpayne@69: gr_slatJStretch, jpayne@69: /// Amount this slot can shrink (not implemented) jpayne@69: gr_slatJShrink, jpayne@69: /// Granularity by which this slot can stretch or shrink (not implemented) jpayne@69: gr_slatJStep, jpayne@69: /// Justification weight for this glyph (not implemented) jpayne@69: gr_slatJWeight, jpayne@69: /// Amount this slot mush shrink or stretch in design units jpayne@69: gr_slatJWidth = 29, jpayne@69: /// SubSegment split point jpayne@69: gr_slatSegSplit = gr_slatJStretch + 29, jpayne@69: /// User defined attribute, see subattr for user attr number jpayne@69: gr_slatUserDefn, jpayne@69: /// Bidi level jpayne@69: gr_slatBidiLevel = 56, jpayne@69: /// Collision flags jpayne@69: gr_slatColFlags, jpayne@69: /// Collision constraint rectangle left (bl.x) jpayne@69: gr_slatColLimitblx, jpayne@69: /// Collision constraint rectangle lower (bl.y) jpayne@69: gr_slatColLimitbly, jpayne@69: /// Collision constraint rectangle right (tr.x) jpayne@69: gr_slatColLimittrx, jpayne@69: /// Collision constraint rectangle upper (tr.y) jpayne@69: gr_slatColLimittry, jpayne@69: /// Collision shift x jpayne@69: gr_slatColShiftx, jpayne@69: /// Collision shift y jpayne@69: gr_slatColShifty, jpayne@69: /// Collision margin jpayne@69: gr_slatColMargin, jpayne@69: /// Margin cost weight jpayne@69: gr_slatColMarginWt, jpayne@69: // Additional glyph that excludes movement near this one: jpayne@69: gr_slatColExclGlyph, jpayne@69: gr_slatColExclOffx, jpayne@69: gr_slatColExclOffy, jpayne@69: // Collision sequence enforcing attributes: jpayne@69: gr_slatSeqClass, jpayne@69: gr_slatSeqProxClass, jpayne@69: gr_slatSeqOrder, jpayne@69: gr_slatSeqAboveXoff, jpayne@69: gr_slatSeqAboveWt, jpayne@69: gr_slatSeqBelowXlim, jpayne@69: gr_slatSeqBelowWt, jpayne@69: gr_slatSeqValignHt, jpayne@69: gr_slatSeqValignWt, jpayne@69: jpayne@69: /// not implemented jpayne@69: gr_slatMax, jpayne@69: /// not implemented jpayne@69: gr_slatNoEffect = gr_slatMax + 1 jpayne@69: }; jpayne@69: jpayne@69: enum gr_bidirtl { jpayne@69: /// Underlying paragraph direction is RTL jpayne@69: gr_rtl = 1, jpayne@69: /// Set this to not run the bidi pass internally, even if the font asks for it. jpayne@69: /// This presumes that the segment is in a single direction. Most of the time jpayne@69: /// this bit should be set unless you know you are passing full paragraphs of text. jpayne@69: gr_nobidi = 2, jpayne@69: /// Disable auto mirroring for rtl text jpayne@69: gr_nomirror = 4 jpayne@69: }; jpayne@69: jpayne@69: typedef struct gr_char_info gr_char_info; jpayne@69: typedef struct gr_segment gr_segment; jpayne@69: typedef struct gr_slot gr_slot; jpayne@69: jpayne@69: /** Returns Unicode character for a charinfo. jpayne@69: * jpayne@69: * @param p Pointer to charinfo to return information on. jpayne@69: */ jpayne@69: GR2_API unsigned int gr_cinfo_unicode_char(const gr_char_info* p/*not NULL*/); jpayne@69: jpayne@69: /** Returns breakweight for a charinfo. jpayne@69: * jpayne@69: * @return Breakweight is a number between -50 and 50 indicating the cost of a jpayne@69: * break before or after this character. If the value < 0, the absolute value jpayne@69: * is this character's contribution to the overall breakweight before it. If the value jpayne@69: * > 0, then the value is this character's contribution to the overall breakweight after it. jpayne@69: * The overall breakweight between two characters is the maximum of the breakweight jpayne@69: * contributions from the characters either side of it. If a character makes no jpayne@69: * contribution to the breakweight on one side of it, the contribution is considered jpayne@69: * to be 0. jpayne@69: * @param p Pointer to charinfo to return information on. jpayne@69: */ jpayne@69: GR2_API int gr_cinfo_break_weight(const gr_char_info* p/*not NULL*/); jpayne@69: jpayne@69: /** Returns the slot index that after this character is after in the slot stream jpayne@69: * jpayne@69: * In effect each character is associated with a set of slots and this returns jpayne@69: * the index of the last slot in the segment this character is associated with. jpayne@69: * jpayne@69: * @return after slot index between 0 and gr_seg_n_slots() jpayne@69: * @param p Pointer to charinfo to return information on. jpayne@69: */ jpayne@69: GR2_API int gr_cinfo_after(const gr_char_info* p/*not NULL*/); jpayne@69: jpayne@69: /** Returns the slot index that before this character is before in the slot stream jpayne@69: * jpayne@69: * In effect each character is associated with a set of slots and this returns jpayne@69: * the index of the first slot in the segment this character is associated with. jpayne@69: * jpayne@69: * @return before slot index between 0 and gr_seg_n_slots() jpayne@69: * @param p Pointer to charinfo to return information on. jpayne@69: */ jpayne@69: GR2_API int gr_cinfo_before(const gr_char_info* p/*not NULL*/); jpayne@69: jpayne@69: /** Returns the code unit index of this character in the input string jpayne@69: * jpayne@69: * @return code unit index between 0 and the end of the string jpayne@69: * @param p Pointer to charinfo to return information on. jpayne@69: */ jpayne@69: GR2_API size_t gr_cinfo_base(const gr_char_info* p/*not NULL*/); jpayne@69: jpayne@69: /** Returns the number of unicode characters in a string. jpayne@69: * jpayne@69: * @return number of characters in the string jpayne@69: * @param enc Specifies the type of data in the string: utf8, utf16, utf32 jpayne@69: * @param buffer_begin The start of the string jpayne@69: * @param buffer_end Measure up to the first nul or when end is reached, whichever is earliest. jpayne@69: * This parameter may be NULL. jpayne@69: * @param pError If there is a structural fault in the string, the location is returned jpayne@69: * in this variable. If no error occurs, pError will contain NULL. NULL jpayne@69: * may be passed for pError if no such information is required. jpayne@69: */ jpayne@69: GR2_API size_t gr_count_unicode_characters(enum gr_encform enc, const void* buffer_begin, const void* buffer_end, const void** pError); jpayne@69: jpayne@69: /** Creates and returns a segment. jpayne@69: * jpayne@69: * @return a segment that needs seg_destroy called on it. May return NULL if bad problems jpayne@69: * in segment processing. jpayne@69: * @param font Gives the size of the font in pixels per em for final positioning. If jpayne@69: * NULL, positions are returned in design units, i.e. at a ppm of the upem jpayne@69: * of the face. jpayne@69: * @param face The face containing all the non-size dependent information. jpayne@69: * @param script This is a tag containing a script identifier that is used to choose jpayne@69: * which graphite table within the font to use. Maybe 0. Tag may be 4 chars jpayne@69: * NULL padded in LSBs or space padded in LSBs. jpayne@69: * @param pFeats Pointer to a feature values to be used for the segment. Only one jpayne@69: * feature values may be used for a segment. If NULL the default features jpayne@69: * for the font will be used. jpayne@69: * @param enc Specifies what encoding form the string is in (utf8, utf16, utf32) jpayne@69: * @param pStart Start of the string jpayne@69: * @param nChars Number of unicode characters to process in the string. The string will jpayne@69: * be processed either up to the first NULL or until nChars have been jpayne@69: * processed. nChars is also used to initialise the internal memory jpayne@69: * allocations of the segment. So it is wise not to make nChars too much jpayne@69: * greater than the actual number of characters being processed. jpayne@69: * @param dir Specifies whether the segment is processed right to left (1) or left to jpayne@69: * right (0) and whether to run the internal bidi pass, if a font requests it. jpayne@69: * See enum gr_bidirtl for details. jpayne@69: */ jpayne@69: GR2_API gr_segment* gr_make_seg(const gr_font* font, const gr_face* face, gr_uint32 script, const gr_feature_val* pFeats, enum gr_encform enc, const void* pStart, size_t nChars, int dir); jpayne@69: jpayne@69: /** Destroys a segment, freeing the memory. jpayne@69: * jpayne@69: * @param p The segment to destroy jpayne@69: */ jpayne@69: GR2_API void gr_seg_destroy(gr_segment* p); jpayne@69: jpayne@69: /** Returns the advance for the whole segment. jpayne@69: * jpayne@69: * Returns the width of the segment up to the next glyph origin after the segment jpayne@69: */ jpayne@69: GR2_API float gr_seg_advance_X(const gr_segment* pSeg/*not NULL*/); jpayne@69: jpayne@69: /** Returns the height advance for the segment. **/ jpayne@69: GR2_API float gr_seg_advance_Y(const gr_segment* pSeg/*not NULL*/); jpayne@69: jpayne@69: /** Returns the number of gr_char_infos in the segment. **/ jpayne@69: GR2_API unsigned int gr_seg_n_cinfo(const gr_segment* pSeg/*not NULL*/); jpayne@69: jpayne@69: /** Returns a gr_char_info at a given index in the segment. **/ jpayne@69: GR2_API const gr_char_info* gr_seg_cinfo(const gr_segment* pSeg/*not NULL*/, unsigned int index/*must be