Add ICU message format support
[chromium-blink-merge.git] / content / common / mac / font_loader.h
blob2f9f8982a5b414c688090e75ffa2155020136bbc
1 // Copyright (c) 2012 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.
5 #ifndef CONTENT_COMMON_MAC_FONT_LOADER_H_
6 #define CONTENT_COMMON_MAC_FONT_LOADER_H_
8 #include <ApplicationServices/ApplicationServices.h>
10 #include "base/memory/shared_memory.h"
11 #include "content/common/content_export.h"
13 #ifdef __OBJC__
14 @class NSFont;
15 #else
16 class NSFont;
17 #endif
19 struct FontDescriptor;
21 // Provides functionality to transmit fonts over IPC.
23 // Note about font formats: .dfont (datafork suitcase) fonts are currently not
24 // supported by this code since CGFontCreateWithDataProvider() can't handle them
25 // directly.
27 class FontLoader {
28 public:
29 // This structure holds the result of LoadFont(). This structure is passed to
30 // LoadFont(), which should run on the file thread, then it is passed to a
31 // task which sends the result to the originating renderer.
32 struct Result {
33 uint32 font_data_size;
34 base::SharedMemory font_data;
35 uint32 font_id;
37 // Load a font specified by |font| into a shared memory buffer suitable for
38 // sending over IPC.
40 // On return:
41 // |result->font_data| - shared memory buffer containing the raw data for
42 // the font file. The buffer is only valid when both |result->font_data_size|
43 // and |result->font_id| are not zero.
44 // |result->font_data_size| - size of data contained in |result->font_data|.
45 // This value is zero on failure.
46 // |result->font_id| - unique identifier for the on-disk file we load for
47 // the font. This value is zero on failure.
48 CONTENT_EXPORT
49 static void LoadFont(const FontDescriptor& font, FontLoader::Result* result);
51 // Given a shared memory buffer containing the raw data for a font file, load
52 // the font and return a CGFontRef.
54 // |data| - A shared memory handle pointing to the raw data from a font file.
55 // |data_size| - Size of |data|.
57 // On return:
58 // returns true on success, false on failure.
59 // |out| - A CGFontRef corresponding to the designated font.
60 // The caller is responsible for releasing this value via CGFontRelease()
61 // when done.
62 CONTENT_EXPORT
63 static bool CGFontRefFromBuffer(base::SharedMemoryHandle font_data,
64 uint32 font_data_size,
65 CGFontRef* out);
68 #endif // CONTENT_COMMON_MAC_FONT_LOADER_H_