Added methods to SkTypeface to read the actual name of the typeface family and to...
authoradrian gallero <agallero@gmail.com>
Sun, 1 May 2016 06:00:40 +0000 (03:00 -0300)
committeradrian gallero <agallero@gmail.com>
Sun, 1 May 2016 06:00:40 +0000 (03:00 -0300)
gyp/core.gypi
include/c/xamarin/sk_x_string.h [new file with mode: 0644]
include/c/xamarin/sk_x_typeface.h
include/c/xamarin/sk_x_types.h
src/c/xamarin/sk_x_string.cpp [new file with mode: 0644]
src/c/xamarin/sk_x_typeface.cpp
src/c/xamarin/sk_x_types_priv.h

index c3daa8d..1c91293 100644 (file)
@@ -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 (file)
index 0000000..8011813
--- /dev/null
@@ -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
index 78bab58..f280a96 100644 (file)
@@ -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
index b7c1209..0781206 100644 (file)
@@ -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 (file)
index 0000000..e0161c8
--- /dev/null
@@ -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();
+}
index 9281db6..63cb9fc 100644 (file)
@@ -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);
+}
index d1de211..eb1dc0f 100644 (file)
@@ -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<sk_fontmetrics_t*>(p);
 }
 
+static inline SkString* AsString(const sk_string_t* cdata) {
+       return reinterpret_cast<SkString*>(const_cast<sk_string_t*>(cdata));
+}
+
+static inline sk_string_t* ToString(SkString* data) {
+       return reinterpret_cast<sk_string_t*>(data);
+}
+
+
 #endif