1 #ifndef FONTFORGE_SFD_H 2 #define FONTFORGE_SFD_H 3 4 #include <fontforge-config.h> 5 6 #include "splinefont.h" 7 8 typedef struct sfd_getfontmetadatadata { 9 // these indicate if we saw some metadata or not. 10 // perhaps the caller wants to do something special 11 // if the metadata was present/missing. 12 int hadtimes; 13 int had_layer_cnt; 14 15 // state that is mostly interesting to SFD_GetFontMetaData() only 16 struct Base* last_base; 17 struct basescript* last_base_script; 18 OTLookup* lastpotl; 19 OTLookup* lastsotl; 20 KernClass* lastkc; 21 KernClass* lastvkc; 22 struct ff_glyphclasses* lastgroup; 23 struct ff_rawoffsets* lastgroupkern; 24 struct ff_rawoffsets* lastgroupvkern; 25 FPST* lastfp; 26 ASM* lastsm; 27 struct ttf_table* lastttf[2]; 28 } SFD_GetFontMetaDataData; 29 30 extern void SFD_GetFontMetaDataData_Init(SFD_GetFontMetaDataData* d); 31 extern bool SFD_GetFontMetaData(FILE *sfd, char *tok, SplineFont *sf, SFD_GetFontMetaDataData* d); 32 extern void SFD_GetFontMetaDataVoid(FILE *sfd, char *tok, SplineFont *sf, void* d); 33 34 /** 35 * Create, open and unlink a new temporary file. This allows the 36 * caller to write to and read from the file without needing to worry 37 * about cleaning up the filesystem at all. 38 * 39 * On Linux, this will create a new file in /tmp with a secure name, 40 * open it, and delete the file from the filesystem. The application 41 * can still happily use the file as it has it open, but once it is 42 * closed or the application itself closes (or crashes) then the file 43 * will be expunged for you by the kernel. 44 * 45 * The caller can fclose() the returned file. Other applications will 46 * not be able to find the file by name anymore when this call 47 * returns. 48 * 49 * This function returns 0 if error encountered. 50 */ 51 extern FILE* MakeTemporaryFile(void); 52 53 /* 54 * Convert the contents of a File* to a newly allocated string 55 * The caller needs to free the returned string. 56 */ 57 extern char* FileToAllocatedString(FILE *f); 58 extern char *getquotedeol(FILE *sfd); 59 extern int getname(FILE *sfd, char *tokbuf); 60 extern void SFDGetKerns(FILE *sfd, SplineChar *sc, char* ttok); 61 extern void SFDGetPSTs(FILE *sfd, SplineChar *sc, char* ttok); 62 63 /** 64 * Move the sfd file pointer to the start of the next glyph. Return 0 65 * if there is no next glyph. Otherwise, a copy of the string on the 66 * line of the SFD file that starts the glyph is returned. The caller 67 * should return the return value of this function. 68 * 69 * If the glyph starts with: 70 * StartChar: a 71 * The the return value with be "a" (sans the quotes). 72 * 73 * This is handy if the caller is done with a glyph and just wants to 74 * skip to the start of the next one. 75 */ 76 extern char* SFDMoveToNextStartChar(FILE* sfd); 77 78 /** 79 * Some references in the SFD file are to a numeric glyph ID. As a 80 * sneaky method to handle that, fontforge will load these glyph 81 * numbers into the pointers which should refer to the glyph. For 82 * example, in kerning, instead of pointing to the splinechar for the 83 * "v" glyph, the ID might be stored there, say the number 143. This 84 * fixup function will convert such 143 references to being pointers 85 * to the splinechar with a numeric ID of 143. It is generally a good 86 * idea to do this, as some fontforge code will of course assume a 87 * pointer to a splinechar is a pointer to a splinechar and not just 88 * the glyph index of that splinechar. 89 * 90 * MIQ updated this in Oct 2012 to be more forgiving when called twice 91 * or on a splinefont which has some of it's references already fixed. 92 * This was to allow partial updates of data structures from SFD 93 * fragments and the fixup to operate just on those references which 94 * need to be fixed. 95 */ 96 extern void SFDFixupRefs(SplineFont *sf); 97 98 /** 99 * Dump a single undo for the given splinechar to the file at "sfd". 100 * The keyPrefix can be either Undo or Redo to generate the correct XML 101 * element, and idx is the index into the undoes list that 'u' was found at 102 * so that a stream of single undo/redo elements can be saved and reloaded 103 * in the correct order. 104 */ 105 extern void SFDDumpUndo(FILE *sfd, SplineChar *sc, Undoes *u, const char* keyPrefix, int idx); 106 107 extern char **NamesReadSFD(char *filename); 108 extern char *utf7toutf8_copy(const char *_str); 109 extern char *utf8toutf7_copy(const char *_str); 110 extern const char *EncName(Encoding *encname); 111 extern int SFDDoesAnyBackupExist(char* filename); 112 extern int SFD_DumpSplineFontMetadata(FILE *sfd, SplineFont *sf); 113 extern int SFDWriteBak(char *filename, SplineFont *sf, EncMap *map, EncMap *normal); 114 extern int SFDWriteBakExtended(char* locfilename, SplineFont *sf, EncMap *map, EncMap *normal, int s2d, int localPrefMaxBackupsToKeep); 115 extern MacFeat *SFDParseMacFeatures(FILE *sfd, char *tok); 116 extern SplineChar *SFDReadOneChar(SplineFont *cur_sf, const char *name); 117 extern SplineFont *SFDirRead(char *filename); 118 extern SplineFont *_SFDRead(char *filename, FILE *sfd); 119 extern SplineFont *SFRecoverFile(char *autosavename, int inquire, int *state); 120 extern Undoes *SFDGetUndo(FILE *sfd, SplineChar *sc, const char* startTag, int current_layer); 121 extern void SFAutoSave(SplineFont *sf, EncMap *map); 122 extern void SFClearAutoSave(SplineFont *sf); 123 extern void SFDDumpCharStartingMarker(FILE *sfd, SplineChar *sc); 124 extern void SFD_DumpKerns(FILE *sfd, SplineChar *sc, int *newgids); 125 extern void SFD_DumpLookup(FILE *sfd, SplineFont *sf); 126 extern void SFDDumpMacFeat(FILE *sfd, MacFeat *mf); 127 extern void SFD_DumpPST(FILE *sfd, SplineChar *sc); 128 extern void SFTimesFromFile(SplineFont *sf, FILE *file); 129 extern SplineFont *SFDRead(char *filename); 130 extern int SFDWrite(char *filename,SplineFont *sf,EncMap *map,EncMap *normal, int todir); 131 132 typedef void (*visitSFDFragmentFunc)(FILE *sfd, char *tokbuf, SplineFont *sf, void* udata); 133 extern void visitSFDFragment(FILE *sfd, SplineFont *sf, visitSFDFragmentFunc ufunc, void* udata); 134 135 #endif /* FONTFORGE_SFD_H */ 136