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();
|
|
|
|
|
2010-06-25 16:43:10 +04:00
|
|
|
HFONT GetHFONT() { if (!mMetrics) Initialize(); return mFont; }
|
2010-03-15 12:34:25 +03:00
|
|
|
|
2014-11-17 12:59:50 +03:00
|
|
|
virtual gfxFloat GetAdjustedSize()
|
|
|
|
{
|
|
|
|
if (!mMetrics) {
|
|
|
|
Initialize();
|
|
|
|
}
|
|
|
|
return mAdjustedSize;
|
|
|
|
}
|
2010-03-15 12:34:25 +03: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 19:28:04 +03:00
|
|
|
virtual uint32_t GetSpaceGlyph() override;
|
2010-03-15 12:34:25 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool SetupCairoFont(gfxContext *aContext) override;
|
2010-03-15 12:34:25 +03:00
|
|
|
|
2011-06-22 12:49:53 +04:00
|
|
|
/* override Measure to add padding for antialiasing */
|
|
|
|
virtual RunMetrics Measure(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,
|
|
|
|
gfxContext *aContextForTightBoundingBox,
|
2014-10-16 12:40:19 +04:00
|
|
|
Spacing *aSpacing,
|
2015-03-21 19:28:04 +03:00
|
|
|
uint16_t 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" */
|
2014-11-17 12:59:50 +03:00
|
|
|
virtual 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 */
|
2014-05-31 11:12:40 +04:00
|
|
|
virtual bool ShapeText(gfxContext *aContext,
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t *aText,
|
2014-05-31 11:12:40 +04:00
|
|
|
uint32_t aOffset,
|
|
|
|
uint32_t aLength,
|
|
|
|
int32_t aScript,
|
2014-10-01 23:25:48 +04:00
|
|
|
bool aVertical,
|
2015-03-21 19:28:04 +03:00
|
|
|
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
|
|
|
|
2012-07-03 14:42:07 +04: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 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)
|
|
|
|
nsAutoPtr<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
|
2013-09-02 12:41:57 +04:00
|
|
|
nsAutoPtr<nsDataHashtable<nsUint32HashKey,int32_t> > mGlyphWidths;
|
2010-03-15 12:34:25 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* GFX_GDIFONT_H */
|