Chromium Code Reviews| 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 struct Result { |
|
jeremy
2012/04/04 08:35:38
can you add a comment here describing what the str
bashi
2012/04/04 09:36:22
Done.
| |
| 29 // suitable for sending over IPC. | 31 uint32 font_data_size; |
| 32 base::SharedMemory font_data; | |
| 33 uint32 font_id; | |
| 34 }; | |
| 35 // Load a font specified by |font| into a shared memory buffer suitable for | |
| 36 // sending over IPC. | |
| 30 // | 37 // |
| 31 // On return: | 38 // On return: |
| 32 // returns true on success, false on failure. | 39 // |result->font_data| - shared memory buffer containing the raw data for |
| 33 // |font_data| - shared memory buffer containing the raw data for the font | 40 // the font file. |
|
jeremy
2012/04/04 08:35:38
Can you add a comment as to what to expect in this
bashi
2012/04/04 09:36:22
The buffer won't be valid on failure. Added descri
| |
| 34 // file. | 41 // |result->font_data_size| - size of data contained in |result->font_data|. |
| 35 // |font_data_size| - size of data contained in |font_data|. | 42 // This value is zero on failure. |
| 36 // |font_id| - unique identifier for the on-disk file we load for the font. | 43 // |result->font_id| - unique identifier for the on-disk file we load for |
| 44 // the font. This value is zero on failure. | |
| 37 CONTENT_EXPORT | 45 CONTENT_EXPORT |
| 38 static bool LoadFontIntoBuffer(NSFont* font_to_encode, | 46 static void LoadFont(const FontDescriptor& font, FontLoader::Result* result); |
| 39 base::SharedMemory* font_data, | |
| 40 uint32* font_data_size, | |
| 41 uint32* font_id); | |
| 42 | 47 |
| 43 // Given a shared memory buffer containing the raw data for a font file, load | 48 // Given a shared memory buffer containing the raw data for a font file, load |
| 44 // the font and return a CGFontRef. | 49 // the font and return a CGFontRef. |
| 45 // | 50 // |
| 46 // |data| - A shared memory handle pointing to the raw data from a font file. | 51 // |data| - A shared memory handle pointing to the raw data from a font file. |
| 47 // |data_size| - Size of |data|. | 52 // |data_size| - Size of |data|. |
| 48 // | 53 // |
| 49 // On return: | 54 // On return: |
| 50 // returns true on success, false on failure. | 55 // returns true on success, false on failure. |
| 51 // |out| - A CGFontRef corresponding to the designated font. | 56 // |out| - A CGFontRef corresponding to the designated font. |
| 52 // The caller is responsible for releasing this value via CGFontRelease() | 57 // The caller is responsible for releasing this value via CGFontRelease() |
| 53 // when done. | 58 // when done. |
| 54 CONTENT_EXPORT | 59 CONTENT_EXPORT |
| 55 static bool CGFontRefFromBuffer(base::SharedMemoryHandle font_data, | 60 static bool CGFontRefFromBuffer(base::SharedMemoryHandle font_data, |
| 56 uint32 font_data_size, | 61 uint32 font_data_size, |
| 57 CGFontRef* out); | 62 CGFontRef* out); |
| 58 }; | 63 }; |
| 59 | 64 |
| 60 #endif // CONTENT_COMMON_MAC_FONT_LOADER_H_ | 65 #endif // CONTENT_COMMON_MAC_FONT_LOADER_H_ |
| OLD | NEW |