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
15 * The Original Code is Mozilla Foundation code.
17 * The Initial Developer of the Original Code is Mozilla Foundation.
18 * Portions created by the Initial Developer are Copyright (C) 2006
19 * the Initial Developer. All Rights Reserved.
22 * Vladimir Vukicevic <vladimir@pobox.com>
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #ifndef GFX_TEXT_RUN_CACHE_H
39 #define GFX_TEXT_RUN_CACHE_H
44 * A simple textrun cache for textruns that do not carry state
45 * (e.g., actual or potential linebreaks) and do not need complex initialization.
46 * The lifetimes of these textruns are managed by the cache (they are auto-expired
47 * after a certain period of time).
49 class THEBES_API gfxTextRunCache
{
52 * Get a textrun for the given text, using a global cache. The textrun
53 * must be released via ReleaseTextRun, not deleted.
54 * Do not set any state in the textrun (e.g. actual or potential linebreaks).
55 * Flags IS_8BIT and IS_ASCII are automatically set appropriately.
56 * Flag IS_PERSISTENT must NOT be set unless aText is guaranteed to live
58 * The string can contain any characters, invalid ones will be stripped
61 static gfxTextRun
*MakeTextRun(const PRUnichar
*aText
, PRUint32 aLength
,
62 gfxFontGroup
*aFontGroup
,
63 gfxContext
*aRefContext
,
64 PRUint32 aAppUnitsPerDevUnit
,
68 * As above, but allows a full Parameters object to be passed in.
70 static gfxTextRun
*MakeTextRun(const PRUnichar
*aText
, PRUint32 aLength
,
71 gfxFontGroup
*aFontGroup
,
72 const gfxTextRunFactory::Parameters
* aParams
,
76 * Get a textrun for the given text, using a global cache. The textrun
77 * must be released via ReleaseTextRun, not deleted.
78 * Do not set any state in the textrun (e.g. actual or potential linebreaks).
79 * Flags IS_8BIT, IS_ASCII and HAS_SURROGATES are automatically set
81 * Flag IS_PERSISTENT must NOT be set unless aText is guaranteed to live
83 * The string can contain any characters, invalid ones will be stripped
86 static gfxTextRun
*MakeTextRun(const PRUint8
*aText
, PRUint32 aLength
,
87 gfxFontGroup
*aFontGroup
,
88 gfxContext
*aRefContext
,
89 PRUint32 aAppUnitsPerDevUnit
,
93 * Release a previously acquired textrun. Consider using AutoTextRun
94 * instead of calling this.
96 static void ReleaseTextRun(gfxTextRun
*aTextRun
);
100 AutoTextRun(gfxTextRun
*aTextRun
) : mTextRun(aTextRun
) {}
101 AutoTextRun() : mTextRun(nsnull
) {}
102 AutoTextRun
& operator=(gfxTextRun
*aTextRun
) {
103 gfxTextRunCache::ReleaseTextRun(mTextRun
);
108 gfxTextRunCache::ReleaseTextRun(mTextRun
);
110 gfxTextRun
*get() { return mTextRun
; }
111 gfxTextRun
*operator->() { return mTextRun
; }
113 gfxTextRun
*mTextRun
;
117 friend class gfxPlatform
;
119 static nsresult
Init();
120 static void Shutdown();
123 #endif /* GFX_TEXT_RUN_CACHE_H */