michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsThebesFontEnumerator.h" michael@0: #include // for uint32_t michael@0: #include "gfxPlatform.h" // for gfxPlatform michael@0: #include "mozilla/Assertions.h" // for MOZ_ASSERT_HELPER2 michael@0: #include "nsCOMPtr.h" // for nsCOMPtr michael@0: #include "nsDebug.h" // for NS_ENSURE_ARG_POINTER michael@0: #include "nsError.h" // for NS_OK, NS_FAILED, nsresult michael@0: #include "nsIAtom.h" // for nsIAtom, do_GetAtom michael@0: #include "nsID.h" michael@0: #include "nsMemory.h" // for nsMemory michael@0: #include "nsString.h" // for nsAutoCString, nsAutoString, etc michael@0: #include "nsTArray.h" // for nsTArray, nsTArray_Impl, etc michael@0: #include "nscore.h" // for char16_t, NS_IMETHODIMP michael@0: michael@0: NS_IMPL_ISUPPORTS(nsThebesFontEnumerator, nsIFontEnumerator) michael@0: michael@0: nsThebesFontEnumerator::nsThebesFontEnumerator() michael@0: { michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsThebesFontEnumerator::EnumerateAllFonts(uint32_t *aCount, michael@0: char16_t ***aResult) michael@0: { michael@0: return EnumerateFonts (nullptr, nullptr, aCount, aResult); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsThebesFontEnumerator::EnumerateFonts(const char *aLangGroup, michael@0: const char *aGeneric, michael@0: uint32_t *aCount, michael@0: char16_t ***aResult) michael@0: { michael@0: NS_ENSURE_ARG_POINTER(aCount); michael@0: NS_ENSURE_ARG_POINTER(aResult); michael@0: michael@0: nsTArray fontList; michael@0: michael@0: nsAutoCString generic; michael@0: if (aGeneric) michael@0: generic.Assign(aGeneric); michael@0: else michael@0: generic.SetIsVoid(true); michael@0: michael@0: nsCOMPtr langGroupAtom; michael@0: if (aLangGroup) { michael@0: nsAutoCString lowered; michael@0: lowered.Assign(aLangGroup); michael@0: ToLowerCase(lowered); michael@0: langGroupAtom = do_GetAtom(lowered); michael@0: } michael@0: michael@0: nsresult rv = gfxPlatform::GetPlatform()->GetFontList(langGroupAtom, generic, fontList); michael@0: michael@0: if (NS_FAILED(rv)) { michael@0: *aCount = 0; michael@0: *aResult = nullptr; michael@0: /* XXX in this case, do we want to return the CSS generics? */ michael@0: return NS_OK; michael@0: } michael@0: michael@0: char16_t **fs = static_cast michael@0: (nsMemory::Alloc(fontList.Length() * sizeof(char16_t*))); michael@0: for (uint32_t i = 0; i < fontList.Length(); i++) { michael@0: fs[i] = ToNewUnicode(fontList[i]); michael@0: } michael@0: michael@0: *aResult = fs; michael@0: *aCount = fontList.Length(); michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsThebesFontEnumerator::HaveFontFor(const char *aLangGroup, michael@0: bool *aResult) michael@0: { michael@0: NS_ENSURE_ARG_POINTER(aResult); michael@0: michael@0: *aResult = true; michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsThebesFontEnumerator::GetDefaultFont(const char *aLangGroup, michael@0: const char *aGeneric, michael@0: char16_t **aResult) michael@0: { michael@0: NS_ENSURE_ARG_POINTER(aResult); michael@0: *aResult = nullptr; michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsThebesFontEnumerator::UpdateFontList(bool *_retval) michael@0: { michael@0: gfxPlatform::GetPlatform()->UpdateFontList(); michael@0: *_retval = false; // always return false for now michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsThebesFontEnumerator::GetStandardFamilyName(const char16_t *aName, michael@0: char16_t **aResult) michael@0: { michael@0: NS_ENSURE_ARG_POINTER(aResult); michael@0: NS_ENSURE_ARG_POINTER(aName); michael@0: michael@0: nsAutoString name(aName); michael@0: if (name.IsEmpty()) { michael@0: *aResult = nullptr; michael@0: return NS_OK; michael@0: } michael@0: michael@0: nsAutoString family; michael@0: nsresult rv = gfxPlatform::GetPlatform()-> michael@0: GetStandardFamilyName(nsDependentString(aName), family); michael@0: if (NS_FAILED(rv) || family.IsEmpty()) { michael@0: *aResult = nullptr; michael@0: return NS_OK; michael@0: } michael@0: *aResult = ToNewUnicode(family); michael@0: return NS_OK; michael@0: }