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.

340 lines
8.8 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: fontgdip.cxx
  3. *
  4. * Private font API entry points.
  5. *
  6. * Created: 26-Jun-1991 10:04:34
  7. * Author: Gilman Wong [gilmanw]
  8. *
  9. * Copyright (c) 1990-1999 Microsoft Corporation
  10. *
  11. \**************************************************************************/
  12. #include "precomp.hxx"
  13. LONG lNormAngle(LONG lAngle);
  14. /******************************Public*Routine******************************\
  15. *
  16. * VOID vSetLOCALFONT(HLFONT hlf, PVOID pvCliData)
  17. *
  18. * Effects:
  19. * set the pointer to the memory shared between client and
  20. * kernel
  21. *
  22. * History:
  23. * 18-Mar-1996 -by- Bodin Dresevic [BodinD]
  24. * Wrote it.
  25. \**************************************************************************/
  26. VOID vSetLOCALFONT(HLFONT hlf, PVOID pvCliData)
  27. {
  28. PENTRY pentry;
  29. UINT uiIndex = (UINT) HmgIfromH(hlf);
  30. pentry = &gpentHmgr[uiIndex];
  31. ASSERTGDI(uiIndex < gcMaxHmgr,"hfontcreate pentry > gcMaxHmgr");
  32. pentry->pUser = pvCliData;
  33. }
  34. /******************************Public*Routine******************************\
  35. * GreSelectFont
  36. *
  37. * Server-side entry point for selecting a font into a DC.
  38. *
  39. * History:
  40. *
  41. * Mon 18-Mar-1996 -by- Bodin Dresevic [BodinD]
  42. * update: added ref counting in the kernel
  43. *
  44. * 22-Oct-1993 -by- Patrick Haluptzok patrickh
  45. * Wrote it.
  46. \**************************************************************************/
  47. HFONT GreSelectFont(HDC hdc, HFONT hlfntNew)
  48. {
  49. HLFONT hlfntOld = (HLFONT) 0;
  50. XDCOBJ dco(hdc);
  51. PLFONT plfnt;
  52. if (dco.bValid())
  53. {
  54. // Let us make sure it is ok to select this new font to a DC,
  55. // that is make sure that it is not marked deletable
  56. hlfntOld = (HLFONT)dco.pdc->plfntNew()->hGet();
  57. if ((HLFONT)hlfntNew != hlfntOld)
  58. {
  59. // Lock down the new logfont handle so as to get the pointer out
  60. // This also increments the reference count of the new font
  61. plfnt = (PLFONT)HmgShareCheckLock((HOBJ)hlfntNew, LFONT_TYPE);
  62. // What if this did not work?
  63. if (plfnt)
  64. {
  65. // if marked for deletion, refuse to select it in
  66. if (!(PENTRY_FROM_POBJ(plfnt)->Flags & HMGR_ENTRY_LAZY_DEL))
  67. {
  68. // undo the lock from when the brush was selected
  69. DEC_SHARE_REF_CNT_LAZY_DEL_LOGFONT(dco.pdc->plfntNew());
  70. // set the new lfont:
  71. dco.pdc->plfntNew(plfnt);
  72. dco.pdc->hlfntNew((HLFONT)hlfntNew);
  73. dco.ulDirtyAdd(DIRTY_CHARSET);
  74. // same as CLEAR_CACHED_TEXT(pdcattr);
  75. dco.ulDirtySub(SLOW_WIDTHS);
  76. }
  77. else
  78. {
  79. DEC_SHARE_REF_CNT_LAZY_DEL_LOGFONT(plfnt);
  80. hlfntOld = 0;
  81. }
  82. }
  83. else
  84. {
  85. hlfntOld = 0;
  86. }
  87. }
  88. dco.vUnlockFast();
  89. }
  90. #if DBG
  91. else
  92. {
  93. WARNING1("GreSelectFont passed invalid DC\n");
  94. }
  95. #endif
  96. // return old HLFONT
  97. return((HFONT)hlfntOld);
  98. }
  99. /******************************Public*Routine******************************\
  100. * hfontCreate
  101. *
  102. * Creates the file with an LOGFONTW and a type.
  103. *
  104. * History:
  105. * Sun 13-Jun-1993 -by- Patrick Haluptzok [patrickh]
  106. * Wrote it.
  107. \**************************************************************************/
  108. HFONT hfontCreate(ENUMLOGFONTEXDVW * pelfw, LFTYPE lft, FLONG fl, PVOID pvCliData)
  109. {
  110. HFONT hfReturn;
  111. TRACE_FONT(("hfontCreate: ENTERING, font name %ws\n", pelfw->elfEnumLogfontEx.elfLogFont.lfFaceName));
  112. if (pelfw &&
  113. pelfw->elfDesignVector.dvNumAxes <= MM_MAX_NUMAXES)
  114. {
  115. // We must Allocate - init object - add to hmgr table.
  116. // Otherwise possible crash if bad app uses newly created handle
  117. // before init finishes.
  118. ULONG cjElfw = offsetof(ENUMLOGFONTEXDVW,elfDesignVector) +
  119. SIZEOFDV(pelfw->elfDesignVector.dvNumAxes) ;
  120. PLFONT plfnt = (PLFONT) ALLOCOBJ(offsetof(LFONT,elfw)+cjElfw,LFONT_TYPE,FALSE);
  121. if (plfnt != NULL)
  122. {
  123. plfnt->lft = lft;
  124. plfnt->fl = fl;
  125. plfnt->cjElfw_ = cjElfw;
  126. RtlCopyMemory(&plfnt->elfw, pelfw, cjElfw);
  127. plfnt->cMapsInCache = 0;
  128. // Add the upper case version of the facename to the LFONT.
  129. cCapString
  130. (
  131. plfnt->wcCapFacename,
  132. pelfw->elfEnumLogfontEx.elfLogFont.lfFaceName,
  133. LF_FACESIZE
  134. );
  135. // Normalize the orientation angle. This saves the mapper from doing it.
  136. pelfw->elfEnumLogfontEx.elfLogFont.lfOrientation
  137. = lNormAngle(pelfw->elfEnumLogfontEx.elfLogFont.lfOrientation);
  138. hfReturn = (HFONT) HmgInsertObject((HOBJ)plfnt,0,LFONT_TYPE);
  139. if (hfReturn != (HFONT) 0)
  140. {
  141. vSetLOCALFONT((HLFONT)hfReturn, pvCliData);
  142. TRACE_FONT(("hfontCreate: SUCCESS\n"));
  143. return(hfReturn);
  144. }
  145. WARNING("hfontCreate failed HmgInsertObject\n");
  146. FREEOBJ(plfnt, LFONT_TYPE);
  147. }
  148. }
  149. else
  150. {
  151. WARNING("hfontCreate invalid parameter\n");
  152. }
  153. TRACE_FONT(("hfontCreate: FAILIURE\n"));
  154. return((HFONT) 0);
  155. }
  156. /******************************Public*Routine******************************\
  157. * BOOL bDeleteFont
  158. *
  159. * Destroys the LFONT object identified by the handle, hlfnt.
  160. *
  161. * History:
  162. * Thu 10-Jun-1993 -by- Patrick Haluptzok [patrickh]
  163. * Change deletion to check for other locks.
  164. *
  165. * 26-Feb-1991 -by- Gilman Wong [gilmanw]
  166. * Wrote it.
  167. \**************************************************************************/
  168. BOOL bDeleteFont(HLFONT hlfnt, BOOL bForceDelete)
  169. {
  170. BOOL bRet = TRUE;
  171. PLFONT plfnt;
  172. BOOL bDelete = TRUE;
  173. TRACE_FONT(("Entering bDeleteFont\n"
  174. " hlfnt = %x, bForceDelete = %d\n", hlfnt, bForceDelete));
  175. HANDLELOCK LfontLock;
  176. //
  177. // Old comment from bodind:
  178. // Isn't this operation incresing share ref count?
  179. //
  180. // This should be investigated.
  181. //
  182. LfontLock.bLockHobj((HOBJ)hlfnt, LFONT_TYPE);
  183. if (LfontLock.bValid())
  184. {
  185. POBJ pObj = LfontLock.pObj();
  186. ASSERTGDI(pObj->cExclusiveLock == 0,
  187. "deletefont - cExclusiveLock != 0\n");
  188. // if brush still in use mark for lazy deletion and return true
  189. if (LfontLock.ShareCount() > 0)
  190. {
  191. LfontLock.pentry()->Flags |= HMGR_ENTRY_LAZY_DEL;
  192. bDelete = FALSE;
  193. }
  194. // We always force delete of LOCALFONT client side structure
  195. // in the client side, therefore we can set the pointer to this
  196. // structure to zero
  197. LfontLock.pentry()->pUser = NULL;
  198. // Done
  199. LfontLock.vUnlock();
  200. }
  201. else
  202. {
  203. bRet = FALSE;
  204. bDelete = FALSE;
  205. }
  206. if (bDelete)
  207. {
  208. if ((plfnt = (LFONT *) HmgRemoveObject((HOBJ)hlfnt, 0, 0, bForceDelete, LFONT_TYPE)) != NULL)
  209. {
  210. FREEOBJ(plfnt, LFONT_TYPE);
  211. bRet = TRUE;
  212. }
  213. else
  214. {
  215. WARNING1("bDeleteFont failed HmgRemoveObject\n");
  216. bRet = FALSE;
  217. }
  218. }
  219. TRACE_FONT(("Exiting bDeleteFont\n"
  220. " return value = %d\n", bRet));
  221. return(bRet);
  222. }
  223. /******************************Public*Routine******************************\
  224. * GreSetFontEnumeration
  225. *
  226. * Comments:
  227. * This function is intended as a private entry point for Control Panel.
  228. *
  229. \**************************************************************************/
  230. ULONG APIENTRY NtGdiSetFontEnumeration(ULONG ulType)
  231. {
  232. return (GreSetFontEnumeration(ulType));
  233. }
  234. ULONG GreSetFontEnumeration(ULONG ulType)
  235. {
  236. ULONG ulOld;
  237. if (ulType & ~(FE_FILTER_TRUETYPE | FE_AA_ON | FE_SET_AA |
  238. FE_CT_ON | FE_SET_CT))
  239. {
  240. WARNING("GreSetFontEnumeration(): unknown ulType %ld\n");
  241. }
  242. ulOld = gulFontInformation;
  243. if(ulType & FE_SET_AA)
  244. gulFontInformation = (ulType & FE_AA_ON) | (ulOld & FE_CT_ON) | (ulOld & FE_FILTER_TRUETYPE);
  245. else if (ulType & FE_SET_CT)
  246. gulFontInformation = (ulType & FE_CT_ON) | (ulOld & FE_AA_ON) | (ulOld & FE_FILTER_TRUETYPE);
  247. else
  248. gulFontInformation = (ulType & FE_FILTER_TRUETYPE) | (ulOld & FE_AA_ON) | (ulOld & FE_CT_ON);
  249. return ulOld;
  250. }
  251. ULONG GreSetFontContrast(ULONG ulContrast)
  252. {
  253. ULONG ulOld;
  254. ulOld = gulGamma;
  255. gulGamma = ulContrast;
  256. return ulOld;
  257. }
  258. ULONG GreGetFontEnumeration(VOID)
  259. {
  260. return gulFontInformation;
  261. }
  262. ULONG GreGetFontContrast(VOID)
  263. {
  264. return gulGamma;
  265. }