[FONTVIEW]
[reactos.git] / reactos / base / applications / fontview / display.c
index 55272ee..9e1f2f2 100644 (file)
  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#include <windows.h>
-#include <stdio.h>
+#include "precomp.h"
 
-#include "display.h"
+#include <stdio.h>
+#include <malloc.h>
 
 #define SPACING1 8
 #define SPACING2 5
@@ -91,7 +91,7 @@ Display_DrawText(HDC hDC, DISPLAYDATA* pData, int nYPos)
        GetTextMetrics(hDC, &tm);
 
        swprintf(szCaption, L"%s%s", pData->szTypeFaceName, pData->szFormat);
-       TextOutW(hDC, 0, y, szCaption, wcslen(szCaption));
+       TextOutW(hDC, 0, y, szCaption, (INT)wcslen(szCaption));
        y += tm.tmHeight + SPACING1;
 
        /* Draw a seperation Line */
@@ -106,15 +106,15 @@ Display_DrawText(HDC hDC, DISPLAYDATA* pData, int nYPos)
        SelectObject(hDC, pData->hCharSetFont);
        GetTextMetrics(hDC, &tm);
        swprintf(szCaption, L"abcdefghijklmnopqrstuvwxyz");
-       TextOutW(hDC, 0, y, szCaption, wcslen(szCaption));
+       TextOutW(hDC, 0, y, szCaption, (INT)wcslen(szCaption));
        y += tm.tmHeight + 1;
 
        swprintf(szCaption, L"ABCDEFGHIJKLMNOPQRSTUVWXYZ");
-       TextOutW(hDC, 0, y, szCaption, wcslen(szCaption));
+       TextOutW(hDC, 0, y, szCaption, (INT)wcslen(szCaption));
        y += tm.tmHeight + 1;
 
-       swprintf(szCaption, L"0123456789.:,;(\"~!@#$%^&*')");
-       TextOutW(hDC, 0, y, szCaption, wcslen(szCaption));
+       swprintf(szCaption, L"0123456789.:,;(\"~!@#$%%^&*')");
+       TextOutW(hDC, 0, y, szCaption, (INT)wcslen(szCaption));
        y += tm.tmHeight + 1;
 
        /* Draw a seperation Line */
@@ -127,18 +127,40 @@ Display_DrawText(HDC hDC, DISPLAYDATA* pData, int nYPos)
        for (i = 0; i < MAX_SIZES; i++)
        {
                SelectObject(hDC, pData->hFonts[i]);
-               TextOutW(hDC, 20, y, pData->szString, wcslen(pData->szString));
+               TextOutW(hDC, 20, y, pData->szString, (INT)wcslen(pData->szString));
                GetTextMetrics(hDC, &tm);
                y += tm.tmHeight + 1;
                SelectObject(hDC, pData->hSizeFont);
                swprintf(szSize, L"%d", pData->nSizes[i]);
-               TextOutW(hDC, 0, y - 13 - tm.tmDescent, szSize, wcslen(szSize));
+               TextOutW(hDC, 0, y - 13 - tm.tmDescent, szSize, (INT)wcslen(szSize));
        }
        SelectObject(hDC, hOldFont);
 
        return y;
 }
 
+static int
+CALLBACK
+EnumFontFamProcW(
+       const LOGFONTW *lpelfe,
+       const TEXTMETRICW *lptm,
+       DWORD FontType,
+       LPARAM lParam)
+{
+       PNEWTEXTMETRICW pntmw = (PNEWTEXTMETRICW)lptm;
+       PBOOL pfOpenType = (PBOOL)lParam;
+
+       if (FontType & TRUETYPE_FONTTYPE)
+       {
+               if (pntmw->ntmFlags & (NTM_TT_OPENTYPE | NTM_PS_OPENTYPE))
+               {
+                       *pfOpenType = TRUE;
+                       return FALSE;
+               }
+       }
+       return TRUE;
+}
+
 static LRESULT
 Display_SetTypeFace(HWND hwnd, PEXTLOGFONTW pExtLogFont)
 {
@@ -163,12 +185,27 @@ Display_SetTypeFace(HWND hwnd, PEXTLOGFONTW pExtLogFont)
        pData->hCharSetFont = CreateFontIndirectW(&logfont);
 
        /* Get font format */
-       // FIXME: Get the real font format (OpenType?)
        SelectObject(hDC, pData->hCharSetFont);
        GetTextMetrics(hDC, &tm);
-       if ((tm.tmPitchAndFamily & TMPF_TRUETYPE) == TMPF_TRUETYPE)
+       if (tm.tmPitchAndFamily & TMPF_TRUETYPE)
+       {
+               BOOL fOpenType = FALSE;
+
+               EnumFontFamiliesExW(hDC, &logfont,
+                       EnumFontFamProcW, (LPARAM)&fOpenType, 0);
+
+               if (fOpenType)
+                       swprintf(pData->szFormat, L" (OpenType)");
+               else
+                       swprintf(pData->szFormat, L" (TrueType)");
+       }
+       else if (tm.tmPitchAndFamily & TMPF_VECTOR)
+       {
+               swprintf(pData->szFormat, L" (Vector)");
+       }
+       else
        {
-               swprintf(pData->szFormat, L" (TrueType)");
+               swprintf(pData->szFormat, L" (Raster)");
        }
 
        for (i = 0; i < MAX_SIZES; i++)
@@ -377,6 +414,94 @@ Display_OnDestroy(HWND hwnd)
        return 0;
 }
 
+LRESULT
+Display_OnPrint(HWND hwnd)
+{
+       PRINTDLG pfont;
+       TEXTMETRIC tm;
+       int copies, yPos;
+
+       /* Clears the memory before using it */
+       ZeroMemory(&pfont, sizeof(pfont));
+
+       pfont.lStructSize = sizeof(pfont);
+       pfont.hwndOwner = hwnd;
+       pfont.hDevMode = NULL;
+       pfont.hDevNames = NULL;
+       pfont.Flags = PD_USEDEVMODECOPIESANDCOLLATE | PD_RETURNDC;
+       pfont.nCopies = 1;
+       pfont.nFromPage = 0xFFFF;
+       pfont.nToPage = 0xFFFF;
+       pfont.nMinPage = 1;
+       pfont.nMaxPage = 0xFFFF;
+
+       /* Opens up the print dialog box */
+       if (PrintDlg(&pfont))
+       {
+               DOCINFO docinfo;
+#if 0
+               DISPLAYDATA* pData;
+
+               pData = malloc(sizeof(DISPLAYDATA));
+               ZeroMemory(pData, sizeof(DISPLAYDATA));
+
+               /* Sets up the font layout */
+               pData = (DISPLAYDATA*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
+#endif
+               docinfo.cbSize = sizeof(DOCINFO);
+               docinfo.lpszDocName = "Printing Font";
+               docinfo.lpszOutput = NULL;
+               docinfo.lpszDatatype = NULL;
+               docinfo.fwType = 0;
+
+               /* We start printing */
+               StartDoc(pfont.hDC, &docinfo);
+
+               /* Grabs the text metrics for the printer */
+               GetTextMetrics(pfont.hDC, &tm);
+
+               /* Start out with 0 for the y position for the page */
+               yPos = 0;
+
+               /* Starts out with the current page */
+               StartPage(pfont.hDC);
+
+               /* Used when printing for more than one copy */
+               for (copies = 0; copies < pfont.nCopies; copies++)
+               {
+                       /* Test output */
+                       TextOutW(pfont.hDC, 10, yPos, L"Testing...1...2...3", 19);
+
+                       /* TODO: Determine if using Display_DrawText() will work for both rendering out to the
+                       window and to the printer output */
+#if 0
+                       Display_DrawText(pfont.hDC, pData, yPos);
+#endif
+
+                       /* Ends the current page */
+                       EndPage(pfont.hDC);
+
+                       /* If we are making more than one copy, start a new page */
+                       if (copies != pfont.nCopies)
+                       {
+                               yPos = 0;
+                               StartPage(pfont.hDC);
+                       }
+               }
+
+               /* The printing is now over */
+               EndDoc(pfont.hDC);
+
+               DeleteDC(pfont.hDC);
+#if 0
+               /* Frees the memory since we no longer need it for now */
+               free(pData);
+#endif
+       }
+
+       return 0;
+}
+
 LRESULT CALLBACK
 DisplayProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
 {