gfx/thebes/gfxFontTest.h

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:e534976f9485
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 #ifndef GFX_FONT_TEST_H
7 #define GFX_FONT_TEST_H
8
9 #include "nsString.h"
10 #include "nsTArray.h"
11
12 #include "cairo/cairo.h"
13
14 struct gfxFontTestItem {
15 gfxFontTestItem(const nsCString& fontName,
16 cairo_glyph_t *cglyphs, int nglyphs)
17 : platformFont(fontName)
18 {
19 glyphs = new cairo_glyph_t[nglyphs];
20 memcpy (glyphs, cglyphs, sizeof(cairo_glyph_t) * nglyphs);
21 num_glyphs = nglyphs;
22 }
23
24 gfxFontTestItem(const gfxFontTestItem& other) {
25 platformFont = other.platformFont;
26 num_glyphs = other.num_glyphs;
27 glyphs = new cairo_glyph_t[num_glyphs];
28 memcpy (glyphs, other.glyphs, sizeof(cairo_glyph_t) * num_glyphs);
29 }
30
31 ~gfxFontTestItem() {
32 delete [] glyphs;
33 }
34
35 nsCString platformFont;
36 cairo_glyph_t *glyphs;
37 int num_glyphs;
38 };
39
40
41 class gfxFontTestStore {
42 public:
43 gfxFontTestStore() { }
44
45 void AddItem (const nsCString& fontString,
46 cairo_glyph_t *cglyphs, int nglyphs)
47 {
48 items.AppendElement(gfxFontTestItem(fontString, cglyphs, nglyphs));
49 }
50
51 void AddItem (const nsString& fontString,
52 cairo_glyph_t *cglyphs, int nglyphs)
53 {
54 items.AppendElement(gfxFontTestItem(NS_ConvertUTF16toUTF8(fontString), cglyphs, nglyphs));
55 }
56
57 nsTArray<gfxFontTestItem> items;
58
59 public:
60 static gfxFontTestStore *CurrentStore() {
61 return sCurrentStore;
62 }
63
64 static gfxFontTestStore *NewStore() {
65 if (sCurrentStore)
66 delete sCurrentStore;
67
68 sCurrentStore = new gfxFontTestStore;
69 return sCurrentStore;
70 }
71
72 static void DeleteStore() {
73 if (sCurrentStore)
74 delete sCurrentStore;
75
76 sCurrentStore = nullptr;
77 }
78
79 protected:
80 static gfxFontTestStore *sCurrentStore;
81 };
82
83
84 #endif /* GFX_FONT_TEST_H */

mercurial