author Gregory Szorc <>
Tue, 24 Sep 2013 15:05:43 -0700
changeset 162321 b51710e0e485a5c4edccd438ddb2a46bd7f0e91f
parent 144845 8fed67bc814d173ddba7083a1a6e6669456b7a2e
child 178109 5a9badd6db004310b9d1aca5db25ef4c275a4362
permissions -rw-r--r--
Bug 901990 - Part 3: Don't purge _tests during PGO builds; r=glandium CLOSED TREE

/* vim: set sw=4 sts=4 et cin: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at */

#ifndef GFX_OS2_FONTS_H
#define GFX_OS2_FONTS_H

#include "gfxTypes.h"
#include "gfxFont.h"
#include "gfxMatrix.h"
#include "nsDataHashtable.h"

#define INCL_GPI
#include <os2.h>
#include <cairo-os2.h>
#include "cairo-ft.h" // includes fontconfig.h, too
#include <freetype/tttables.h>

#include "nsICharsetConverterManager.h"

class gfxOS2FontEntry : public gfxFontEntry {
    gfxOS2FontEntry(const nsAString& aName) : gfxFontEntry(aName) {}
    ~gfxOS2FontEntry() {}

class gfxOS2Font : public gfxFont {
    gfxOS2Font(gfxOS2FontEntry *aFontEntry, const gfxFontStyle *aFontStyle);
    virtual ~gfxOS2Font();

    virtual const gfxFont::Metrics& GetMetrics();
    cairo_font_face_t *CairoFontFace();
    cairo_scaled_font_t *CairoScaledFont();

    // Get the glyphID of a space
    virtual uint32_t GetSpaceGlyph() {
        if (!mMetrics)
        return mSpaceGlyph;

    static already_AddRefed<gfxOS2Font> GetOrMakeFont(const nsAString& aName,
                                                      const gfxFontStyle *aStyle);

    virtual bool SetupCairoFont(gfxContext *aContext);

    virtual FontType GetType() const { return FONT_TYPE_OS2; }

    cairo_font_face_t *mFontFace;
    Metrics *mMetrics;
    gfxFloat mAdjustedSize;
    uint32_t mSpaceGlyph;
    int mHinting;
    bool mAntialias;

class gfxOS2FontGroup : public gfxFontGroup {
    gfxOS2FontGroup(const nsAString& aFamilies, const gfxFontStyle* aStyle, gfxUserFontSet *aUserFontSet);
    virtual ~gfxOS2FontGroup();

    virtual gfxFontGroup *Copy(const gfxFontStyle *aStyle);

    // create and initialize the textRun using FreeType font
    virtual gfxTextRun *MakeTextRun(const PRUnichar* aString, uint32_t aLength,
                                    const Parameters* aParams, uint32_t aFlags);
    virtual gfxTextRun *MakeTextRun(const uint8_t* aString, uint32_t aLength,
                                    const Parameters* aParams, uint32_t aFlags);

    gfxOS2Font *GetFontAt(int32_t i) {
        // If it turns out to be hard for all clients that cache font
        // groups to call UpdateFontList at appropriate times, we could
        // instead consider just calling UpdateFontList from someplace
        // more central (such as here).
        NS_ASSERTION(!mUserFontSet || mCurrGeneration == GetGeneration(),
                     "Whoever was caching this font group should have "
                     "called UpdateFontList on it");

#ifdef DEBUG_thebes_2
        printf("gfxOS2FontGroup[%#x]::GetFontAt(%d), %#x, %#x\n",
               (unsigned)this, i, (unsigned)&mFonts, (unsigned)&mFonts[i]);
        return static_cast<gfxOS2Font*>(static_cast<gfxFont*>(mFonts[i]));

    void InitTextRun(gfxTextRun *aTextRun, const uint8_t *aUTF8Text,
                     uint32_t aUTF8Length, uint32_t aUTF8HeaderLength);
    void CreateGlyphRunsFT(gfxTextRun *aTextRun, const uint8_t *aUTF8,
                           uint32_t aUTF8Length);
    static bool FontCallback(const nsAString& aFontName,
                               const nsACString& aGenericName,
                               bool aUseFontSet,
                               void *aClosure);

    bool mEnableKerning;

#endif /* GFX_OS2_FONTS_H */