Leaked source code of windows server 2003
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.

174 lines
4.8 KiB

  1. /******************************* MODULE HEADER *******************************
  2. * writefnt.c
  3. * Function to take a FI_DATA_HEADER structure and write the data to
  4. * the passed in file handle as a font record. This layout is used
  5. * in both minidrivers and the font installer font file.
  6. *
  7. * Copyright (C) 1992 Microsoft Corporation.
  8. *
  9. *****************************************************************************/
  10. #include "StdAfx.H"
  11. #include "fontinst.h"
  12. /************************* Function Header *********************************
  13. * bWrite
  14. * Writes data out to a file handle. Returns TRUE on success.
  15. * Functions as a nop if the size request is zero.
  16. *
  17. * RETURNS:
  18. * TRUE/FALSE, TRUE for success.
  19. *
  20. * HISTORY:
  21. * 17:38 on Fri 21 Feb 1992 -by- Lindsay Harris [lindsayh]
  22. * # 1
  23. *
  24. ****************************************************************************/
  25. static BOOL bWrite(HANDLE hFile, PVOID pvBuf, int iSize ) {
  26. /*
  27. * Simplify the ugly NT interface. Returns TRUE if the WriteFile
  28. * call returns TRUE and the number of bytes written equals the
  29. * number of bytes desired.
  30. */
  31. BOOL bRet;
  32. DWORD dwSize; /* Filled in by WriteFile */
  33. bRet = TRUE;
  34. if( iSize > 0 &&
  35. (!WriteFile( hFile, pvBuf, (DWORD)iSize, &dwSize, NULL ) ||
  36. (DWORD)iSize != dwSize) )
  37. bRet = FALSE; /* Too bad */
  38. return bRet;
  39. }
  40. /******************************* Function Header *****************************
  41. * iWriteFDH
  42. * Write the FI_DATA_HEADER data out to our file. We do the conversion
  43. * from addresses to offsets, and write out any data we find.
  44. *
  45. * RETURNS:
  46. * The number of bytes actually written; -1 for error, 0 for nothing.
  47. *
  48. * HISTORY:
  49. * 16:58 on Thu 05 Mar 1992 -by- Lindsay Harris [lindsayh]
  50. * Based on an experimental version first used in font installer.
  51. *
  52. * 17:11 on Fri 21 Feb 1992 -by- Lindsay Harris [lindsayh]
  53. * First version.
  54. *
  55. *****************************************************************************/
  56. int iWriteFDH(HANDLE hFile, FI_DATA *pFD) {
  57. /*
  58. * Decide how many bytes will be written out. We presume that the
  59. * file pointer is located at the correct position when we are called.
  60. */
  61. int iSize; /* Evaluate output size */
  62. FI_DATA_HEADER fdh; /* Header written to file */
  63. if (!pFD)
  64. return 0; /* Perhaps only deleting? */
  65. memset( &fdh, 0, sizeof( fdh ) ); /* Zero for convenience */
  66. /*
  67. * Set the miscellaneous flags etc.
  68. */
  69. fdh.cjThis = sizeof( fdh );
  70. fdh.fCaps = pFD->fCaps;
  71. fdh.wFontType= pFD->wFontType; /* Device Font Type */
  72. fdh.wXRes = pFD->wXRes;
  73. fdh.wYRes = pFD->wYRes;
  74. fdh.sYAdjust = pFD->sYAdjust;
  75. fdh.sYMoved = pFD->sYMoved;
  76. fdh.u.sCTTid = (short)pFD->dsCTT.cBytes;
  77. fdh.dwSelBits = pFD->dwSelBits;
  78. fdh.wPrivateData = pFD->wPrivateData;
  79. iSize = sizeof( fdh ); /* Our header already */
  80. fdh.dwIFIMet = iSize; /* Location of IFIMETRICS */
  81. iSize += pFD->dsIFIMet.cBytes; /* Bytes in struct */
  82. /*
  83. * And there may be a width table too! The pFD values are zero if none.
  84. */
  85. if( pFD->dsWidthTab.cBytes )
  86. {
  87. fdh.dwWidthTab = iSize;
  88. iSize += pFD->dsWidthTab.cBytes;
  89. }
  90. /*
  91. * Finally are the select/deselect strings.
  92. */
  93. if( pFD->dsSel.cBytes )
  94. {
  95. fdh.dwCDSelect = iSize;
  96. iSize += pFD->dsSel.cBytes;
  97. }
  98. if( pFD->dsDesel.cBytes )
  99. {
  100. fdh.dwCDDeselect = iSize;
  101. iSize += pFD->dsDesel.cBytes;
  102. }
  103. /*
  104. * There may also be some sort of identification string.
  105. */
  106. if( pFD->dsIdentStr.cBytes )
  107. {
  108. fdh.dwIdentStr = iSize;
  109. iSize += pFD->dsIdentStr.cBytes;
  110. }
  111. if( pFD->dsETM.cBytes )
  112. {
  113. fdh.dwETM = iSize;
  114. iSize += pFD->dsETM.cBytes;
  115. }
  116. /*
  117. * Sizes all figured out, so write the data!
  118. */
  119. if( !bWrite( hFile, &fdh, sizeof( fdh ) ) ||
  120. !bWrite( hFile, pFD->dsIFIMet.pvData, pFD->dsIFIMet.cBytes ) ||
  121. !bWrite( hFile, pFD->dsWidthTab.pvData, pFD->dsWidthTab.cBytes ) ||
  122. !bWrite( hFile, pFD->dsSel.pvData, pFD->dsSel.cBytes ) ||
  123. !bWrite( hFile, pFD->dsDesel.pvData, pFD->dsDesel.cBytes ) ||
  124. !bWrite( hFile, pFD->dsIdentStr.pvData, pFD->dsIdentStr.cBytes ) ||
  125. !bWrite( hFile, pFD->dsETM.pvData, pFD->dsETM.cBytes ) )
  126. return -1;
  127. return iSize; /* Number of bytes written */
  128. }