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