Use mapped sections for fonts instead of paged pool memory.
Modified: trunk/reactos/subsys/win32k/objects/text.c

Modified: trunk/reactos/subsys/win32k/objects/text.c
--- trunk/reactos/subsys/win32k/objects/text.c	2005-08-02 20:17:01 UTC (rev 16976)
+++ trunk/reactos/subsys/win32k/objects/text.c	2005-08-02 20:33:33 UTC (rev 16977)
@@ -256,22 +256,24 @@
    HANDLE FileHandle;
    OBJECT_ATTRIBUTES ObjectAttributes;
    FILE_STANDARD_INFORMATION FileStdInfo;
-   PVOID Buffer;
+   PVOID Buffer = NULL;
    IO_STATUS_BLOCK Iosb;
    INT Error;
    FT_Face Face;
    ANSI_STRING AnsiFaceName;
    PFONT_ENTRY Entry;
+   PSECTION_OBJECT SectionObject;
+   ULONG ViewSize = 0;
 
    /* Open the font file */
 
    InitializeObjectAttributes(&ObjectAttributes, FileName, 0, NULL, NULL);
    Status = ZwOpenFile(
       &FileHandle,
-      GENERIC_READ | SYNCHRONIZE,
+      FILE_GENERIC_READ | SYNCHRONIZE,
       &ObjectAttributes,
       &Iosb,
-      0,
+      FILE_SHARE_READ,
       FILE_SYNCHRONOUS_IO_NONALERT);
 
    if (!NT_SUCCESS(Status))
@@ -280,59 +282,25 @@
       return 0;
    }
 
-   /* Get the size of the file */
-
-   Status = ZwQueryInformationFile(
-      FileHandle,
-      &Iosb,
-      &FileStdInfo,
-      sizeof(FileStdInfo),
-      FileStandardInformation);
-
+   Status = MmCreateSection(&SectionObject, SECTION_ALL_ACCESS,
+                            NULL, NULL, PAGE_READONLY,
+                            0, FileHandle, NULL);
    if (!NT_SUCCESS(Status))
    {
-      DPRINT("Could not get file size\n");
+      DPRINT("Could not map file: %wZ\n", FileName);
       ZwClose(FileHandle);
       return 0;
    }
 
-   /* Allocate pageable memory for the font */
+   ZwClose(FileHandle);
 
-   Buffer = ExAllocatePoolWithTag(
-      PagedPool,
-      FileStdInfo.EndOfFile.u.LowPart,
-      TAG_FNTFILE);
-
-   if (Buffer == NULL)
-   {
-      DPRINT("Could not allocate memory for font");
-      ZwClose(FileHandle);
-      return 0;
-   }
-
-   /* Load the font into memory chunk */
-
-   Status = ZwReadFile(
-      FileHandle,
-      NULL,
-      NULL,
-      NULL,
-      &Iosb,
-      Buffer,
-      FileStdInfo.EndOfFile.u.LowPart,
-      NULL,
-      NULL);
-
+   Status = MmMapViewInSystemSpace(SectionObject, &Buffer, &ViewSize);
    if (!NT_SUCCESS(Status))
    {
-      DPRINT("Could not read the font file into memory");
-      ExFreePool(Buffer);
-      ZwClose(FileHandle);
-      return 0;
+      DPRINT("Could not map file: %wZ\n", FileName);
+      return Status;
    }
 
-   ZwClose(FileHandle);
-
    IntLockFreeType;
    Error = FT_New_Memory_Face(
       library,
@@ -348,7 +316,7 @@
          DPRINT("Unknown font file format\n");
       else
          DPRINT("Error reading font file (error code: %u)\n", Error);
-      ExFreePool(Buffer);
+      ObDereferenceObject(SectionObject);
       return 0;
    }
 
@@ -356,7 +324,7 @@
    if (!Entry)
    {
       FT_Done_Face(Face);
-      ExFreePool(Buffer);
+      ObDereferenceObject(SectionObject);
       SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY);
       return 0;
    }
@@ -365,7 +333,7 @@
    if(FontGDI == NULL)
    {
       FT_Done_Face(Face);
-      ExFreePool(Buffer);
+      ObDereferenceObject(SectionObject);
       ExFreePool(Entry);
       SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY);
       return 0;
@@ -1559,7 +1527,7 @@
       }
    }
 
-   BitmapObj = BITMAPOBJ_LockBitmap(dc->w.hBitmap);
+   BitmapObj = BITMAPOBJ_LockBitmap(DC_BITMAP(dc));
    if ( !BitmapObj )
    {
       goto fail;
@@ -1574,7 +1542,7 @@
    YStart = Start.y + dc->w.DCOrgY;
 
    /* Create the brushes */
-   PalDestGDI = PALETTE_LockPalette(dc->w.hPalette);
+   PalDestGDI = PALETTE_LockPalette(DC_PALETTE(dc));
    if ( !PalDestGDI )
       Mode = PAL_RGB;
    else
@@ -1582,7 +1550,7 @@
       Mode = PalDestGDI->Mode;
       PALETTE_UnlockPalette(PalDestGDI);
    }
-   XlateObj = (XLATEOBJ*)IntEngCreateXlate(Mode, PAL_RGB, dc->w.hPalette, NULL);
+   XlateObj = (XLATEOBJ*)IntEngCreateXlate(Mode, PAL_RGB, DC_PALETTE(dc), NULL);
    if ( !XlateObj )
    {
       goto fail;
@@ -1612,7 +1580,7 @@
       }
       IntGdiInitBrushInstance(&BrushBgInst, BrushBg, NULL);
    }
-   XlateObj2 = (XLATEOBJ*)IntEngCreateXlate(PAL_RGB, Mode, NULL, dc->w.hPalette);
+   XlateObj2 = (XLATEOBJ*)IntEngCreateXlate(PAL_RGB, Mode, NULL, DC_PALETTE(dc));
    if ( !XlateObj2 )
    {
       goto fail;