Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

169 lines
3.2 KiB

  1. /***
  2. **
  3. ** Module: PFB
  4. **
  5. ** Description:
  6. ** This is a module of the T1 to TT font converter. The module
  7. ** contains functions that manages the "printer binary file" file
  8. ** format (Adobe Type 1 for MS-Windows).
  9. **
  10. ** Author: Michael Jansson
  11. **
  12. ** Created: 5/26/93
  13. **
  14. ***/
  15. /**** INCLUDES */
  16. /* General types and definitions. */
  17. #include <ctype.h>
  18. /* Special types and definitions. */
  19. #include "titott.h"
  20. #include "types.h"
  21. #include "safemem.h"
  22. /* Module dependent types and prototypes. */
  23. #include "fileio.h"
  24. /***** LOCAL TYPES */
  25. struct t1file {
  26. struct ioFile *file;
  27. enum blocktype {none=0, ascii, encoded} type;
  28. long size;
  29. long curr;
  30. };
  31. /***** CONSTANTS */
  32. /*-none-*/
  33. /***** MACROS */
  34. #define HEXDIGIT(c) (((c)>='a') ? ((c) - 'a' + 10) : ((c) - '0'))
  35. #define HEX(c1,c2) (HEXDIGIT(c1)*16+HEXDIGIT(c2))
  36. /***** STATIC FUNCTIONS */
  37. /*-none-*/
  38. /***** FUNCTIONS */
  39. /***
  40. ** Function: PFBAllocIOBlock
  41. **
  42. ** Description:
  43. ** Initiate an I/O stream for a PFB font file.
  44. ***/
  45. struct t1file *PFBAllocIOBlock(const char *name)
  46. {
  47. struct t1file *pfb;
  48. if ((pfb=Malloc(sizeof(struct t1file)))!=NULL) {
  49. if ((pfb->file = io_OpenFile(name, READONLY))==NULL) {
  50. Free(pfb);
  51. pfb = NULL;
  52. } else {
  53. pfb->type = none;
  54. pfb->size = 0;
  55. pfb->curr = 0;
  56. }
  57. }
  58. return pfb;
  59. }
  60. /***
  61. ** Function: PFBFreeIOBlock
  62. **
  63. ** Description:
  64. ** Free an I/O stream for a PFB font file.
  65. ***/
  66. errcode FASTCALL PFBFreeIOBlock(struct t1file *pfb)
  67. {
  68. errcode status = SUCCESS;
  69. status = io_CloseFile(pfb->file);
  70. Free(pfb);
  71. return status;
  72. }
  73. /***
  74. ** Function: PFBFileError
  75. **
  76. ** Description:
  77. ** Check if an I/O stream is ok.
  78. ***/
  79. boolean FASTCALL PFBFileError(const struct t1file *pfb)
  80. {
  81. return io_FileError(pfb->file);
  82. }
  83. /***
  84. ** Function: PFBGetByte
  85. **
  86. ** Description:
  87. ** Pull one byte from the opened PFB font file.
  88. ** Please note that this function does not check
  89. ** if it succeedes it reading a byte or not. It is
  90. ** up to the calling module to manage the error
  91. ** checkes by using the FileError() function when
  92. ** appropriate.
  93. **
  94. ***/
  95. short FASTCALL PFBGetByte(struct t1file *pfb)
  96. {
  97. short b, c1, c2;
  98. /* Enter a new PFB block? */
  99. if (pfb->curr>=pfb->size) {
  100. UBYTE type[2];
  101. UBYTE size[4];
  102. type[0]=(UBYTE)io_ReadOneByte(pfb->file);
  103. type[1]=(UBYTE)io_ReadOneByte(pfb->file);
  104. size[0]=(UBYTE)io_ReadOneByte(pfb->file);
  105. size[1]=(UBYTE)io_ReadOneByte(pfb->file);
  106. size[2]=(UBYTE)io_ReadOneByte(pfb->file);
  107. size[3]=(UBYTE)io_ReadOneByte(pfb->file);
  108. pfb->curr = 0;
  109. pfb->size = (long)MkLong(size[3], size[2], size[1], size[0]);
  110. pfb->type = ((type[0]==0x80 && (type[1]==0x01 ||
  111. type[1]==0x02)) ? ascii : encoded);
  112. }
  113. /* Read a byte. */
  114. switch (pfb->type) {
  115. case ascii:
  116. b = (short)io_ReadOneByte(pfb->file);
  117. pfb->curr++;
  118. break;
  119. case encoded:
  120. c1 = (short)tolower(io_ReadOneByte(pfb->file));
  121. c2 = (short)tolower(io_ReadOneByte(pfb->file));
  122. b = (short)HEX(c1, c2);
  123. pfb->curr += 2;
  124. break;
  125. case none:
  126. default:
  127. b = (short)-1;
  128. break;
  129. }
  130. return b;
  131. }