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
4 : *
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/
9 : *
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.
14 : *
15 : * The Original Code is mozilla.org code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * mozilla.org.
19 : * Portions created by the Initial Developer are Copyright (C) 2006
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * Vladimir Vukicevic <vladimir@mozilla.com>
24 : *
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.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 :
39 : #include "nsThebesFontEnumerator.h"
40 :
41 : #include "nsMemory.h"
42 :
43 : #include "gfxPlatform.h"
44 : #include "nsTArray.h"
45 : #include "nsIAtom.h"
46 :
47 0 : NS_IMPL_ISUPPORTS1(nsThebesFontEnumerator, nsIFontEnumerator)
48 :
49 0 : nsThebesFontEnumerator::nsThebesFontEnumerator()
50 : {
51 0 : }
52 :
53 : NS_IMETHODIMP
54 0 : nsThebesFontEnumerator::EnumerateAllFonts(PRUint32 *aCount,
55 : PRUnichar ***aResult)
56 : {
57 0 : return EnumerateFonts (nsnull, nsnull, aCount, aResult);
58 : }
59 :
60 : NS_IMETHODIMP
61 0 : nsThebesFontEnumerator::EnumerateFonts(const char *aLangGroup,
62 : const char *aGeneric,
63 : PRUint32 *aCount,
64 : PRUnichar ***aResult)
65 : {
66 0 : NS_ENSURE_ARG_POINTER(aCount);
67 0 : NS_ENSURE_ARG_POINTER(aResult);
68 :
69 0 : nsTArray<nsString> fontList;
70 :
71 0 : nsCAutoString generic;
72 0 : if (aGeneric)
73 0 : generic.Assign(aGeneric);
74 : else
75 0 : generic.SetIsVoid(true);
76 :
77 0 : nsCOMPtr<nsIAtom> langGroupAtom;
78 0 : if (aLangGroup) {
79 0 : nsCAutoString lowered;
80 0 : lowered.Assign(aLangGroup);
81 0 : ToLowerCase(lowered);
82 0 : langGroupAtom = do_GetAtom(lowered);
83 : }
84 :
85 0 : nsresult rv = gfxPlatform::GetPlatform()->GetFontList(langGroupAtom, generic, fontList);
86 :
87 0 : if (NS_FAILED(rv)) {
88 0 : *aCount = 0;
89 0 : *aResult = nsnull;
90 : /* XXX in this case, do we want to return the CSS generics? */
91 0 : return NS_OK;
92 : }
93 :
94 : PRUnichar **fs = static_cast<PRUnichar **>
95 0 : (nsMemory::Alloc(fontList.Length() * sizeof(PRUnichar*)));
96 0 : for (PRUint32 i = 0; i < fontList.Length(); i++) {
97 0 : fs[i] = ToNewUnicode(fontList[i]);
98 : }
99 :
100 0 : *aResult = fs;
101 0 : *aCount = fontList.Length();
102 :
103 0 : return NS_OK;
104 : }
105 :
106 : NS_IMETHODIMP
107 0 : nsThebesFontEnumerator::HaveFontFor(const char *aLangGroup,
108 : bool *aResult)
109 : {
110 0 : NS_ENSURE_ARG_POINTER(aResult);
111 :
112 0 : *aResult = true;
113 0 : return NS_OK;
114 : }
115 :
116 : NS_IMETHODIMP
117 0 : nsThebesFontEnumerator::GetDefaultFont(const char *aLangGroup,
118 : const char *aGeneric,
119 : PRUnichar **aResult)
120 : {
121 0 : NS_ENSURE_ARG_POINTER(aResult);
122 0 : *aResult = nsnull;
123 0 : return NS_OK;
124 : }
125 :
126 : NS_IMETHODIMP
127 0 : nsThebesFontEnumerator::UpdateFontList(bool *_retval)
128 : {
129 0 : gfxPlatform::GetPlatform()->UpdateFontList();
130 0 : *_retval = false; // always return false for now
131 0 : return NS_OK;
132 : }
133 :
134 : NS_IMETHODIMP
135 0 : nsThebesFontEnumerator::GetStandardFamilyName(const PRUnichar *aName,
136 : PRUnichar **aResult)
137 : {
138 0 : NS_ENSURE_ARG_POINTER(aResult);
139 0 : NS_ENSURE_ARG_POINTER(aName);
140 :
141 0 : nsAutoString name(aName);
142 0 : if (name.IsEmpty()) {
143 0 : *aResult = nsnull;
144 0 : return NS_OK;
145 : }
146 :
147 0 : nsAutoString family;
148 0 : nsresult rv = gfxPlatform::GetPlatform()->
149 0 : GetStandardFamilyName(nsDependentString(aName), family);
150 0 : if (NS_FAILED(rv) || family.IsEmpty()) {
151 0 : *aResult = nsnull;
152 0 : return NS_OK;
153 : }
154 0 : *aResult = ToNewUnicode(family);
155 0 : return NS_OK;
156 : }
|