OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_COMMON_MAC_FONT_LOADER_H_ | 5 #ifndef CONTENT_COMMON_MAC_FONT_LOADER_H_ |
6 #define CONTENT_COMMON_MAC_FONT_LOADER_H_ | 6 #define CONTENT_COMMON_MAC_FONT_LOADER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <ApplicationServices/ApplicationServices.h> | 9 #include <ApplicationServices/ApplicationServices.h> |
10 | 10 |
11 #include "base/shared_memory.h" | 11 #include "base/shared_memory.h" |
12 #include "content/common/content_export.h" | 12 #include "content/common/content_export.h" |
13 | 13 |
14 #ifdef __OBJC__ | 14 #ifdef __OBJC__ |
15 @class NSFont; | 15 @class NSFont; |
16 #else | 16 #else |
17 class NSFont; | 17 class NSFont; |
18 #endif | 18 #endif |
19 | 19 |
| 20 struct FontDescriptor; |
| 21 |
20 // Provides functionality to transmit fonts over IPC. | 22 // Provides functionality to transmit fonts over IPC. |
21 // | 23 // |
22 // Note about font formats: .dfont (datafork suitcase) fonts are currently not | 24 // Note about font formats: .dfont (datafork suitcase) fonts are currently not |
23 // supported by this code since CGFontCreateWithDataProvider() can't handle them | 25 // supported by this code since CGFontCreateWithDataProvider() can't handle them |
24 // directly. | 26 // directly. |
25 | 27 |
26 class FontLoader { | 28 class FontLoader { |
27 public: | 29 public: |
28 // Load a font specified by |font_to_encode| into a shared memory buffer | 30 // This structure holds the result of LoadFont(). This structure is passed to |
29 // suitable for sending over IPC. | 31 // LoadFont(), which should run on the file thread, then it is passed to a |
| 32 // task which sends the result to the originating renderer. |
| 33 struct Result { |
| 34 uint32 font_data_size; |
| 35 base::SharedMemory font_data; |
| 36 uint32 font_id; |
| 37 }; |
| 38 // Load a font specified by |font| into a shared memory buffer suitable for |
| 39 // sending over IPC. |
30 // | 40 // |
31 // On return: | 41 // On return: |
32 // returns true on success, false on failure. | 42 // |result->font_data| - shared memory buffer containing the raw data for |
33 // |font_data| - shared memory buffer containing the raw data for the font | 43 // the font file. The buffer is only valid when both |result->font_data_size| |
34 // file. | 44 // and |result->font_id| are not zero. |
35 // |font_data_size| - size of data contained in |font_data|. | 45 // |result->font_data_size| - size of data contained in |result->font_data|. |
36 // |font_id| - unique identifier for the on-disk file we load for the font. | 46 // This value is zero on failure. |
| 47 // |result->font_id| - unique identifier for the on-disk file we load for |
| 48 // the font. This value is zero on failure. |
37 CONTENT_EXPORT | 49 CONTENT_EXPORT |
38 static bool LoadFontIntoBuffer(NSFont* font_to_encode, | 50 static void LoadFont(const FontDescriptor& font, FontLoader::Result* result); |
39 base::SharedMemory* font_data, | |
40 uint32* font_data_size, | |
41 uint32* font_id); | |
42 | 51 |
43 // Given a shared memory buffer containing the raw data for a font file, load | 52 // Given a shared memory buffer containing the raw data for a font file, load |
44 // the font and return a CGFontRef. | 53 // the font and return a CGFontRef. |
45 // | 54 // |
46 // |data| - A shared memory handle pointing to the raw data from a font file. | 55 // |data| - A shared memory handle pointing to the raw data from a font file. |
47 // |data_size| - Size of |data|. | 56 // |data_size| - Size of |data|. |
48 // | 57 // |
49 // On return: | 58 // On return: |
50 // returns true on success, false on failure. | 59 // returns true on success, false on failure. |
51 // |out| - A CGFontRef corresponding to the designated font. | 60 // |out| - A CGFontRef corresponding to the designated font. |
52 // The caller is responsible for releasing this value via CGFontRelease() | 61 // The caller is responsible for releasing this value via CGFontRelease() |
53 // when done. | 62 // when done. |
54 CONTENT_EXPORT | 63 CONTENT_EXPORT |
55 static bool CGFontRefFromBuffer(base::SharedMemoryHandle font_data, | 64 static bool CGFontRefFromBuffer(base::SharedMemoryHandle font_data, |
56 uint32 font_data_size, | 65 uint32 font_data_size, |
57 CGFontRef* out); | 66 CGFontRef* out); |
58 }; | 67 }; |
59 | 68 |
60 #endif // CONTENT_COMMON_MAC_FONT_LOADER_H_ | 69 #endif // CONTENT_COMMON_MAC_FONT_LOADER_H_ |
OLD | NEW |