Bug 458861. Validate TrueType headers before activating downloaded font. r=roc, sr...
[wine-gecko.git] / gfx / src / thebes / nsThebesGfxFactory.cpp
blob4d2b1eb5960d2f5238ac4ee275ce94547035c77a
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is thebes gfx
17 * The Initial Developer of the Original Code is
18 * mozilla.org.
19 * Portions created by the Initial Developer are Copyright (C) 2005
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Vladimir Vukicevic <vladimir@pobox.com>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #include "nsIGenericFactory.h"
40 #include "nsIModule.h"
41 #include "nsCOMPtr.h"
42 #include "nsGfxCIID.h"
44 #include "nsScriptableRegion.h"
45 #include "gfxImageFrame.h"
47 #include "nsThebesDeviceContext.h"
48 #include "nsThebesRenderingContext.h"
49 #include "nsThebesImage.h"
50 #include "nsThebesRegion.h"
51 #include "nsThebesFontMetrics.h"
52 #include "nsThebesFontEnumerator.h"
53 #include "gfxPlatform.h"
55 NS_GENERIC_FACTORY_CONSTRUCTOR(nsThebesFontMetrics)
56 NS_GENERIC_FACTORY_CONSTRUCTOR(gfxImageFrame)
57 NS_GENERIC_FACTORY_CONSTRUCTOR(nsThebesDeviceContext)
58 NS_GENERIC_FACTORY_CONSTRUCTOR(nsThebesRenderingContext)
59 NS_GENERIC_FACTORY_CONSTRUCTOR(nsThebesImage)
60 NS_GENERIC_FACTORY_CONSTRUCTOR(nsThebesRegion)
61 NS_GENERIC_FACTORY_CONSTRUCTOR(nsThebesFontEnumerator)
63 static NS_IMETHODIMP nsScriptableRegionConstructor(nsISupports *aOuter, REFNSIID aIID, void **aResult)
65 nsresult rv;
67 nsIScriptableRegion *inst = nsnull;
69 if ( !aResult )
71 rv = NS_ERROR_NULL_POINTER;
72 return rv;
74 *aResult = nsnull;
75 if (aOuter)
77 rv = NS_ERROR_NO_AGGREGATION;
78 return rv;
81 nsCOMPtr <nsIRegion> rgn;
82 NS_NEWXPCOM(rgn, nsThebesRegion);
83 nsCOMPtr<nsIScriptableRegion> scriptableRgn;
84 if (rgn != nsnull)
86 scriptableRgn = new nsScriptableRegion(rgn);
87 inst = scriptableRgn;
89 if (!inst)
91 rv = NS_ERROR_OUT_OF_MEMORY;
92 return rv;
94 NS_ADDREF(inst);
95 // release our variable above now that we have created our owning
96 // reference - we don't want this to go out of scope early!
97 scriptableRgn = nsnull;
98 rv = inst->QueryInterface(aIID, aResult);
99 NS_RELEASE(inst);
101 return rv;
104 static const nsModuleComponentInfo components[] =
106 { "Thebes nsFontMetrics",
107 NS_FONT_METRICS_CID,
108 "@mozilla.org/gfx/fontmetrics;1",
109 nsThebesFontMetricsConstructor },
110 { "Thebes Font Enumerator",
111 NS_FONT_ENUMERATOR_CID,
112 "@mozilla.org/gfx/fontenumerator;1",
113 nsThebesFontEnumeratorConstructor },
114 { "Thebes Device Context",
115 NS_DEVICE_CONTEXT_CID,
116 "@mozilla.org/gfx/devicecontext;1",
117 nsThebesDeviceContextConstructor },
118 { "Thebes Rendering Context",
119 NS_RENDERING_CONTEXT_CID,
120 "@mozilla.org/gfx/renderingcontext;1",
121 nsThebesRenderingContextConstructor },
122 { "Thebes nsImage",
123 NS_IMAGE_CID,
124 "@mozilla.org/gfx/image;1",
125 nsThebesImageConstructor },
126 { "Thebes Region",
127 NS_REGION_CID,
128 "@mozilla.org/gfx/region/nsThebes;1",
129 nsThebesRegionConstructor },
130 { "Scriptable Region",
131 NS_SCRIPTABLE_REGION_CID,
132 "@mozilla.org/gfx/region;1",
133 nsScriptableRegionConstructor },
134 { "image frame",
135 GFX_IMAGEFRAME_CID,
136 "@mozilla.org/gfx/image/frame;2",
137 gfxImageFrameConstructor },
140 static nsresult
141 nsThebesGfxModuleCtor(nsIModule *self)
143 return gfxPlatform::Init();
146 static void
147 nsThebesGfxModuleDtor(nsIModule *self)
149 nsThebesDeviceContext::Shutdown();
150 gfxPlatform::Shutdown();
153 NS_IMPL_NSGETMODULE_WITH_CTOR_DTOR(nsGfxModule, components,
154 nsThebesGfxModuleCtor, nsThebesGfxModuleDtor)