gfx/thebes/gfxFontTest.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/thebes/gfxFontTest.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,84 @@
     1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef GFX_FONT_TEST_H
    1.10 +#define GFX_FONT_TEST_H
    1.11 +
    1.12 +#include "nsString.h"
    1.13 +#include "nsTArray.h"
    1.14 +
    1.15 +#include "cairo/cairo.h"
    1.16 +
    1.17 +struct gfxFontTestItem {
    1.18 +    gfxFontTestItem(const nsCString& fontName,
    1.19 +                    cairo_glyph_t *cglyphs, int nglyphs)
    1.20 +        : platformFont(fontName)
    1.21 +    {
    1.22 +        glyphs = new cairo_glyph_t[nglyphs];
    1.23 +        memcpy (glyphs, cglyphs, sizeof(cairo_glyph_t) * nglyphs);
    1.24 +        num_glyphs = nglyphs;
    1.25 +    }
    1.26 +
    1.27 +    gfxFontTestItem(const gfxFontTestItem& other) {
    1.28 +        platformFont = other.platformFont;
    1.29 +        num_glyphs = other.num_glyphs;
    1.30 +        glyphs = new cairo_glyph_t[num_glyphs];
    1.31 +        memcpy (glyphs, other.glyphs, sizeof(cairo_glyph_t) * num_glyphs);
    1.32 +    }
    1.33 +
    1.34 +    ~gfxFontTestItem() {
    1.35 +        delete [] glyphs;
    1.36 +    }
    1.37 +
    1.38 +    nsCString platformFont;
    1.39 +    cairo_glyph_t *glyphs;
    1.40 +    int num_glyphs;
    1.41 +};
    1.42 +
    1.43 +
    1.44 +class gfxFontTestStore {
    1.45 +public:
    1.46 +    gfxFontTestStore() { }
    1.47 +
    1.48 +    void AddItem (const nsCString& fontString,
    1.49 +                  cairo_glyph_t *cglyphs, int nglyphs)
    1.50 +    {
    1.51 +        items.AppendElement(gfxFontTestItem(fontString, cglyphs, nglyphs));
    1.52 +    }
    1.53 +
    1.54 +    void AddItem (const nsString& fontString,
    1.55 +                  cairo_glyph_t *cglyphs, int nglyphs)
    1.56 +    {
    1.57 +        items.AppendElement(gfxFontTestItem(NS_ConvertUTF16toUTF8(fontString), cglyphs, nglyphs));
    1.58 +    }
    1.59 +
    1.60 +    nsTArray<gfxFontTestItem> items;
    1.61 +
    1.62 +public:
    1.63 +    static gfxFontTestStore *CurrentStore() {
    1.64 +        return sCurrentStore;
    1.65 +    }
    1.66 +
    1.67 +    static gfxFontTestStore *NewStore() {
    1.68 +        if (sCurrentStore)
    1.69 +            delete sCurrentStore;
    1.70 +
    1.71 +        sCurrentStore = new gfxFontTestStore;
    1.72 +        return sCurrentStore;
    1.73 +    }
    1.74 +
    1.75 +    static void DeleteStore() {
    1.76 +        if (sCurrentStore)
    1.77 +            delete sCurrentStore;
    1.78 +
    1.79 +        sCurrentStore = nullptr;
    1.80 +    }
    1.81 +
    1.82 +protected:
    1.83 +    static gfxFontTestStore *sCurrentStore;
    1.84 +};
    1.85 +
    1.86 +
    1.87 +#endif /* GFX_FONT_TEST_H */

mercurial