⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 font.c

📁 这是一个开放源代码的与WINNT/WIN2K/WIN2003兼容的操作系统
💻 C
📖 第 1 页 / 共 3 页
字号:


/*
 * @implemented
 */
HFONT
STDCALL
CreateFontIndirectA(
	CONST LOGFONTA		*lplf
	)
{
  if (lplf)
    {
      LOGFONTW tlf;

      LogFontA2W(&tlf, lplf);
      return CreateFontIndirectW(&tlf);
    }
  else return NULL;
}


/*
 * @implemented
 */
HFONT
STDCALL
CreateFontIndirectW(
	CONST LOGFONTW		*lplf
	)
{
 if (lplf)
 {
    ENUMLOGFONTEXDVW Logfont;

    RtlCopyMemory( &Logfont.elfEnumLogfontEx.elfLogFont, lplf, sizeof(LOGFONTW));
    // Need something other than just cleaning memory here.
    // Guess? Use caller data to determine the rest.
    RtlZeroMemory( &Logfont.elfEnumLogfontEx.elfFullName,
                                 sizeof(Logfont.elfEnumLogfontEx.elfFullName));
    RtlZeroMemory( &Logfont.elfEnumLogfontEx.elfStyle,
                                 sizeof(Logfont.elfEnumLogfontEx.elfStyle));
    RtlZeroMemory( &Logfont.elfEnumLogfontEx.elfScript,
                                 sizeof(Logfont.elfEnumLogfontEx.elfScript));
    
    RtlZeroMemory( &Logfont.elfDesignVector, sizeof(DESIGNVECTOR));

    return CreateFontIndirectExW(&Logfont);
 }
 else return NULL;
}


/*
 * @implemented
 */
HFONT
STDCALL
CreateFontA(
	int	nHeight,
	int	nWidth,
	int	nEscapement,
	int	nOrientation,
	int	fnWeight,
	DWORD	fdwItalic,
	DWORD	fdwUnderline,
	DWORD	fdwStrikeOut,
	DWORD	fdwCharSet,
	DWORD	fdwOutputPrecision,
	DWORD	fdwClipPrecision,
	DWORD	fdwQuality,
	DWORD	fdwPitchAndFamily,
	LPCSTR	lpszFace
	)
{
        ANSI_STRING StringA;
        UNICODE_STRING StringU;
	HFONT ret;

	RtlInitAnsiString(&StringA, (LPSTR)lpszFace);
	RtlAnsiStringToUnicodeString(&StringU, &StringA, TRUE);

        ret = CreateFontW(nHeight, 
                           nWidth,
                      nEscapement,
                     nOrientation,
                         fnWeight,
                        fdwItalic,
                     fdwUnderline,
                     fdwStrikeOut,
                       fdwCharSet,
               fdwOutputPrecision,
                 fdwClipPrecision,
                       fdwQuality,
                fdwPitchAndFamily,
                   StringU.Buffer);

	RtlFreeUnicodeString(&StringU);

	return ret;
}


/*
 * @implemented
 */
HFONT
STDCALL
CreateFontW(
	int	nHeight,
	int	nWidth,
	int	nEscapement,
	int	nOrientation,
	int	nWeight,
	DWORD	fnItalic,
	DWORD	fdwUnderline,
	DWORD	fdwStrikeOut,
	DWORD	fdwCharSet,
	DWORD	fdwOutputPrecision,
	DWORD	fdwClipPrecision,
	DWORD	fdwQuality,
	DWORD	fdwPitchAndFamily,
	LPCWSTR	lpszFace
	)
{
  LOGFONTW logfont;

  logfont.lfHeight = nHeight;
  logfont.lfWidth = nWidth;
  logfont.lfEscapement = nEscapement;
  logfont.lfOrientation = nOrientation;
  logfont.lfWeight = nWeight;
  logfont.lfItalic = fnItalic;
  logfont.lfUnderline = fdwUnderline;
  logfont.lfStrikeOut = fdwStrikeOut;
  logfont.lfCharSet = fdwCharSet;
  logfont.lfOutPrecision = fdwOutputPrecision;
  logfont.lfClipPrecision = fdwClipPrecision;
  logfont.lfQuality = fdwQuality;
  logfont.lfPitchAndFamily = fdwPitchAndFamily;

  if (NULL != lpszFace)
  {
    int Size = sizeof(logfont.lfFaceName) / sizeof(WCHAR);
    wcsncpy((wchar_t *)logfont.lfFaceName, lpszFace, Size - 1);
    /* Be 101% sure to have '\0' at end of string */
    logfont.lfFaceName[Size - 1] = '\0';
  }
  else
  {
    logfont.lfFaceName[0] = L'\0';
  }

  return CreateFontIndirectW(&logfont);
}


/*
 * @implemented
 */
BOOL
STDCALL
CreateScalableFontResourceW(
	DWORD		fdwHidden,
	LPCWSTR		lpszFontRes,
	LPCWSTR		lpszFontFile,
	LPCWSTR		lpszCurrentPath
	)
{
  return NtGdiCreateScalableFontResource ( fdwHidden,
					  lpszFontRes,
					  lpszFontFile,
					  lpszCurrentPath );
}


/*
 * @implemented
 */
BOOL
STDCALL
CreateScalableFontResourceA(
	DWORD		fdwHidden,
	LPCSTR		lpszFontRes,
	LPCSTR		lpszFontFile,
	LPCSTR		lpszCurrentPath
	)
{
  NTSTATUS Status;
  LPWSTR lpszFontResW, lpszFontFileW, lpszCurrentPathW;
  BOOL rc = FALSE;

  Status = HEAP_strdupA2W ( &lpszFontResW, lpszFontRes );
  if (!NT_SUCCESS (Status))
    SetLastError (RtlNtStatusToDosError(Status));
  else
    {
      Status = HEAP_strdupA2W ( &lpszFontFileW, lpszFontFile );
      if (!NT_SUCCESS (Status))
	SetLastError (RtlNtStatusToDosError(Status));
      else
	{
	  Status = HEAP_strdupA2W ( &lpszCurrentPathW, lpszCurrentPath );
	  if (!NT_SUCCESS (Status))
	    SetLastError (RtlNtStatusToDosError(Status));
	  else
	    {
	      rc = NtGdiCreateScalableFontResource ( fdwHidden,
						    lpszFontResW,
						    lpszFontFileW,
						    lpszCurrentPathW );

	      HEAP_free ( lpszCurrentPathW );
	    }

	  HEAP_free ( lpszFontFileW );
	}

      HEAP_free ( lpszFontResW );
    }
  return rc;
}


/*
 * @implemented
 */
int
STDCALL
AddFontResourceExW ( LPCWSTR lpszFilename, DWORD fl, PVOID pvReserved )
{
  UNICODE_STRING Filename;

  /* FIXME handle fl parameter */
  RtlInitUnicodeString(&Filename, lpszFilename);
  return NtGdiAddFontResource ( &Filename, fl );
}


/*
 * @implemented
 */
int
STDCALL
AddFontResourceExA ( LPCSTR lpszFilename, DWORD fl, PVOID pvReserved )
{
  NTSTATUS Status;
  PWSTR FilenameW;
  int rc = 0;

  Status = HEAP_strdupA2W ( &FilenameW, lpszFilename );
  if ( !NT_SUCCESS (Status) )
    SetLastError (RtlNtStatusToDosError(Status));
  else
    {
      rc = AddFontResourceExW ( FilenameW, fl, pvReserved );

      HEAP_free ( FilenameW );
    }
  return rc;
}


/*
 * @implemented
 */
int
STDCALL
AddFontResourceA ( LPCSTR lpszFilename )
{
  return AddFontResourceExA ( lpszFilename, 0, 0 );
}


/*
 * @implemented
 */
int
STDCALL
AddFontResourceW ( LPCWSTR lpszFilename )
{
	return AddFontResourceExW ( lpszFilename, 0, 0 );
}


/*
 * @implemented
 */
BOOL
STDCALL
RemoveFontResourceW(
	LPCWSTR	lpFileName
	)
{
  return NtGdiRemoveFontResource ( lpFileName );
}


/*
 * @implemented
 */
BOOL
STDCALL
RemoveFontResourceA(
	LPCSTR	lpFileName
	)
{
  NTSTATUS Status;
  LPWSTR lpFileNameW;
  BOOL rc = 0;

  Status = HEAP_strdupA2W ( &lpFileNameW, lpFileName );
  if (!NT_SUCCESS (Status))
    SetLastError (RtlNtStatusToDosError(Status));
  else
    {
      rc = NtGdiRemoveFontResource ( lpFileNameW );

      HEAP_free ( lpFileNameW );
    }

  return rc;
}

/***********************************************************************
 *           GdiGetCharDimensions
 *
 * Gets the average width of the characters in the English alphabet.
 *
 * PARAMS
 *  hdc    [I] Handle to the device context to measure on.
 *  lptm   [O] Pointer to memory to store the text metrics into.
 *  height [O] On exit, the maximum height of characters in the English alphabet.
 *
 * RETURNS
 *  The average width of characters in the English alphabet.
 *
 * NOTES
 *  This function is used by the dialog manager to get the size of a dialog
 *  unit. It should also be used by other pieces of code that need to know
 *  the size of a dialog unit in logical units without having access to the
 *  window handle of the dialog.
 *  Windows caches the font metrics from this function, but we don't and
 *  there doesn't appear to be an immediate advantage to do so.
 *
 * SEE ALSO
 *  GetTextExtentPointW, GetTextMetricsW, MapDialogRect.
 *
 * Despite most of MSDN insisting that the horizontal base unit is
 * tmAveCharWidth it isn't.  Knowledge base article Q145994
 * "HOWTO: Calculate Dialog Units When Not Using the System Font",
 * says that we should take the average of the 52 English upper and lower
 * case characters.
 */
/*
 * @implemented
 */
DWORD
STDCALL
GdiGetCharDimensions(HDC hdc, LPTEXTMETRICW lptm, LONG *height)
{
    SIZE sz;
    static const WCHAR alphabet[] = {
        'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q',
        'r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H',
        'I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',0};

    if(lptm && !GetTextMetricsW(hdc, lptm)) return 0;

    if(!GetTextExtentPointW(hdc, alphabet, 52, &sz)) return 0;

    if (height) *height = sz.cy;
    return (sz.cx / 26 + 1) / 2;
}


/*
 * @unimplemented
 */
int
STDCALL
EnumFontsW(
	HDC  hDC,
	LPCWSTR lpFaceName,
	FONTENUMPROCW  FontFunc,
	LPARAM  lParam
	)
{
#if 0
  return NtGdiEnumFonts ( hDC, lpFaceName, FontFunc, lParam );
#else
  return EnumFontFamiliesW( hDC, lpFaceName, FontFunc, lParam );
#endif
}

/*
 * @unimplemented
 */
int
STDCALL
EnumFontsA (
	HDC  hDC,
	LPCSTR lpFaceName,
	FONTENUMPROCA  FontFunc,
	LPARAM  lParam
	)
{
#if 0
  NTSTATUS Status;
  LPWSTR lpFaceNameW;
  int rc = 0;

  Status = HEAP_strdupA2W ( &lpFaceNameW, lpFaceName );
  if (!NT_SUCCESS (Status))
    SetLastError (RtlNtStatusToDosError(Status));
  else
    {
      rc = NtGdiEnumFonts ( hDC, lpFaceNameW, FontFunc, lParam );

      HEAP_free ( lpFaceNameW );
    }
  return rc;
#else
  return EnumFontFamiliesA( hDC, lpFaceName, FontFunc, lParam );
#endif
}




⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -