2018-11-30 19:52:05 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2012-05-21 11:12:37 +00: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 09:34:25 +00:00
|
|
|
|
|
|
|
#ifndef GFX_GDIFONT_H
|
|
|
|
#define GFX_GDIFONT_H
|
|
|
|
|
2013-06-23 12:03:39 +00:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2010-03-15 09:34:25 +00:00
|
|
|
#include "gfxFont.h"
|
|
|
|
#include "gfxGDIFontList.h"
|
|
|
|
|
2009-10-07 17:16:52 +00:00
|
|
|
#include "nsDataHashtable.h"
|
|
|
|
#include "nsHashKeys.h"
|
|
|
|
|
2010-03-15 09:34:25 +00:00
|
|
|
#include "cairo.h"
|
2014-06-09 15:43:16 +00:00
|
|
|
#include "usp10.h"
|
2010-03-15 09:34:25 +00:00
|
|
|
|
|
|
|
class gfxGDIFont : public gfxFont {
|
|
|
|
public:
|
|
|
|
gfxGDIFont(GDIFontEntry *aFontEntry, const gfxFontStyle *aFontStyle,
|
|
|
|
AntialiasOption anAAOption = kAntialiasDefault);
|
|
|
|
|
|
|
|
virtual ~gfxGDIFont();
|
|
|
|
|
2016-08-22 20:39:19 +00:00
|
|
|
HFONT GetHFONT() { return mFont; }
|
2010-03-15 09:34:25 +00:00
|
|
|
|
2017-08-07 20:20:40 +00:00
|
|
|
cairo_font_face_t *CairoFontFace() { return mFontFace; }
|
2010-03-15 09:34:25 +00:00
|
|
|
|
|
|
|
/* overrides for the pure virtual methods in gfxFont */
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual uint32_t GetSpaceGlyph() override;
|
2010-03-15 09:34:25 +00:00
|
|
|
|
2015-12-15 21:56:40 +00:00
|
|
|
virtual bool SetupCairoFont(DrawTarget *aDrawTarget) override;
|
2010-03-15 09:34:25 +00:00
|
|
|
|
2017-08-07 20:20:44 +00:00
|
|
|
virtual already_AddRefed<mozilla::gfx::ScaledFont> GetScaledFont(
|
|
|
|
DrawTarget *aTarget) override;
|
|
|
|
|
2011-06-22 08:49:53 +00:00
|
|
|
/* override Measure to add padding for antialiasing */
|
2016-06-27 16:41:55 +00:00
|
|
|
virtual RunMetrics Measure(
|
2012-08-22 15:56:38 +00:00
|
|
|
const gfxTextRun *aTextRun, uint32_t aStart, uint32_t aEnd,
|
2011-06-22 08:49:53 +00:00
|
|
|
BoundingBoxType aBoundingBoxType,
|
2015-12-15 21:56:41 +00:00
|
|
|
DrawTarget *aDrawTargetForTightBoundingBox, Spacing *aSpacing,
|
2017-05-04 21:27:05 +00:00
|
|
|
mozilla::gfx::ShapedTextFlags aOrientation) override;
|
2011-06-22 08:49:53 +00:00
|
|
|
|
2010-03-15 09:34:25 +00:00
|
|
|
/* required for MathML to suppress effects of ClearType "padding" */
|
2017-01-09 17:41:35 +00:00
|
|
|
mozilla::UniquePtr<gfxFont> CopyWithAntialiasOption(
|
2015-03-21 16:28:04 +00:00
|
|
|
AntialiasOption anAAOption) override;
|
2010-03-15 09:34:25 +00:00
|
|
|
|
2014-06-09 14:47:31 +00: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 16:28:04 +00:00
|
|
|
virtual bool ProvidesGetGlyph() const override {
|
2014-06-09 14:47:31 +00:00
|
|
|
return !mFontEntry->HasCmapTable();
|
|
|
|
}
|
|
|
|
|
2014-11-17 09:59:50 +00:00
|
|
|
virtual uint32_t GetGlyph(uint32_t aUnicode, uint32_t aVarSelector) override;
|
2014-06-09 14:47:31 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual bool ProvidesGlyphWidths() const override { return true; }
|
2011-01-07 12:38:28 +00:00
|
|
|
|
|
|
|
// get hinted glyph width in pixels as 16.16 fixed-point value
|
2018-12-31 11:43:27 +00:00
|
|
|
virtual int32_t GetGlyphWidth(uint16_t aGID) override;
|
2011-01-07 12:38:28 +00:00
|
|
|
|
2013-10-15 02:19:47 +00:00
|
|
|
virtual void AddSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf,
|
|
|
|
FontCacheSizes *aSizes) const;
|
|
|
|
virtual void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf,
|
|
|
|
FontCacheSizes *aSizes) const;
|
2012-03-23 12:14:16 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual FontType GetType() const override { return FONT_TYPE_GDI; }
|
2012-04-11 14:55:31 +00:00
|
|
|
|
2011-01-07 12:38:28 +00:00
|
|
|
protected:
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual const Metrics &GetHorizontalMetrics() override;
|
2014-09-30 06:37:40 +00:00
|
|
|
|
2014-06-09 14:47:31 +00:00
|
|
|
/* override to ensure the cairo font is set up properly */
|
2017-04-03 16:49:17 +00:00
|
|
|
bool ShapeText(DrawTarget *aDrawTarget, const char16_t *aText,
|
|
|
|
uint32_t aOffset, uint32_t aLength, Script aScript,
|
|
|
|
bool aVertical, RoundingFlags aRounding,
|
|
|
|
gfxShapedText *aShapedText) override;
|
2009-10-07 17:16:52 +00:00
|
|
|
|
2010-05-05 10:10:36 +00:00
|
|
|
void Initialize(); // creates metrics and Cairo fonts
|
2010-03-15 09:34:25 +00:00
|
|
|
|
2017-11-23 19:38:17 +00:00
|
|
|
// Fill the given LOGFONT record according to our size.
|
|
|
|
// (Synthetic italic is *not* handled here, because GDI may not reliably
|
|
|
|
// use the face we expect if we tweak the lfItalic field, and because we
|
|
|
|
// have generic support for this in gfxFont::Draw instead.)
|
|
|
|
void FillLogFont(LOGFONTW &aLogFont, gfxFloat aSize);
|
2010-03-15 09:34:25 +00:00
|
|
|
|
|
|
|
HFONT mFont;
|
|
|
|
cairo_font_face_t *mFontFace;
|
|
|
|
|
2010-05-05 10:10:36 +00:00
|
|
|
Metrics *mMetrics;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mSpaceGlyph;
|
2010-05-05 10:10:36 +00:00
|
|
|
|
2018-04-26 11:46:18 +00:00
|
|
|
bool mNeedsSyntheticBold;
|
2009-10-07 17:16:52 +00:00
|
|
|
|
2014-06-09 14:47:31 +00:00
|
|
|
// cache of glyph IDs (used for non-sfnt fonts only)
|
2016-04-15 19:45:37 +00:00
|
|
|
mozilla::UniquePtr<nsDataHashtable<nsUint32HashKey, uint32_t> > mGlyphIDs;
|
2014-06-09 15:43:16 +00:00
|
|
|
SCRIPT_CACHE mScriptCache;
|
2014-06-09 14:47:31 +00:00
|
|
|
|
2009-10-07 17:16:52 +00:00
|
|
|
// cache of glyph widths in 16.16 fixed-point pixels
|
2016-04-15 19:45:37 +00:00
|
|
|
mozilla::UniquePtr<nsDataHashtable<nsUint32HashKey, int32_t> > mGlyphWidths;
|
2010-03-15 09:34:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* GFX_GDIFONT_H */
|