Doug Felt | f7cb1f7 | 2010-07-01 16:20:43 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "jni.h" |
| 18 | |
| 19 | #include "SkCanvas.h" |
| 20 | #include "SkPaint.h" |
| 21 | #include "unicode/utypes.h" |
| 22 | |
Fabrice Di Meglio | d313c66 | 2011-02-24 19:56:18 -0800 | [diff] [blame] | 23 | #include "TextLayoutCache.h" |
| 24 | |
Doug Felt | f7cb1f7 | 2010-07-01 16:20:43 -0700 | [diff] [blame] | 25 | namespace android { |
| 26 | |
Fabrice Di Meglio | dd347df | 2011-02-17 13:22:08 -0800 | [diff] [blame] | 27 | #define UNICODE_NOT_A_CHAR 0xffff |
| 28 | #define UNICODE_ZWSP 0x200b |
| 29 | #define UNICODE_FIRST_LOW_SURROGATE 0xdc00 |
| 30 | #define UNICODE_FIRST_HIGH_SURROGATE 0xd800 |
| 31 | #define UNICODE_FIRST_PRIVATE_USE 0xe000 |
| 32 | #define UNICODE_FIRST_RTL_CHAR 0x0590 |
| 33 | |
| 34 | /* |
| 35 | * Temporary buffer size |
| 36 | */ |
| 37 | #define CHAR_BUFFER_SIZE 80 |
| 38 | |
Fabrice Di Meglio | d313c66 | 2011-02-24 19:56:18 -0800 | [diff] [blame] | 39 | /** |
| 40 | * Turn on for using the Cache |
| 41 | */ |
| 42 | #define USE_TEXT_LAYOUT_CACHE 1 |
| 43 | |
Fabrice Di Meglio | 689e515 | 2011-04-13 16:07:37 -0700 | [diff] [blame] | 44 | enum { |
Fabrice Di Meglio | 689e515 | 2011-04-13 16:07:37 -0700 | [diff] [blame] | 45 | kDirection_LTR = 0, |
| 46 | kDirection_RTL = 1, |
| 47 | |
| 48 | kDirection_Mask = 0x1 |
| 49 | }; |
| 50 | |
Doug Felt | f7cb1f7 | 2010-07-01 16:20:43 -0700 | [diff] [blame] | 51 | class TextLayout { |
| 52 | public: |
| 53 | |
Fabrice Di Meglio | d313c66 | 2011-02-24 19:56:18 -0800 | [diff] [blame] | 54 | static void getTextRunAdvances(SkPaint* paint, const jchar* chars, jint start, |
Fabrice Di Meglio | 6d9fe5b | 2013-02-11 18:27:34 -0800 | [diff] [blame^] | 55 | jint count, jint contextCount, |
Fabrice Di Meglio | 79df532 | 2011-09-19 15:17:56 -0700 | [diff] [blame] | 56 | jfloat* resultAdvances, jfloat* resultTotalAdvance); |
Doug Felt | f7cb1f7 | 2010-07-01 16:20:43 -0700 | [diff] [blame] | 57 | |
Fabrice Di Meglio | d313c66 | 2011-02-24 19:56:18 -0800 | [diff] [blame] | 58 | static void getTextPath(SkPaint* paint, const jchar* text, jsize len, |
Fabrice Di Meglio | 6d9fe5b | 2013-02-11 18:27:34 -0800 | [diff] [blame^] | 59 | jfloat x, jfloat y, SkPath* path); |
Doug Felt | f7cb1f7 | 2010-07-01 16:20:43 -0700 | [diff] [blame] | 60 | |
| 61 | static void drawTextOnPath(SkPaint* paint, const jchar* text, jsize len, |
Fabrice Di Meglio | 6d9fe5b | 2013-02-11 18:27:34 -0800 | [diff] [blame^] | 62 | jfloat hOffset, jfloat vOffset, |
Doug Felt | f7cb1f7 | 2010-07-01 16:20:43 -0700 | [diff] [blame] | 63 | SkPath* path, SkCanvas* canvas); |
Doug Felt | f7cb1f7 | 2010-07-01 16:20:43 -0700 | [diff] [blame] | 64 | |
| 65 | private: |
Fabrice Di Meglio | d313c66 | 2011-02-24 19:56:18 -0800 | [diff] [blame] | 66 | static void handleText(SkPaint* paint, const jchar* text, jsize len, |
Fabrice Di Meglio | 6d9fe5b | 2013-02-11 18:27:34 -0800 | [diff] [blame^] | 67 | jfloat x, jfloat y, SkPath* path); |
Doug Felt | f7cb1f7 | 2010-07-01 16:20:43 -0700 | [diff] [blame] | 68 | }; |
Fabrice Di Meglio | fcf2be1 | 2011-04-05 17:02:36 -0700 | [diff] [blame] | 69 | } // namespace android |