gfx/thebes/gfxFontTest.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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/. */
     6 #ifndef GFX_FONT_TEST_H
     7 #define GFX_FONT_TEST_H
     9 #include "nsString.h"
    10 #include "nsTArray.h"
    12 #include "cairo/cairo.h"
    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     }
    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     }
    31     ~gfxFontTestItem() {
    32         delete [] glyphs;
    33     }
    35     nsCString platformFont;
    36     cairo_glyph_t *glyphs;
    37     int num_glyphs;
    38 };
    41 class gfxFontTestStore {
    42 public:
    43     gfxFontTestStore() { }
    45     void AddItem (const nsCString& fontString,
    46                   cairo_glyph_t *cglyphs, int nglyphs)
    47     {
    48         items.AppendElement(gfxFontTestItem(fontString, cglyphs, nglyphs));
    49     }
    51     void AddItem (const nsString& fontString,
    52                   cairo_glyph_t *cglyphs, int nglyphs)
    53     {
    54         items.AppendElement(gfxFontTestItem(NS_ConvertUTF16toUTF8(fontString), cglyphs, nglyphs));
    55     }
    57     nsTArray<gfxFontTestItem> items;
    59 public:
    60     static gfxFontTestStore *CurrentStore() {
    61         return sCurrentStore;
    62     }
    64     static gfxFontTestStore *NewStore() {
    65         if (sCurrentStore)
    66             delete sCurrentStore;
    68         sCurrentStore = new gfxFontTestStore;
    69         return sCurrentStore;
    70     }
    72     static void DeleteStore() {
    73         if (sCurrentStore)
    74             delete sCurrentStore;
    76         sCurrentStore = nullptr;
    77     }
    79 protected:
    80     static gfxFontTestStore *sCurrentStore;
    81 };
    84 #endif /* GFX_FONT_TEST_H */

mercurial