PageRenderTime 160ms CodeModel.GetById 149ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/binding/win32/gdiplusfontcollection.d

http://github.com/wilkie/djehuty
D | 139 lines | 92 code | 24 blank | 23 comment | 7 complexity | ddefca0728e0a505e661463d7e1900af MD5 | raw file
  1/*
  2 * gdiplusfontcollection.d
  3 *
  4 * This module implements GdiPlusFontCollection.h for D. The original
  5 * copyright info is given below.
  6 *
  7 * Author: Dave Wilkinson
  8 * Originated: November 25th, 2009
  9 *
 10 */
 11
 12module binding.win32.gdiplusfontcollection;
 13
 14import binding.win32.windef;
 15import binding.win32.winbase;
 16import binding.win32.winnt;
 17import binding.win32.wingdi;
 18import binding.win32.guiddef;
 19import binding.win32.gdiplusbase;
 20import binding.win32.gdiplustypes;
 21import binding.win32.gdiplusenums;
 22import binding.win32.gdipluspixelformats;
 23import binding.win32.gdiplusgpstubs;
 24import binding.win32.gdiplusmetaheader;
 25import binding.win32.gdipluspixelformats;
 26import binding.win32.gdipluscolor;
 27import binding.win32.gdipluscolormatrix;
 28import binding.win32.gdiplusflat;
 29import binding.win32.gdiplusimaging;
 30import binding.win32.gdiplusbitmap;
 31import binding.win32.gdiplusimageattributes;
 32import binding.win32.gdiplusmatrix;
 33import binding.win32.gdiplusfontfamily;
 34
 35/**************************************************************************\
 36*
 37* Copyright (c) 2000, Microsoft Corp.  All Rights Reserved.
 38*
 39* Module Name:
 40* 
 41*   GdiplusFontCollection.h
 42*
 43* Abstract:
 44*
 45*   Font collections (Installed and Private)
 46*
 47\**************************************************************************/
 48
 49class FontCollection : GdiplusBase {
 50
 51    this() {
 52    }
 53    
 54    ~this() {
 55    }
 56
 57    INT GetFamilyCount() {
 58        INT numFound = 0;
 59    
 60        lastResult = GdipGetFontCollectionFamilyCount(
 61                                 nativeFontCollection, &numFound);
 62    
 63        return numFound;       
 64    }
 65
 66    Status GetFamilies(in INT numSought, FontFamily[] gpfamilies, INT* numFound) {
 67        if (numSought <= 0 || gpfamilies is null || numFound is null) {
 68            return SetStatus(Status.InvalidParameter);
 69        }
 70        
 71        *numFound = 0;
 72        GpFontFamily*[] nativeFamilyList = new GpFontFamily*[numSought];
 73    
 74        if (nativeFamilyList is null) {
 75            return SetStatus(Status.OutOfMemory);
 76        }
 77    
 78        Status status = SetStatus(GdipGetFontCollectionFamilyList(
 79            nativeFontCollection,
 80            numSought,
 81            nativeFamilyList,
 82            numFound
 83        ));
 84        if (status == Status.Ok){
 85            for (INT i = 0; i < *numFound; i++) {
 86                GdipCloneFontFamily(nativeFamilyList[i],
 87                                                &gpfamilies[i].nativeFamily);
 88            }
 89        }
 90    
 91        return status;
 92    }
 93
 94    Status GetLastStatus() {
 95        return lastResult;        
 96    }
 97
 98protected:
 99    package Status SetStatus(Status status) {
100        lastResult = status;
101        return lastResult;        
102    }
103
104    package GpFontCollection *nativeFontCollection = null;
105    package Status    lastResult;
106}
107
108
109class InstalledFontCollection : FontCollection {
110    this() {
111        nativeFontCollection = null;
112        lastResult = GdipNewInstalledFontCollection(&nativeFontCollection);
113    }
114    
115    ~this() {
116    }
117}
118
119class PrivateFontCollection : FontCollection {
120    this() {
121        nativeFontCollection = null;
122        lastResult = GdipNewPrivateFontCollection(&nativeFontCollection);
123    }
124    
125    ~this() {
126        GdipDeletePrivateFontCollection(&nativeFontCollection);        
127    }
128
129    Status AddFontFile(in WCHAR* filename) {
130        return SetStatus(GdipPrivateAddFontFile(nativeFontCollection, filename));        
131    }
132    
133    Status AddMemoryFont(in VOID* memory, in INT length) {
134        return SetStatus(GdipPrivateAddMemoryFont(
135            nativeFontCollection,
136            memory,
137            length));                             
138    }
139}