2010-03-15 02:34:25 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2012-05-21 04:12:37 -07:00
|
|
|
* 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 http://mozilla.org/MPL/2.0/. */
|
2010-03-15 02:34:25 -07:00
|
|
|
|
|
|
|
#ifndef GFX_GDIFONT_H
|
|
|
|
#define GFX_GDIFONT_H
|
|
|
|
|
2013-06-23 05:03:39 -07:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2010-03-15 02:34:25 -07:00
|
|
|
#include "gfxFont.h"
|
|
|
|
#include "gfxGDIFontList.h"
|
|
|
|
|
2009-10-07 10:16:52 -07:00
|
|
|
#include "nsDataHashtable.h"
|
|
|
|
#include "nsHashKeys.h"
|
|
|
|
|
2010-03-15 02:34:25 -07:00
|
|
|
#include "cairo.h"
|
2014-06-09 08:43:16 -07:00
|
|
|
#include "usp10.h"
|
2010-03-15 02:34:25 -07:00
|
|
|
|
|
|
|
class gfxGDIFont : public gfxFont
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
gfxGDIFont(GDIFontEntry *aFontEntry,
|
|
|
|
const gfxFontStyle *aFontStyle,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aNeedsBold,
|
2010-03-15 02:34:25 -07:00
|
|
|
AntialiasOption anAAOption = kAntialiasDefault);
|
|
|
|
|
|
|
|
virtual ~gfxGDIFont();
|
|
|
|
|
2010-06-25 05:43:10 -07:00
|
|
|
HFONT GetHFONT() { if (!mMetrics) Initialize(); return mFont; }
|
2010-03-15 02:34:25 -07:00
|
|
|
|
2014-11-17 01:59:50 -08:00
|
|
|
virtual gfxFloat GetAdjustedSize()
|
|
|
|
{
|
|
|
|
if (!mMetrics) {
|
|
|
|
Initialize();
|
|
|
|
}
|
|
|
|
return mAdjustedSize;
|
|
|
|
}
|
2010-03-15 02:34:25 -07:00
|
|
|
|
|
|
|
cairo_font_face_t *CairoFontFace() { return mFontFace; }
|
|
|
|
cairo_scaled_font_t *CairoScaledFont() { return mScaledFont; }
|
|
|
|
|
|
|
|
/* overrides for the pure virtual methods in gfxFont */
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual uint32_t GetSpaceGlyph() override;
|
2010-03-15 02:34:25 -07:00
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual bool SetupCairoFont(gfxContext *aContext) override;
|
2010-03-15 02:34:25 -07:00
|
|
|
|
2011-06-22 01:49:53 -07:00
|
|
|
/* override Measure to add padding for antialiasing */
|
|
|
|
virtual RunMetrics Measure(gfxTextRun *aTextRun,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aStart, uint32_t aEnd,
|
2011-06-22 01:49:53 -07:00
|
|
|
BoundingBoxType aBoundingBoxType,
|
|
|
|
gfxContext *aContextForTightBoundingBox,
|
2014-10-16 01:40:19 -07:00
|
|
|
Spacing *aSpacing,
|
2015-03-21 09:28:04 -07:00
|
|
|
uint16_t aOrientation) override;
|
2011-06-22 01:49:53 -07:00
|
|
|
|
2010-03-15 02:34:25 -07:00
|
|
|
/* required for MathML to suppress effects of ClearType "padding" */
|
2014-11-17 01:59:50 -08:00
|
|
|
virtual gfxFont*
|
2015-03-21 09:28:04 -07:00
|
|
|
CopyWithAntialiasOption(AntialiasOption anAAOption) override;
|
2010-03-15 02:34:25 -07:00
|
|
|
|
2014-06-09 07:47:31 -07:00
|
|
|
// If the font has a cmap table, we handle it purely with harfbuzz;
|
|
|
|
// but if not (e.g. .fon fonts), we'll use a GDI callback to get glyphs.
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual bool ProvidesGetGlyph() const override {
|
2014-06-09 07:47:31 -07:00
|
|
|
return !mFontEntry->HasCmapTable();
|
|
|
|
}
|
|
|
|
|
2014-11-17 01:59:50 -08:00
|
|
|
virtual uint32_t GetGlyph(uint32_t aUnicode,
|
2015-03-21 09:28:04 -07:00
|
|
|
uint32_t aVarSelector) override;
|
2014-06-09 07:47:31 -07:00
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual bool ProvidesGlyphWidths() const override { return true; }
|
2011-01-07 04:38:28 -08:00
|
|
|
|
|
|
|
// get hinted glyph width in pixels as 16.16 fixed-point value
|
2014-11-17 01:59:50 -08:00
|
|
|
virtual int32_t GetGlyphWidth(DrawTarget& aDrawTarget,
|
2015-03-21 09:28:04 -07:00
|
|
|
uint16_t aGID) override;
|
2011-01-07 04:38:28 -08:00
|
|
|
|
2013-10-14 19:19:47 -07:00
|
|
|
virtual void AddSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf,
|
|
|
|
FontCacheSizes* aSizes) const;
|
|
|
|
virtual void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf,
|
|
|
|
FontCacheSizes* aSizes) const;
|
2012-03-23 05:14:16 -07:00
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual FontType GetType() const override { return FONT_TYPE_GDI; }
|
2012-04-11 07:55:31 -07:00
|
|
|
|
2011-01-07 04:38:28 -08:00
|
|
|
protected:
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual const Metrics& GetHorizontalMetrics() override;
|
2014-09-29 23:37:40 -07:00
|
|
|
|
2014-06-09 07:47:31 -07:00
|
|
|
/* override to ensure the cairo font is set up properly */
|
2014-05-31 00:12:40 -07:00
|
|
|
virtual bool ShapeText(gfxContext *aContext,
|
2014-01-04 07:02:17 -08:00
|
|
|
const char16_t *aText,
|
2014-05-31 00:12:40 -07:00
|
|
|
uint32_t aOffset,
|
|
|
|
uint32_t aLength,
|
|
|
|
int32_t aScript,
|
2014-10-01 12:25:48 -07:00
|
|
|
bool aVertical,
|
2015-03-21 09:28:04 -07:00
|
|
|
gfxShapedText *aShapedText) override;
|
2009-10-07 10:16:52 -07:00
|
|
|
|
2010-05-05 03:10:36 -07:00
|
|
|
void Initialize(); // creates metrics and Cairo fonts
|
2010-03-15 02:34:25 -07:00
|
|
|
|
2012-07-03 03:42:07 -07:00
|
|
|
// Fill the given LOGFONT record according to our style, but don't adjust
|
|
|
|
// the lfItalic field if we're going to use a cairo transform for fake
|
|
|
|
// italics.
|
|
|
|
void FillLogFont(LOGFONTW& aLogFont, gfxFloat aSize, bool aUseGDIFakeItalic);
|
2010-03-15 02:34:25 -07:00
|
|
|
|
|
|
|
HFONT mFont;
|
|
|
|
cairo_font_face_t *mFontFace;
|
|
|
|
|
2010-05-05 03:10:36 -07:00
|
|
|
Metrics *mMetrics;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mSpaceGlyph;
|
2010-05-05 03:10:36 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mNeedsBold;
|
2009-10-07 10:16:52 -07:00
|
|
|
|
2014-06-09 07:47:31 -07:00
|
|
|
// cache of glyph IDs (used for non-sfnt fonts only)
|
|
|
|
nsAutoPtr<nsDataHashtable<nsUint32HashKey,uint32_t> > mGlyphIDs;
|
2014-06-09 08:43:16 -07:00
|
|
|
SCRIPT_CACHE mScriptCache;
|
2014-06-09 07:47:31 -07:00
|
|
|
|
2009-10-07 10:16:52 -07:00
|
|
|
// cache of glyph widths in 16.16 fixed-point pixels
|
2013-09-02 01:41:57 -07:00
|
|
|
nsAutoPtr<nsDataHashtable<nsUint32HashKey,int32_t> > mGlyphWidths;
|
2010-03-15 02:34:25 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* GFX_GDIFONT_H */
|