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.

216 lines
5.2 KiB

  1. /*++
  2. Copyright (c) 1996 - 1999 Microsoft Corporation
  3. Module Name:
  4. qadvwdth.c
  5. Abstract:
  6. Implements the DrvQueryAdvanceWidths function - returns information
  7. about glyph widths.
  8. Environment:
  9. Windows NT Unidrv driver
  10. Revision History:
  11. 01/02/97 -ganeshp-
  12. Created
  13. --*/
  14. #include "font.h"
  15. BOOL
  16. FMQueryAdvanceWidths(
  17. PDEV *pPDev,
  18. FONTOBJ *pfo,
  19. ULONG iMode,
  20. HGLYPH *phg,
  21. PVOID *pvWidths,
  22. ULONG cGlyphs
  23. )
  24. /*++
  25. Routine Description:
  26. Return Width information about glyphs in the font.
  27. Arguments:
  28. pPDev Pointer to PDEV
  29. pfo The font of interest
  30. iMode Glyphdata or kerning information
  31. phg handle to glyph
  32. pvWidths Output area
  33. cGlyphs The number of them
  34. Return Value:
  35. TRUE for success and FALSE if widths of all the glyphs cannot be computed.
  36. It returns DD_ERROR if the function fails.
  37. Note:
  38. 01/02/97 -ganeshp-
  39. --*/
  40. {
  41. /*
  42. * First version is for fixed pitch fonts, which are easy to do:
  43. * the data is in the font's metrics!
  44. */
  45. FONTPDEV *pFontPDev;
  46. int iRot; /* Rotation multiple of 90 degrees */
  47. BOOL bRet; /* Value returned */
  48. FONTMAP *pFM; /* Font data */
  49. IFIMETRICS *pIFI;
  50. XFORMOBJ *pxo;
  51. FONTCTL ctl; /* Scaling information */
  52. USHORT *pusWidths;
  53. FLOATOBJ fo;
  54. pFontPDev = pPDev->pFontPDev;
  55. bRet = DDI_ERROR;
  56. pusWidths = (USHORT *) pvWidths;
  57. if( pfo->iFace < 1 || (int)pfo->iFace > pPDev->iFonts )
  58. {
  59. ERR(("UniFont!FMQueryAdvanceWidths: Bad FONTOBJ, iFace is %d",pfo->iFace));
  60. SetLastError( ERROR_INVALID_PARAMETER );
  61. return bRet;
  62. }
  63. pFM = PfmGetDevicePFM( pPDev, pfo->iFace );
  64. if( pFM == NULL )
  65. return FALSE;
  66. pIFI = pFM->pIFIMet; /* IFIMETRICS - useful to have */
  67. if( !(pxo = FONTOBJ_pxoGetXform( pfo )) )
  68. {
  69. ERR(( "UniFont!FMQueryAdvanceWidths: FONTOBJ_pxoGetXform fails\n" ));
  70. return bRet;
  71. }
  72. /*
  73. * ALWAYS call the iSetScale function, because some printers can
  74. * rotate bitmap fonts.
  75. */
  76. //Added Check for HP Intellifont
  77. iRot = ISetScale( &ctl, pxo, ((pFM->flFlags & FM_SCALABLE) &&
  78. (((PFONTMAP_DEV)pFM->pSubFM)->wDevFontType ==
  79. DF_TYPE_HPINTELLIFONT)),
  80. (pFontPDev->flText & TC_CR_ANY)?TRUE:FALSE);
  81. if( pFM->flFlags & FM_SCALABLE )
  82. {
  83. int iPtSize, iAdjustedPtSize; /* For scale factor adjustment */
  84. #ifdef USEFLOATS
  85. /* The limited font size resolution */
  86. iPtSize = (int)(0.5 + ctl.eYScale * pIFI->fwdUnitsPerEm * 7200) / pPDev->ptGrxRes.y;
  87. /* if the tranform is very small (Less than a quarter of point size)
  88. * then make it atleast a quarter point. This was causing AV in certain
  89. * cases.
  90. */
  91. if (iPtSize < 25)
  92. {
  93. iPtSize = 25;
  94. }
  95. iAdjustedPtSize = ((iPtSize + 12) / 25) * 25;
  96. //Adjust the Scale Factor for quarter point adjustment.
  97. ctl.eXScale = (ctl.eXScale * iAdjustedPtSize) / iPtSize;
  98. ctl.eYScale = (ctl.eYScale * iAdjustedPtSize) / iPtSize;
  99. #else
  100. fo = ctl.eYScale;
  101. FLOATOBJ_MulLong(&fo,pIFI->fwdUnitsPerEm);
  102. FLOATOBJ_MulLong(&fo,7200);
  103. #ifndef WINNT_40 //NT 5.0
  104. FLOATOBJ_AddFloat(&fo,(FLOATL)FLOATL_00_50);
  105. #else // NT 4.0
  106. FLOATOBJ_AddFloat(&fo,(FLOAT)0.5);
  107. #endif //!WINNT_40
  108. iPtSize = FLOATOBJ_GetLong(&fo);
  109. iPtSize /= pPDev->ptGrxRes.y;
  110. /* if the trannform is very small (Less than a quarter of point size)
  111. * then make it atleast a quarter point. This was causing AV in certain
  112. * cases.
  113. */
  114. if (iPtSize < 25)
  115. {
  116. iPtSize = 25;
  117. }
  118. iAdjustedPtSize = ((iPtSize + 12) / 25) * 25;
  119. //Adjust the Scale Factor for quarter point adjustment.
  120. FLOATOBJ_MulLong(&ctl.eXScale,iAdjustedPtSize);
  121. FLOATOBJ_DivLong(&ctl.eXScale,iPtSize);
  122. FLOATOBJ_MulLong(&ctl.eYScale,iAdjustedPtSize);
  123. FLOATOBJ_DivLong(&ctl.eYScale,iPtSize);
  124. #endif
  125. }
  126. /* We need to adjust the width table entries to the current resolution.IGetGlyphWidth
  127. * returns the scaled width for current resolution.
  128. */
  129. switch( iMode )
  130. {
  131. case QAW_GETWIDTHS: /* Glyph width etc data */
  132. case QAW_GETEASYWIDTHS:
  133. while( cGlyphs-- > 0 )
  134. {
  135. int iWide; /* Glyph's width */
  136. iWide = IGetGlyphWidth( pPDev, pFM, (HGLYPH)*phg++);
  137. iWide = LMulFloatLong(&ctl.eXScale,iWide);
  138. *pusWidths++ = LTOFX( iWide );
  139. }
  140. bRet = TRUE;
  141. break;
  142. default:
  143. ERR(( "UniFont!FMQueryAdvanceWidths: illegal iMode value" ));
  144. SetLastError( ERROR_INVALID_PARAMETER );
  145. break;
  146. }
  147. return bRet;
  148. }