Commit e3790aec authored by Jonathan Kew's avatar Jonathan Kew
Browse files

Bug 1356399 - Try to catch DWrite font access exceptions within GetGlyphBounds. r=lsalzman

parent 95e54931
Loading
Loading
Loading
Loading
+29 −15
Original line number Diff line number Diff line
@@ -752,7 +752,8 @@ gfxFloat gfxDWriteFont::MeasureGlyphWidth(uint16_t aGlyph) {
}

bool gfxDWriteFont::GetGlyphBounds(uint16_t aGID, gfxRect* aBounds,
                                   bool aTight) const {
                                   bool aTight) {
  MOZ_SEH_TRY {
    DWRITE_GLYPH_METRICS m;
    HRESULT hr = mFontFace->GetDesignGlyphMetrics(&aGID, 1, &m, FALSE);
    if (FAILED(hr)) {
@@ -770,6 +771,19 @@ bool gfxDWriteFont::GetGlyphBounds(uint16_t aGID, gfxRect* aBounds,
    *aBounds = bounds;
    return true;
  }
  MOZ_SEH_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
    // Exception (e.g. disk i/o error) occurred when DirectWrite tried to use
    // the font resource; possibly a failing drive or similar hardware issue.
    // Mark the font as invalid, and wipe the fontEntry's charmap so that font
    // selection will skip it; we'll use a fallback font instead.
    mIsValid = false;
    GetFontEntry()->mCharacterMap = new gfxCharacterMap();
    GetFontEntry()->mShmemCharacterMap = nullptr;
    gfxCriticalError() << "Exception occurred measuring glyph bounds for "
                       << GetFontEntry()->Name().get();
  }
  return false;
}

void gfxDWriteFont::AddSizeOfExcludingThis(MallocSizeOf aMallocSizeOf,
                                           FontCacheSizes* aSizes) const {
+1 −2
Original line number Diff line number Diff line
@@ -57,8 +57,7 @@ class gfxDWriteFont final : public gfxFont {

  int32_t GetGlyphWidth(uint16_t aGID) override;

  bool GetGlyphBounds(uint16_t aGID, gfxRect* aBounds,
                      bool aTight) const override;
  bool GetGlyphBounds(uint16_t aGID, gfxRect* aBounds, bool aTight) override;

  void AddSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf,
                              FontCacheSizes* aSizes) const override;
+1 −1
Original line number Diff line number Diff line
@@ -761,7 +761,7 @@ const gfxFT2FontBase::GlyphMetrics& gfxFT2FontBase::GetCachedGlyphMetrics(
}

bool gfxFT2FontBase::GetGlyphBounds(uint16_t aGID, gfxRect* aBounds,
                                    bool aTight) const {
                                    bool aTight) {
  IntRect bounds;
  const GlyphMetrics& metrics = GetCachedGlyphMetrics(aGID, &bounds);
  if (!metrics.HasValidBounds()) {
+1 −2
Original line number Diff line number Diff line
@@ -60,8 +60,7 @@ class gfxFT2FontBase : public gfxFont {
    return GetCachedGlyphMetrics(aGID).mAdvance;
  }

  bool GetGlyphBounds(uint16_t aGID, gfxRect* aBounds,
                      bool aTight) const override;
  bool GetGlyphBounds(uint16_t aGID, gfxRect* aBounds, bool aTight) override;

  FontType GetType() const override { return FONT_TYPE_FT2; }

+1 −1
Original line number Diff line number Diff line
@@ -1989,7 +1989,7 @@ class gfxFont {
  virtual int32_t GetGlyphWidth(uint16_t aGID) { return -1; }

  virtual bool GetGlyphBounds(uint16_t aGID, gfxRect* aBounds,
                              bool aTight = false) const {
                              bool aTight = false) {
    return false;
  }

Loading