~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/gfx/src/gtk/nsFontMetricsUtils.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 
2
/* vim:expandtab:shiftwidth=4:tabstop=4:
 
3
 */
 
4
/* ***** BEGIN LICENSE BLOCK *****
 
5
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 
6
 *
 
7
 * The contents of this file are subject to the Mozilla Public License Version
 
8
 * 1.1 (the "License"); you may not use this file except in compliance with
 
9
 * the License. You may obtain a copy of the License at
 
10
 * http://www.mozilla.org/MPL/
 
11
 *
 
12
 * Software distributed under the License is distributed on an "AS IS" basis,
 
13
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 
14
 * for the specific language governing rights and limitations under the
 
15
 * License.
 
16
 *
 
17
 * The Original Code is mozilla.org code.
 
18
 *
 
19
 * The Initial Developer of the Original Code Christopher Blizzard
 
20
 * <blizzard@mozilla.org>.  Portions created by the Initial Developer
 
21
 * are Copyright (C) 2002 the Initial Developer. All Rights Reserved.
 
22
 *
 
23
 * Contributor(s):
 
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
// welcome to the dumping ground for font metrics stuff that has to
 
40
// know about both the xft and core fonts code.
 
41
 
 
42
#ifdef MOZ_ENABLE_XFT
 
43
#include "nsFontMetricsXft.h"
 
44
#include "nsIPref.h"
 
45
#include "nsIServiceManagerUtils.h"
 
46
#include "prenv.h"
 
47
#endif /* MOZ_ENABLE_XFT */
 
48
 
 
49
#ifdef MOZ_ENABLE_COREXFONTS
 
50
#include "nsFontMetricsGTK.h"
 
51
#endif
 
52
 
 
53
#include "nsFontMetricsUtils.h"
 
54
 
 
55
PRUint32
 
56
NS_FontMetricsGetHints(void)
 
57
{
 
58
#ifdef MOZ_ENABLE_XFT
 
59
    if (NS_IsXftEnabled()) {
 
60
        return nsFontMetricsXft::GetHints();
 
61
    }
 
62
#endif
 
63
 
 
64
#ifdef MOZ_ENABLE_COREXFONTS
 
65
    return nsFontMetricsGTK::GetHints();
 
66
#endif
 
67
}
 
68
 
 
69
nsresult
 
70
NS_FontMetricsFamilyExists(nsIDeviceContext *aDevice, const nsString &aName)
 
71
{
 
72
#ifdef MOZ_ENABLE_XFT
 
73
    // try to fall through to the core fonts if xft fails
 
74
    if (NS_IsXftEnabled()) {
 
75
        return nsFontMetricsXft::FamilyExists(aDevice, aName);
 
76
    }
 
77
#endif
 
78
 
 
79
#ifdef MOZ_ENABLE_COREXFONTS
 
80
    return nsFontMetricsGTK::FamilyExists(aDevice, aName);
 
81
#endif
 
82
}
 
83
 
 
84
#ifdef MOZ_ENABLE_XFT
 
85
 
 
86
PRBool
 
87
NS_IsXftEnabled(void)
 
88
{
 
89
    static PRBool been_here = PR_FALSE;
 
90
    static PRBool cachedXftSetting = PR_TRUE;
 
91
 
 
92
    if (!been_here) {
 
93
        been_here = PR_TRUE;
 
94
        nsCOMPtr<nsIPref> prefService;
 
95
        prefService = do_GetService(NS_PREF_CONTRACTID);
 
96
        if (!prefService)
 
97
            return PR_TRUE;
 
98
 
 
99
        nsresult rv;
 
100
 
 
101
        rv = prefService->GetBoolPref("fonts.xft.enabled", &cachedXftSetting);
 
102
 
 
103
        // Yes, this makes sense.  If xft is compiled in and there's no
 
104
        // pref, it's automatically enabled.  If there's no pref, check
 
105
        // the environment.
 
106
        if (NS_FAILED(rv)) {
 
107
            char *val = PR_GetEnv("GDK_USE_XFT");
 
108
 
 
109
            if (val && val[0] == '0') {
 
110
                cachedXftSetting = PR_FALSE;
 
111
                goto end;
 
112
            }
 
113
 
 
114
            cachedXftSetting = PR_TRUE;
 
115
        }
 
116
    }
 
117
 
 
118
 end:
 
119
 
 
120
    return cachedXftSetting;
 
121
}
 
122
 
 
123
#endif /* MOZ_ENABLE_XFT */