|
|
1.1 ! root 1: /*++ ! 2: ! 3: Copyright (c) 1993 Microsoft Corporation ! 4: ! 5: Module Name: ! 6: ! 7: fontcvt.c ! 8: ! 9: Abstract: ! 10: ! 11: Font Editor specific routines for interface to the type conversion ! 12: functions in Typecvt.c. ! 13: ! 14: ! 15: --*/ ! 16: ! 17: ! 18: #include "windows.h" ! 19: #include <windowsx.h> ! 20: #include "typecvt.h" ! 21: #include "fontedit.h" ! 22: ! 23: ! 24: extern LONG lSizeOfOldFontHeader; /* Old packed font header size. */ ! 25: extern LONG lSizeOfOldFontHeader30; /* Old 3.0 packed font header size. */ ! 26: extern LONG lSizeOfOldGlyph20; /* Old packed glyph 2.0 structure. */ ! 27: extern LONG lSizeOfOldGlyph30; /* Old packed glyph 3.0 structure. */ ! 28: ! 29: ! 30: // ! 31: // The following is a definition of the current 2.0 font header structure. ! 32: // This is the same as the old structure except that it will now be stored ! 33: // DWORD aligned in memory. ! 34: // ! 35: // First, we give it the size of the element type (as it was under Win 3.0). ! 36: // Second, we give it the actual size of the element. These will only differ ! 37: // if the element is some sort of array. ! 38: // ! 39: // Note that it is important that this array accurately reflect any changes ! 40: // in the actual structure. When CalculateStructOffsets is called it will ! 41: // return an error if the structure does not match in size, but it cannot ! 42: // detect swapped element errors. ! 43: // ! 44: ! 45: #define pfh2T ((FontHeaderType *)NULL) ! 46: ! 47: SDI rgsdiFontHeader [] = ! 48: { ! 49: { sizeof (WORD), sizeof (pfh2T->Version) }, ! 50: { sizeof (DWORD), sizeof (pfh2T->Size) }, ! 51: { sizeof (CHAR), sizeof (pfh2T->Copyright) }, ! 52: { sizeof (WORD), sizeof (pfh2T->Type) }, ! 53: { sizeof (WORD), sizeof (pfh2T->Points) }, ! 54: { sizeof (WORD), sizeof (pfh2T->VertRes) }, ! 55: { sizeof (WORD), sizeof (pfh2T->HorizRes) }, ! 56: { sizeof (WORD), sizeof (pfh2T->Ascent) }, ! 57: { sizeof (WORD), sizeof (pfh2T->IntLeading) }, ! 58: { sizeof (WORD), sizeof (pfh2T->ExtLeading) }, ! 59: { sizeof (BYTE), sizeof (pfh2T->Italic) }, ! 60: { sizeof (BYTE), sizeof (pfh2T->Underline) }, ! 61: { sizeof (BYTE), sizeof (pfh2T->StrikeOut) }, ! 62: { sizeof (WORD), sizeof (pfh2T->Weight) }, ! 63: { sizeof (BYTE), sizeof (pfh2T->CharSet) }, ! 64: { sizeof (WORD), sizeof (pfh2T->PixWidth) }, ! 65: { sizeof (WORD), sizeof (pfh2T->PixHeight) }, ! 66: { sizeof (BYTE), sizeof (pfh2T->Family) }, ! 67: { sizeof (WORD), sizeof (pfh2T->AvgWidth) }, ! 68: { sizeof (WORD), sizeof (pfh2T->MaxWidth) }, ! 69: { sizeof (BYTE), sizeof (pfh2T->FirstChar) }, ! 70: { sizeof (BYTE), sizeof (pfh2T->LastChar) }, ! 71: { sizeof (BYTE), sizeof (pfh2T->DefaultChar) }, ! 72: { sizeof (BYTE), sizeof (pfh2T->BreakChar) }, ! 73: { sizeof (WORD), sizeof (pfh2T->WidthBytes) }, ! 74: { sizeof (DWORD), sizeof (pfh2T->Device) }, ! 75: { sizeof (DWORD), sizeof (pfh2T->Face) }, ! 76: { sizeof (DWORD), sizeof (pfh2T->BitsPointer) }, ! 77: { sizeof (DWORD), sizeof (pfh2T->BitsOffset) }, ! 78: { 0, 0 } ! 79: }; ! 80: ! 81: // ! 82: // The following is the current font 3.0 header. This structure has not ! 83: // changed at all. Note that it will contain filler between elements to ! 84: // maintain DWORD alignment. ! 85: // ! 86: ! 87: #define pfh3T ((FontHeader30 *)NULL) ! 88: ! 89: SDI rgsdiFontHeader30 [] = ! 90: { ! 91: { sizeof (WORD), sizeof (pfh3T->fsVersion) }, ! 92: { sizeof (DWORD), sizeof (pfh3T->fsSize) }, ! 93: { sizeof (CHAR), sizeof (pfh3T->fsCopyright) }, ! 94: { sizeof (WORD), sizeof (pfh3T->fsType) }, ! 95: { sizeof (WORD), sizeof (pfh3T->fsPoints) }, ! 96: { sizeof (WORD), sizeof (pfh3T->fsVertRes) }, ! 97: { sizeof (WORD), sizeof (pfh3T->fsHorizRes) }, ! 98: { sizeof (WORD), sizeof (pfh3T->fsAscent) }, ! 99: { sizeof (WORD), sizeof (pfh3T->fsInternalLeading) }, ! 100: { sizeof (WORD), sizeof (pfh3T->fsExternalLeading) }, ! 101: { sizeof (BYTE), sizeof (pfh3T->fsItalic) }, ! 102: { sizeof (BYTE), sizeof (pfh3T->fsUnderline) }, ! 103: { sizeof (BYTE), sizeof (pfh3T->fsStrikeOut) }, ! 104: { sizeof (WORD), sizeof (pfh3T->fsWeight) }, ! 105: { sizeof (BYTE), sizeof (pfh3T->fsCharSet) }, ! 106: { sizeof (WORD), sizeof (pfh3T->fsPixWidth) }, ! 107: { sizeof (WORD), sizeof (pfh3T->fsPixHeight) }, ! 108: { sizeof (BYTE), sizeof (pfh3T->fsPitchAndFamily) }, ! 109: { sizeof (WORD), sizeof (pfh3T->fsAvgWidth) }, ! 110: { sizeof (WORD), sizeof (pfh3T->fsMaxWidth) }, ! 111: { sizeof (BYTE), sizeof (pfh3T->fsFirstChar) }, ! 112: { sizeof (BYTE), sizeof (pfh3T->fsLastChar) }, ! 113: { sizeof (BYTE), sizeof (pfh3T->fsDefaultChar) }, ! 114: { sizeof (BYTE), sizeof (pfh3T->fsBreakChar) }, ! 115: { sizeof (WORD), sizeof (pfh3T->fsWidthBytes) }, ! 116: { sizeof (DWORD), sizeof (pfh3T->fsDevice) }, ! 117: { sizeof (DWORD), sizeof (pfh3T->fsFace) }, ! 118: { sizeof (DWORD), sizeof (pfh3T->fsBitsPointer) }, ! 119: { sizeof (DWORD), sizeof (pfh3T->fsBitsOffset) }, ! 120: { sizeof (CHAR), sizeof (pfh3T->fsDBfiller) }, ! 121: { sizeof (DWORD), sizeof (pfh3T->fsFlags) }, ! 122: { sizeof (WORD), sizeof (pfh3T->fsAspace) }, ! 123: { sizeof (WORD), sizeof (pfh3T->fsBspace) }, ! 124: { sizeof (WORD), sizeof (pfh3T->fsCspace) }, ! 125: { sizeof (DWORD), sizeof (pfh3T->fsColorPointer) }, ! 126: { sizeof (DWORD), sizeof (pfh3T->fsReserved) }, ! 127: { sizeof (CHAR), sizeof (pfh3T->fsCharOffset) }, ! 128: { 0, 0 } ! 129: }; ! 130: ! 131: // ! 132: // The following definition is for the GlyphInfo20 structure. These ! 133: // structures are read off of disk and then converted into memory. ! 134: // ! 135: ! 136: #define pgi2T ((GLYPHINFO_20 *)NULL) ! 137: ! 138: SDI rgsdiGlyph20 [] = ! 139: { ! 140: { sizeof (SHORT), sizeof (pgi2T->GIwidth) }, ! 141: { sizeof (SHORT), sizeof (pgi2T->GIoffset) }, ! 142: { 0, 0 } ! 143: }; ! 144: ! 145: // ! 146: // The following definition is for the GlyphInfo30 structure. These ! 147: // structures are read off of disk and then converted into memory. ! 148: // ! 149: ! 150: #define pgi3T ((GLYPHINFO_30 *)NULL) ! 151: ! 152: SDI rgsdiGlyph30 [] = ! 153: { ! 154: { sizeof (SHORT), sizeof (pgi3T->GIwidth) }, ! 155: { sizeof (LONG), sizeof (pgi3T->GIoffset) }, ! 156: { 0, 0 } ! 157: }; ! 158: ! 159: ! 160: ! 161: BOOL ! 162: fConvStructInit () ! 163: ! 164: /*++ ! 165: ! 166: Routine Description: ! 167: ! 168: This function performs all the necessary initialization on the font ! 169: editor's structure definition info strucrures (SDI) and type conversion ! 170: structures (TCI). This routine should be called before either ! 171: FontStructFromBuffer or BufferFromFontStruct are called. ! 172: It is also important that this function be called before the global ! 173: variable ulOldFontHeaderSize is accessed. ! 174: ! 175: Arguments: ! 176: ! 177: None. The function accesses the global definition structures and sets ! 178: the variable ulOldFontHeaderSize to the size of the packed font header ! 179: structure. ! 180: ! 181: Return Value: ! 182: ! 183: BOOL - TRUE = the function successfully initialized all internal ! 184: strucutres. ! 185: FALSE = there was an error in one of the structure definitions. ! 186: This is usually caused by element changes which are not reflected ! 187: in the structure definition. The program should perform an ! 188: assertion failure if this is the case. ! 189: Also, the global variable ulOldFontHeaderSize is set to the size of the ! 190: packed font header structure. ! 191: ! 192: --*/ ! 193: ! 194: { ! 195: // ! 196: // Calculate all of the element offsets for the old font header structure. ! 197: // The function will return the size of the structure in packed format. ! 198: // ! 199: lSizeOfOldFontHeader = lCalculateStructOffsets ( ! 200: rgsdiFontHeader, // Give it the struct definition. ! 201: CVT_ALIGN_PACKED, // Alignment type is packed on disk. ! 202: sizeof (FontHeaderType) ! 203: ); ! 204: ! 205: // ! 206: // If CalculateStructOffsets returns -1 then there was a problem with ! 207: // structure definition. The only types of error it can find is if the ! 208: // structure size it is passed does not match the one it calculates. ! 209: // ! 210: if (lSizeOfOldFontHeader == -1) { ! 211: return (FALSE); ! 212: } ! 213: ! 214: // ! 215: // Calculate The size of the old font 3.0 structure. ! 216: // The function will return the size of the structure in packed format. ! 217: // ! 218: ! 219: lSizeOfOldFontHeader30 = lCalculateStructOffsets ( ! 220: rgsdiFontHeader30, // Give it the new font header struct. ! 221: CVT_ALIGN_PACKED, // Alignment type is packed on disk. ! 222: sizeof (FontHeader30) ! 223: ); ! 224: ! 225: // ! 226: // Check if the routine detected and error in the structure definition. ! 227: // ! 228: if (lSizeOfOldFontHeader30 == -1) { ! 229: return (FALSE); ! 230: } ! 231: ! 232: // ! 233: // Now do the same operations on the glyph information structures. ! 234: // ! 235: ! 236: lSizeOfOldGlyph20 = lCalculateStructOffsets ( ! 237: rgsdiGlyph20, ! 238: CVT_ALIGN_PACKED, ! 239: sizeof (GLYPHINFO_20) ! 240: ); ! 241: ! 242: if (lSizeOfOldGlyph20 == -1) { ! 243: return (FALSE); ! 244: } ! 245: ! 246: lSizeOfOldGlyph30 = lCalculateStructOffsets ( ! 247: rgsdiGlyph30, ! 248: CVT_ALIGN_PACKED, ! 249: sizeof (GLYPHINFO_30) ! 250: ); ! 251: ! 252: if (lSizeOfOldGlyph30 == -1) { ! 253: return (FALSE); ! 254: } ! 255: ! 256: return (TRUE); // No error found. ! 257: } ! 258: ! 259: ! 260: VOID ! 261: vFontStructFromBuffer ( ! 262: PBYTE pjSourceBuff, ! 263: FontHeaderType *pfhDestFHStruct ! 264: ) ! 265: ! 266: /*++ ! 267: ! 268: Routine Description: ! 269: ! 270: This function provides an interface to the font editor for the strutcture ! 271: type conversion routines. ! 272: It essentially just calls the typecvt routines but hides the details from ! 273: the font editor. ! 274: ! 275: Arguments: ! 276: ! 277: pjSourceBuff - This is a pointer to the source buffer with the old ! 278: packed font header information. This buffer is from a ! 279: memory mapped disk file. ! 280: ! 281: pfhDestFHStruct - This is a pointer to the destination FontHeaderType ! 282: structure. This structure is of the new DWORD aligned ! 283: type. ! 284: ! 285: Return Value: ! 286: ! 287: None. ! 288: ! 289: --*/ ! 290: ! 291: { ! 292: vPerformConversion ( ! 293: rgsdiFontHeader, // Give it the structure description. ! 294: pjSourceBuff, // Give it our source file buffer. ! 295: CVT_ALIGN_PACKED, // File is packed alignment. ! 296: CVT_FILE_ENDIAN_DEFAULT, // Use file endian type (little). ! 297: (PBYTE)pfhDestFHStruct, // Give it our destination buffer. ! 298: CVT_ALIGN_SYSTEM, // Use the current system aligment. ! 299: CVT_ENDIAN_SYSTEM // Use the current system endian. ! 300: ); ! 301: } ! 302: ! 303: ! 304: VOID ! 305: vBufferFromFontStruct ( ! 306: FontHeaderType *pfhSrcFHStruct, ! 307: PBYTE pjDestBuff ! 308: ) ! 309: ! 310: /*++ ! 311: ! 312: Routine Description: ! 313: ! 314: This function provides an interface to the font editor for the strutcture ! 315: type conversion routines. ! 316: It converts a source structure of type FontHeaderType to a destination ! 317: buffer which can then be written out to disk. ! 318: It essentially just calls the typecvt routines but hides the details from ! 319: the font editor. ! 320: ! 321: Arguments: ! 322: ! 323: pfhSrcFHStruct - This is a pointer to the source FontHeaderType structure. ! 324: This structure is of the new DWORD aligned type. ! 325: ! 326: pjDestBuff - This is a pointer to the destination buffer which will ! 327: hold the old packed font header structure. ! 328: This buffer is from a memory mapped disk file. ! 329: ! 330: Return Value: ! 331: ! 332: None. ! 333: ! 334: --*/ ! 335: ! 336: { ! 337: vPerformConversion ( ! 338: rgsdiFontHeader, // Give it the structure description. ! 339: (PBYTE)pfhSrcFHStruct, // Give it our destination buffer. ! 340: CVT_ALIGN_SYSTEM, // Use the current system aligment. ! 341: CVT_ENDIAN_SYSTEM, // Use the current system endian. ! 342: pjDestBuff, // Give it our source file buffer. ! 343: CVT_ALIGN_PACKED, // File is packed alignment. ! 344: CVT_FILE_ENDIAN_DEFAULT // Use file endian type (little). ! 345: ); ! 346: } ! 347: ! 348: ! 349: VOID ! 350: vBufferFromFont30Struct ( ! 351: FontHeader30 *pfh3SrcFH3Struct, ! 352: PBYTE pjDestBuff ! 353: ) ! 354: ! 355: /*++ ! 356: ! 357: Routine Description: ! 358: ! 359: This function provides an interface to the font editor for the strutcture ! 360: type conversion routines. ! 361: It converts a source structure of type FontHeader30 to a destination ! 362: buffer which can then be written out to disk. ! 363: It essentially just calls the typecvt routines but hides the details from ! 364: the font editor. ! 365: ! 366: Arguments: ! 367: ! 368: pfh3SrcFH3Struct- This is a pointer to the source FontHeader30 structure. ! 369: This structure is of the new DWORD aligned type. ! 370: ! 371: pjDestBuff - This is a pointer to the destination buffer which will ! 372: hold the old packed font header structure. ! 373: This buffer is from a memory mapped disk file. ! 374: ! 375: Return Value: ! 376: ! 377: None. ! 378: ! 379: --*/ ! 380: ! 381: { ! 382: vPerformConversion ( ! 383: rgsdiFontHeader30, // Give it the structure description. ! 384: (PBYTE)pfh3SrcFH3Struct, // Give it our destination buffer. ! 385: CVT_ALIGN_SYSTEM, // Use the current system aligment. ! 386: CVT_ENDIAN_SYSTEM, // Use the current system endian. ! 387: pjDestBuff, // Give it our source file buffer. ! 388: CVT_ALIGN_PACKED, // File is packed alignment. ! 389: CVT_FILE_ENDIAN_DEFAULT // Use file endian type (little). ! 390: ); ! 391: } ! 392: ! 393: ! 394: VOID ! 395: vGlyphInfo20FromBuffer ( ! 396: PBYTE pjSourceBuff, ! 397: GLYPHINFO_20 *pgi2DestGI2Struct ! 398: ) ! 399: ! 400: /*++ ! 401: ! 402: Routine Description: ! 403: ! 404: This function provides an interface to the font editor for the strutcture ! 405: type conversion routines. ! 406: It essentially just calls the typecvt routines but hides the details from ! 407: the font editor. ! 408: ! 409: Arguments: ! 410: ! 411: pjSourceBuff - This is a pointer to the source buffer with the old ! 412: packed font header information. This buffer is from a ! 413: memory mapped disk file. ! 414: ! 415: pgi2DestGI2Struct - This is a pointer to the destination GLYPHINFO_20 ! 416: structure. This structure is of the new DWORD aligned ! 417: type. ! 418: ! 419: Return Value: ! 420: ! 421: None. ! 422: ! 423: --*/ ! 424: ! 425: { ! 426: vPerformConversion ( ! 427: rgsdiGlyph20, // Give it the structure description. ! 428: pjSourceBuff, // Give it our source file buffer. ! 429: CVT_ALIGN_PACKED, // File is packed alignment. ! 430: CVT_FILE_ENDIAN_DEFAULT, // Use file endian type (little). ! 431: (PBYTE)pgi2DestGI2Struct, // Give it our destination buffer. ! 432: CVT_ALIGN_SYSTEM, // Use the current system aligment. ! 433: CVT_ENDIAN_SYSTEM // Use the current system endian. ! 434: ); ! 435: } ! 436: ! 437: ! 438: VOID ! 439: vGlyphInfo30FromBuffer ( ! 440: PBYTE pjSourceBuff, ! 441: GLYPHINFO_30 *pgi3DestGI3Struct ! 442: ) ! 443: ! 444: /*++ ! 445: ! 446: Routine Description: ! 447: ! 448: This function provides an interface to the font editor for the strutcture ! 449: type conversion routines. ! 450: It essentially just calls the typecvt routines but hides the details from ! 451: the font editor. ! 452: ! 453: Arguments: ! 454: ! 455: pjSourceBuff - This is a pointer to the source buffer with the old ! 456: packed font header information. This buffer is from a ! 457: memory mapped disk file. ! 458: ! 459: pgi3DestGI3Struct - This is a pointer to the destination GLYPHINFO_30 ! 460: structure. This structure is of the new DWORD aligned ! 461: type. ! 462: ! 463: Return Value: ! 464: ! 465: None. ! 466: ! 467: --*/ ! 468: ! 469: { ! 470: vPerformConversion ( ! 471: rgsdiGlyph30, // Give it the structure description. ! 472: pjSourceBuff, // Give it our source file buffer. ! 473: CVT_ALIGN_PACKED, // File is packed alignment. ! 474: CVT_FILE_ENDIAN_DEFAULT, // Use file endian type (little). ! 475: (PBYTE)pgi3DestGI3Struct, // Give it our destination buffer. ! 476: CVT_ALIGN_SYSTEM, // Use the current system aligment. ! 477: CVT_ENDIAN_SYSTEM // Use the current system endian. ! 478: ); ! 479: } ! 480: ! 481: ! 482: VOID ! 483: vBufferFromGlyphInfo20 ( ! 484: GLYPHINFO_20 *pgi2SrcGI2Struct, ! 485: PBYTE pjDestBuff ! 486: ) ! 487: ! 488: /*++ ! 489: ! 490: Routine Description: ! 491: ! 492: This function provides an interface to the font editor for the strutcture ! 493: type conversion routines. ! 494: It converts a source structure of type GLYPHINFO_20 to a destination ! 495: buffer which can then be written out to disk. ! 496: It essentially just calls the typecvt routines but hides the details from ! 497: the font editor. ! 498: ! 499: Arguments: ! 500: ! 501: pgi2SrcGI2Struct- This is a pointer to the source GLYPHINFO_20 structure. ! 502: This structure is of the new DWORD aligned type. ! 503: ! 504: pjDestBuff - This is a pointer to the destination buffer which will ! 505: hold the old packed font header structure. ! 506: This buffer is from a memory mapped disk file. ! 507: ! 508: Return Value: ! 509: ! 510: None. ! 511: ! 512: --*/ ! 513: ! 514: { ! 515: vPerformConversion ( ! 516: rgsdiGlyph20, // Give it the structure description. ! 517: (PBYTE)pgi2SrcGI2Struct, // Give it our destination buffer. ! 518: CVT_ALIGN_SYSTEM, // Use the current system aligment. ! 519: CVT_ENDIAN_SYSTEM, // Use the current system endian. ! 520: pjDestBuff, // Give it our source file buffer. ! 521: CVT_ALIGN_PACKED, // File is packed alignment. ! 522: CVT_FILE_ENDIAN_DEFAULT // Use file endian type (little). ! 523: ); ! 524: } ! 525: ! 526: ! 527: VOID ! 528: vBufferFromGlyphInfo30 ( ! 529: GLYPHINFO_30 *pgi3SrcGI3Struct, ! 530: PBYTE pjDestBuff ! 531: ) ! 532: ! 533: /*++ ! 534: ! 535: Routine Description: ! 536: ! 537: This function provides an interface to the font editor for the strutcture ! 538: type conversion routines. ! 539: It converts a source structure of type GLYPHINFO_30 to a destination ! 540: buffer which can then be written out to disk. ! 541: It essentially just calls the typecvt routines but hides the details from ! 542: the font editor. ! 543: ! 544: Arguments: ! 545: ! 546: pgi3SrcGI3Struct- This is a pointer to the source GLYPHINFO_30 structure. ! 547: This structure is of the new DWORD aligned type. ! 548: ! 549: pjDestBuff - This is a pointer to the destination buffer which will ! 550: hold the old packed font header structure. ! 551: This buffer is from a memory mapped disk file. ! 552: ! 553: Return Value: ! 554: ! 555: None. ! 556: ! 557: --*/ ! 558: ! 559: { ! 560: vPerformConversion ( ! 561: rgsdiGlyph30, // Give it the structure description. ! 562: (PBYTE)pgi3SrcGI3Struct, // Give it our destination buffer. ! 563: CVT_ALIGN_SYSTEM, // Use the current system aligment. ! 564: CVT_ENDIAN_SYSTEM, // Use the current system endian. ! 565: pjDestBuff, // Give it our source file buffer. ! 566: CVT_ALIGN_PACKED, // File is packed alignment. ! 567: CVT_FILE_ENDIAN_DEFAULT // Use file endian type (little). ! 568: ); ! 569: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.