nsFontFaceList.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "nsFontFaceList.h"
  6. #include "nsFontFace.h"
  7. #include "nsFontFaceLoader.h"
  8. #include "nsIFrame.h"
  9. #include "gfxTextRun.h"
  10. #include "mozilla/gfx/2D.h"
  11. nsFontFaceList::nsFontFaceList()
  12. {
  13. }
  14. nsFontFaceList::~nsFontFaceList()
  15. {
  16. }
  17. ////////////////////////////////////////////////////////////////////////
  18. // nsISupports
  19. NS_IMPL_ISUPPORTS(nsFontFaceList, nsIDOMFontFaceList)
  20. ////////////////////////////////////////////////////////////////////////
  21. // nsIDOMFontFaceList
  22. NS_IMETHODIMP
  23. nsFontFaceList::Item(uint32_t index, nsIDOMFontFace **_retval)
  24. {
  25. NS_ENSURE_TRUE(index < mFontFaces.Count(), NS_ERROR_INVALID_ARG);
  26. uint32_t current = 0;
  27. nsIDOMFontFace* result = nullptr;
  28. for (auto iter = mFontFaces.Iter(); !iter.Done(); iter.Next()) {
  29. if (current == index) {
  30. result = iter.UserData();
  31. break;
  32. }
  33. current++;
  34. }
  35. NS_ASSERTION(result != nullptr, "null entry in nsFontFaceList?");
  36. NS_IF_ADDREF(*_retval = result);
  37. return NS_OK;
  38. }
  39. NS_IMETHODIMP
  40. nsFontFaceList::GetLength(uint32_t *aLength)
  41. {
  42. *aLength = mFontFaces.Count();
  43. return NS_OK;
  44. }
  45. ////////////////////////////////////////////////////////////////////////
  46. // nsFontFaceList
  47. nsresult
  48. nsFontFaceList::AddFontsFromTextRun(gfxTextRun* aTextRun,
  49. uint32_t aOffset, uint32_t aLength)
  50. {
  51. gfxTextRun::Range range(aOffset, aOffset + aLength);
  52. gfxTextRun::GlyphRunIterator iter(aTextRun, range);
  53. while (iter.NextRun()) {
  54. gfxFontEntry *fe = iter.GetGlyphRun()->mFont->GetFontEntry();
  55. // if we have already listed this face, just make sure the match type is
  56. // recorded
  57. nsFontFace* existingFace =
  58. static_cast<nsFontFace*>(mFontFaces.GetWeak(fe));
  59. if (existingFace) {
  60. existingFace->AddMatchType(iter.GetGlyphRun()->mMatchType);
  61. } else {
  62. // A new font entry we haven't seen before
  63. RefPtr<nsFontFace> ff =
  64. new nsFontFace(fe, aTextRun->GetFontGroup(),
  65. iter.GetGlyphRun()->mMatchType);
  66. mFontFaces.Put(fe, ff);
  67. }
  68. }
  69. return NS_OK;
  70. }