- add sources.
[platform/framework/web/crosswalk.git] / src / content / browser / renderer_host / pepper / pepper_truetype_font_list_linux.cc
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/renderer_host/pepper/pepper_truetype_font_list.h"
6
7 #include <pango/pango.h>
8 #include <pango/pangocairo.h>
9
10 #include <string>
11
12 #include "ppapi/proxy/serialized_structs.h"
13
14 namespace content {
15
16 void GetFontFamilies_SlowBlocking(std::vector<std::string>* font_families) {
17   PangoFontMap* font_map = ::pango_cairo_font_map_get_default();
18   PangoFontFamily** families = NULL;
19   int num_families = 0;
20   ::pango_font_map_list_families(font_map, &families, &num_families);
21
22   for (int i = 0; i < num_families; ++i)
23     font_families->push_back(::pango_font_family_get_name(families[i]));
24   g_free(families);
25 }
26
27 void GetFontsInFamily_SlowBlocking(
28     const std::string& family,
29     std::vector<ppapi::proxy::SerializedTrueTypeFontDesc>* fonts_in_family) {
30   PangoFontMap* font_map = ::pango_cairo_font_map_get_default();
31   PangoFontFamily** font_families = NULL;
32   int num_families = 0;
33   ::pango_font_map_list_families(font_map, &font_families, &num_families);
34
35   for (int i = 0; i < num_families; ++i) {
36     PangoFontFamily* font_family = font_families[i];
37     if (family.compare(::pango_font_family_get_name(font_family)) == 0) {
38       PangoFontFace** font_faces = NULL;
39       int num_faces = 0;
40       ::pango_font_family_list_faces(font_family, &font_faces, &num_faces);
41
42       for (int j = 0; j < num_faces; ++j) {
43         PangoFontFace* font_face = font_faces[j];
44         PangoFontDescription* font_desc = ::pango_font_face_describe(font_face);
45         ppapi::proxy::SerializedTrueTypeFontDesc desc;
46         desc.family = family;
47         if (::pango_font_description_get_style(font_desc) == PANGO_STYLE_ITALIC)
48           desc.style = PP_TRUETYPEFONTSTYLE_ITALIC;
49         desc.weight = static_cast<PP_TrueTypeFontWeight_Dev>(
50             ::pango_font_description_get_weight(font_desc));
51         desc.width = static_cast<PP_TrueTypeFontWidth_Dev>(
52             ::pango_font_description_get_stretch(font_desc));
53         // Character set is not part of Pango font description.
54         desc.charset = PP_TRUETYPEFONTCHARSET_DEFAULT;
55
56         fonts_in_family->push_back(desc);
57         ::pango_font_description_free(font_desc);
58       }
59       g_free(font_faces);
60     }
61   }
62   g_free(font_families);
63 }
64
65 }  // namespace content