1 /* 2 * Copyright 2009, The Android Open Source Project 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * * Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * * Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 14 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 15 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 16 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 17 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 19 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 20 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 21 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 23 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27 #ifndef android_EmojiFont_DEFINED 28 #define android_EmojiFont_DEFINED 29 30 #include "SkScalar.h" 31 #include "SkUtils.h" 32 33 class SkCanvas; 34 class SkPaint; 35 36 namespace android { 37 38 class EmojiFont { 39 public: 40 /** Returns true if the underlying emoji font mechanism is available. 41 */ 42 static bool IsAvailable(); 43 44 /** Returns index for the corresponding index to the emoji table, or 0 45 if there is no matching emoji form. 46 */ 47 static uint16_t UnicharToGlyph(int32_t unichar); 48 49 /** Returns true if the specified glyph is in the emoji range, i.e. was 50 returned by UnicharToGlyph or UTF16ToGlyph. 51 */ 52 static bool IsEmojiGlyph(uint16_t index) { 53 return index >= kGlyphBase; 54 } 55 56 /** Returns the advance width for the specified emoji form. 57 */ 58 static SkScalar GetAdvanceWidth(uint16_t index, const SkPaint& paint); 59 60 /** Draw the specified emoji form, given the x,y origin of the text 61 version. The paint is the one associated with the text that has 62 the emoji in it. 63 */ 64 static void Draw(SkCanvas*, uint16_t index, SkScalar x, SkScalar y, 65 const SkPaint& paint); 66 67 /** Returns the conver name for Shift_JIS (one of Japanese charset) 68 */ 69 static const char* GetShiftJisConverterName(); 70 private: 71 enum { 72 /* this is our internal trick to embedded private emoji glyph IDs 73 along side normal glyphs IDs that come from real fonts. The 74 assumption is that normal fonts never will report a glyph ID 75 above 20K or 30K, so 64000 should always be a safe starting 76 index. We also assume the the number of emoji will not overflow 77 16bits starting at 64000 i.e. 65535 - 64000 > total emoji count 78 */ 79 kGlyphBase = 64000 80 }; 81 }; 82 } 83 84 #endif 85