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