From 653e2a73b7da23613696aac3b0c7b49c7c759457 Mon Sep 17 00:00:00 2001 From: adrian gallero Date: Sun, 1 May 2016 03:00:40 -0300 Subject: [PATCH] Added methods to SkTypeface to read the actual name of the typeface family and to retrieve ttf tables --- gyp/core.gypi | 2 ++ include/c/xamarin/sk_x_string.h | 46 +++++++++++++++++++++++++++++++++++++++ include/c/xamarin/sk_x_typeface.h | 7 ++++++ include/c/xamarin/sk_x_types.h | 7 ++++++ src/c/xamarin/sk_x_string.cpp | 33 ++++++++++++++++++++++++++++ src/c/xamarin/sk_x_typeface.cpp | 25 +++++++++++++++++++++ src/c/xamarin/sk_x_types_priv.h | 10 +++++++++ 7 files changed, 130 insertions(+) create mode 100644 include/c/xamarin/sk_x_string.h create mode 100644 src/c/xamarin/sk_x_string.cpp diff --git a/gyp/core.gypi b/gyp/core.gypi index c3daa8d..1c91293 100644 --- a/gyp/core.gypi +++ b/gyp/core.gypi @@ -26,6 +26,7 @@ '<(skia_include_path)/c/xamarin/sk_x_shader.h', '<(skia_include_path)/c/xamarin/sk_x_stream.h', '<(skia_include_path)/c/xamarin/sk_x_typeface.h', + '<(skia_include_path)/c/xamarin/sk_x_string.h', '<(skia_src_path)/c/xamarin/sk_x_types_priv.h', '<(skia_src_path)/c/xamarin/sk_x_bitmap.cpp', '<(skia_src_path)/c/xamarin/sk_x_imagedecoder.cpp', @@ -40,6 +41,7 @@ '<(skia_src_path)/c/xamarin/sk_x_shader.cpp', '<(skia_src_path)/c/xamarin/sk_x_stream.cpp', '<(skia_src_path)/c/xamarin/sk_x_typeface.cpp', + '<(skia_src_path)/c/xamarin/sk_x_string.cpp', '<(skia_include_path)/c/sk_canvas.h', '<(skia_include_path)/c/sk_data.h', diff --git a/include/c/xamarin/sk_x_string.h b/include/c/xamarin/sk_x_string.h new file mode 100644 index 0000000..8011813 --- /dev/null +++ b/include/c/xamarin/sk_x_string.h @@ -0,0 +1,46 @@ +/* + * Copyright 2016 Xamarin Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +// EXPERIMENTAL EXPERIMENTAL EXPERIMENTAL EXPERIMENTAL +// DO NOT USE -- FOR INTERNAL TESTING ONLY + +#ifndef sk_x_string_DEFINED +#define sk_x_string_DEFINED + +#include "sk_types.h" +#include "xamarin/sk_x_types.h" + +SK_C_PLUS_PLUS_BEGIN_GUARD + +/** + Returns a new empty sk_string_t. This call must be balanced with a call to + sk_string_destructor(). +*/ +SK_API sk_string_t* sk_string_new_empty(); +/** + Returns a new sk_string_t by copying the specified source string, encoded in UTF-8. + This call must be balanced with a call to sk_string_destructor(). +*/ +SK_API sk_string_t* sk_string_new_with_copy(const char* src, size_t length); + +/** + Deletes the string. +*/ +SK_API void sk_string_destructor(const sk_string_t*); + +/** + Returns the number of bytes stored in the UTF 8 string. Note that this is the number of bytes, not characters. +*/ +SK_API size_t sk_string_get_size(const sk_string_t*); +/** + Returns the pointer to the string. + */ +SK_API const char* sk_string_get_c_str(const sk_string_t*); + +SK_C_PLUS_PLUS_END_GUARD + +#endif diff --git a/include/c/xamarin/sk_x_typeface.h b/include/c/xamarin/sk_x_typeface.h index 78bab58..f280a96 100644 --- a/include/c/xamarin/sk_x_typeface.h +++ b/include/c/xamarin/sk_x_typeface.h @@ -23,6 +23,13 @@ SK_API sk_typeface_t* sk_typeface_create_from_file(const char* path, int index); SK_API sk_typeface_t* sk_typeface_create_from_stream(sk_stream_asset_t* stream, int index); SK_API int sk_typeface_chars_to_glyphs(sk_typeface_t* typeface, const char *chars, sk_encoding_t encoding, uint16_t glyphs[], int glyphCount); +SK_API void sk_typeface_get_family_name(sk_typeface_t* typeface, sk_string_t* family_name); + +SK_API int sk_typeface_count_tables(sk_typeface_t* typeface); +SK_API int sk_typeface_get_table_tags(sk_typeface_t* typeface, sk_font_table_tag_t tags[]); +SK_API size_t sk_typeface_get_table_size(sk_typeface_t* typeface, sk_font_table_tag_t tag); +SK_API size_t sk_typeface_get_table_data(sk_typeface_t* typeface, sk_font_table_tag_t tag, size_t offset, size_t length, void* data); + SK_C_PLUS_PLUS_END_GUARD #endif diff --git a/include/c/xamarin/sk_x_types.h b/include/c/xamarin/sk_x_types.h index b7c1209..0781206 100644 --- a/include/c/xamarin/sk_x_types.h +++ b/include/c/xamarin/sk_x_types.h @@ -58,6 +58,11 @@ typedef struct { #define FONTMETRICS_FLAGS_UNDERLINE_POSITION_IS_VALID (1U << 1) /** + A lightweight managed string. +*/ +typedef struct sk_string_t sk_string_t; +/** + A sk_bitmap_t is an abstraction that specifies a raster bitmap. */ typedef struct sk_bitmap_t sk_bitmap_t; @@ -77,6 +82,8 @@ typedef struct sk_imagefilter_croprect_t sk_imagefilter_croprect_t; Typeface objects are immutable, and so they can be shared between threads. */ typedef struct sk_typeface_t sk_typeface_t; +typedef uint32_t sk_font_table_tag_t; + /** Various stream types */ diff --git a/src/c/xamarin/sk_x_string.cpp b/src/c/xamarin/sk_x_string.cpp new file mode 100644 index 0000000..e0161c8 --- /dev/null +++ b/src/c/xamarin/sk_x_string.cpp @@ -0,0 +1,33 @@ +/* + * Copyright 2016 Xamarin Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "SkString.h" + +#include "xamarin/sk_x_string.h" + +#include "../sk_types_priv.h" +#include "sk_x_types_priv.h" + +sk_string_t* sk_string_new_empty() { + return ToString(new SkString()); +} + +sk_string_t* sk_string_new_with_copy(const char* src, size_t length) { + return ToString(new SkString(src, length)); +} + +void sk_string_destructor(const sk_string_t* cstring) { + delete AsString(cstring); +} + +size_t sk_string_get_size(const sk_string_t* cstring) { + return AsString(cstring)->size(); +} + +const char* sk_string_get_c_str(const sk_string_t* cstring) { + return AsString(cstring)->c_str(); +} diff --git a/src/c/xamarin/sk_x_typeface.cpp b/src/c/xamarin/sk_x_typeface.cpp index 9281db6..63cb9fc 100644 --- a/src/c/xamarin/sk_x_typeface.cpp +++ b/src/c/xamarin/sk_x_typeface.cpp @@ -74,3 +74,28 @@ int sk_typeface_glyph_count (sk_typeface_t* typeface) { return ((SkTypeface*) typeface)->countGlyphs(); } + +void sk_typeface_get_family_name(sk_typeface_t* typeface, sk_string_t* family_name) +{ + ((SkTypeface*)typeface)->getFamilyName(AsString(family_name)); +} + +int sk_typeface_count_tables(sk_typeface_t* typeface) +{ + return ((SkTypeface*)typeface)->countTables(); +} + +int sk_typeface_get_table_tags(sk_typeface_t* typeface, sk_font_table_tag_t tags[]) +{ + return ((SkTypeface*)typeface)->getTableTags(tags); +} + +size_t sk_typeface_get_table_size(sk_typeface_t* typeface, sk_font_table_tag_t tag) +{ + return ((SkTypeface*)typeface)->getTableSize(tag); +} + +size_t sk_typeface_get_table_data(sk_typeface_t* typeface, sk_font_table_tag_t tag, size_t offset, size_t length, void* data) +{ + return ((SkTypeface*)typeface)->getTableData(tag, offset, length, data); +} diff --git a/src/c/xamarin/sk_x_types_priv.h b/src/c/xamarin/sk_x_types_priv.h index d1de211..eb1dc0f 100644 --- a/src/c/xamarin/sk_x_types_priv.h +++ b/src/c/xamarin/sk_x_types_priv.h @@ -20,6 +20,7 @@ #include "SkPictureRecorder.h" #include "SkPoint3.h" #include "SkStream.h" +#include "SkString.h" #include "../../include/effects/SkDisplacementMapEffect.h" #include "../../include/effects/SkDropShadowImageFilter.h" #include "../../include/effects/SkMatrixConvolutionImageFilter.h" @@ -632,4 +633,13 @@ static inline sk_fontmetrics_t* ToFontMetrics(SkPaint::FontMetrics* p) { return reinterpret_cast(p); } +static inline SkString* AsString(const sk_string_t* cdata) { + return reinterpret_cast(const_cast(cdata)); +} + +static inline sk_string_t* ToString(SkString* data) { + return reinterpret_cast(data); +} + + #endif -- 2.7.4