gfx/src/nsThebesFontEnumerator.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/src/nsThebesFontEnumerator.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,129 @@
     1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "nsThebesFontEnumerator.h"
    1.10 +#include <stdint.h>                     // for uint32_t
    1.11 +#include "gfxPlatform.h"                // for gfxPlatform
    1.12 +#include "mozilla/Assertions.h"         // for MOZ_ASSERT_HELPER2
    1.13 +#include "nsCOMPtr.h"                   // for nsCOMPtr
    1.14 +#include "nsDebug.h"                    // for NS_ENSURE_ARG_POINTER
    1.15 +#include "nsError.h"                    // for NS_OK, NS_FAILED, nsresult
    1.16 +#include "nsIAtom.h"                    // for nsIAtom, do_GetAtom
    1.17 +#include "nsID.h"
    1.18 +#include "nsMemory.h"                   // for nsMemory
    1.19 +#include "nsString.h"               // for nsAutoCString, nsAutoString, etc
    1.20 +#include "nsTArray.h"                   // for nsTArray, nsTArray_Impl, etc
    1.21 +#include "nscore.h"                     // for char16_t, NS_IMETHODIMP
    1.22 +
    1.23 +NS_IMPL_ISUPPORTS(nsThebesFontEnumerator, nsIFontEnumerator)
    1.24 +
    1.25 +nsThebesFontEnumerator::nsThebesFontEnumerator()
    1.26 +{
    1.27 +}
    1.28 +
    1.29 +NS_IMETHODIMP
    1.30 +nsThebesFontEnumerator::EnumerateAllFonts(uint32_t *aCount,
    1.31 +                                          char16_t ***aResult)
    1.32 +{
    1.33 +    return EnumerateFonts (nullptr, nullptr, aCount, aResult);
    1.34 +}
    1.35 +
    1.36 +NS_IMETHODIMP
    1.37 +nsThebesFontEnumerator::EnumerateFonts(const char *aLangGroup,
    1.38 +                                       const char *aGeneric,
    1.39 +                                       uint32_t *aCount,
    1.40 +                                       char16_t ***aResult)
    1.41 +{
    1.42 +    NS_ENSURE_ARG_POINTER(aCount);
    1.43 +    NS_ENSURE_ARG_POINTER(aResult);
    1.44 +
    1.45 +    nsTArray<nsString> fontList;
    1.46 +
    1.47 +    nsAutoCString generic;
    1.48 +    if (aGeneric)
    1.49 +        generic.Assign(aGeneric);
    1.50 +    else
    1.51 +        generic.SetIsVoid(true);
    1.52 +
    1.53 +    nsCOMPtr<nsIAtom> langGroupAtom;
    1.54 +    if (aLangGroup) {
    1.55 +        nsAutoCString lowered;
    1.56 +        lowered.Assign(aLangGroup);
    1.57 +        ToLowerCase(lowered);
    1.58 +        langGroupAtom = do_GetAtom(lowered);
    1.59 +    }
    1.60 +
    1.61 +    nsresult rv = gfxPlatform::GetPlatform()->GetFontList(langGroupAtom, generic, fontList);
    1.62 +
    1.63 +    if (NS_FAILED(rv)) {
    1.64 +        *aCount = 0;
    1.65 +        *aResult = nullptr;
    1.66 +        /* XXX in this case, do we want to return the CSS generics? */
    1.67 +        return NS_OK;
    1.68 +    }
    1.69 +
    1.70 +    char16_t **fs = static_cast<char16_t **>
    1.71 +                                (nsMemory::Alloc(fontList.Length() * sizeof(char16_t*)));
    1.72 +    for (uint32_t i = 0; i < fontList.Length(); i++) {
    1.73 +        fs[i] = ToNewUnicode(fontList[i]);
    1.74 +    }
    1.75 +
    1.76 +    *aResult = fs;
    1.77 +    *aCount = fontList.Length();
    1.78 +
    1.79 +    return NS_OK;
    1.80 +}
    1.81 +
    1.82 +NS_IMETHODIMP
    1.83 +nsThebesFontEnumerator::HaveFontFor(const char *aLangGroup,
    1.84 +                                    bool *aResult)
    1.85 +{
    1.86 +    NS_ENSURE_ARG_POINTER(aResult);
    1.87 +
    1.88 +    *aResult = true;
    1.89 +    return NS_OK;
    1.90 +}
    1.91 +
    1.92 +NS_IMETHODIMP
    1.93 +nsThebesFontEnumerator::GetDefaultFont(const char *aLangGroup,
    1.94 +                                       const char *aGeneric,
    1.95 +                                       char16_t **aResult)
    1.96 +{
    1.97 +    NS_ENSURE_ARG_POINTER(aResult);
    1.98 +    *aResult = nullptr;
    1.99 +    return NS_OK;
   1.100 +}
   1.101 +
   1.102 +NS_IMETHODIMP
   1.103 +nsThebesFontEnumerator::UpdateFontList(bool *_retval)
   1.104 +{
   1.105 +    gfxPlatform::GetPlatform()->UpdateFontList();
   1.106 +    *_retval = false; // always return false for now
   1.107 +    return NS_OK;
   1.108 +}
   1.109 +
   1.110 +NS_IMETHODIMP
   1.111 +nsThebesFontEnumerator::GetStandardFamilyName(const char16_t *aName,
   1.112 +                                              char16_t **aResult)
   1.113 +{
   1.114 +    NS_ENSURE_ARG_POINTER(aResult);
   1.115 +    NS_ENSURE_ARG_POINTER(aName);
   1.116 +
   1.117 +    nsAutoString name(aName);
   1.118 +    if (name.IsEmpty()) {
   1.119 +        *aResult = nullptr;
   1.120 +        return NS_OK;
   1.121 +    }
   1.122 +
   1.123 +    nsAutoString family;
   1.124 +    nsresult rv = gfxPlatform::GetPlatform()->
   1.125 +        GetStandardFamilyName(nsDependentString(aName), family);
   1.126 +    if (NS_FAILED(rv) || family.IsEmpty()) {
   1.127 +        *aResult = nullptr;
   1.128 +        return NS_OK;
   1.129 +    }
   1.130 +    *aResult = ToNewUnicode(family);
   1.131 +    return NS_OK;
   1.132 +}

mercurial