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