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 | |
| 23 | namespace android { |
| 24 | |
Fabrice Di Meglio | dd347df | 2011-02-17 13:22:08 -0800 | [diff] [blame] | 25 | #define UNICODE_NOT_A_CHAR 0xffff |
| 26 | #define UNICODE_ZWSP 0x200b |
| 27 | #define UNICODE_FIRST_LOW_SURROGATE 0xdc00 |
| 28 | #define UNICODE_FIRST_HIGH_SURROGATE 0xd800 |
| 29 | #define UNICODE_FIRST_PRIVATE_USE 0xe000 |
| 30 | #define UNICODE_FIRST_RTL_CHAR 0x0590 |
| 31 | |
| 32 | /* |
| 33 | * Temporary buffer size |
| 34 | */ |
| 35 | #define CHAR_BUFFER_SIZE 80 |
| 36 | |
Doug Felt | f7cb1f7 | 2010-07-01 16:20:43 -0700 | [diff] [blame] | 37 | class TextLayout { |
| 38 | public: |
| 39 | |
| 40 | enum { |
| 41 | kDirection_LTR = 0, |
| 42 | kDirection_RTL = 1, |
| 43 | |
| 44 | kDirection_Mask = 0x1 |
| 45 | }; |
| 46 | |
| 47 | enum { |
| 48 | kBidi_LTR = 0, |
| 49 | kBidi_RTL = 1, |
| 50 | kBidi_Default_LTR = 2, |
| 51 | kBidi_Default_RTL = 3, |
| 52 | kBidi_Force_LTR = 4, |
| 53 | kBidi_Force_RTL = 5, |
| 54 | |
| 55 | kBidi_Mask = 0x7 |
| 56 | }; |
| 57 | |
| 58 | /* |
| 59 | * Draws a unidirectional run of text. |
| 60 | */ |
| 61 | static void drawTextRun(SkPaint* paint, const jchar* chars, |
| 62 | jint start, jint count, jint contextCount, |
| 63 | int dirFlags, jfloat x, jfloat y, SkCanvas* canvas); |
| 64 | |
| 65 | static void getTextRunAdvances(SkPaint *paint, const jchar *chars, jint start, |
| 66 | jint count, jint contextCount, jint dirFlags, |
| 67 | jfloat *resultAdvances, jfloat &resultTotalAdvance); |
| 68 | |
| 69 | static void drawText(SkPaint* paint, const jchar* text, jsize len, |
| 70 | jint bidiFlags, jfloat x, jfloat y, SkCanvas* canvas); |
| 71 | |
| 72 | static void getTextPath(SkPaint *paint, const jchar *text, jsize len, |
| 73 | jint bidiFlags, jfloat x, jfloat y, SkPath *path); |
| 74 | |
| 75 | static void drawTextOnPath(SkPaint* paint, const jchar* text, jsize len, |
| 76 | int bidiFlags, jfloat hOffset, jfloat vOffset, |
| 77 | SkPath* path, SkCanvas* canvas); |
Romain Guy | e8e62a4 | 2010-07-23 18:55:21 -0700 | [diff] [blame] | 78 | |
| 79 | static bool prepareText(SkPaint *paint, const jchar* text, jsize len, jint bidiFlags, |
Romain Guy | 9226298 | 2010-07-26 11:17:54 -0700 | [diff] [blame] | 80 | const jchar** outText, int32_t* outBytes, jchar** outBuffer); |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 81 | static bool prepareRtlTextRun(const jchar* context, jsize start, jsize& count, |
| 82 | jsize contextCount, jchar* shaped); |
| 83 | |
Doug Felt | f7cb1f7 | 2010-07-01 16:20:43 -0700 | [diff] [blame] | 84 | |
| 85 | private: |
| 86 | static bool needsLayout(const jchar* text, jint len, jint bidiFlags); |
| 87 | static int shapeRtlText(const jchar* context, jsize start, jsize count, jsize contextCount, |
| 88 | jchar* shaped, UErrorCode &status); |
| 89 | static jint layoutLine(const jchar* text, jint len, jint flags, int &dir, jchar* buffer, |
| 90 | UErrorCode &status); |
| 91 | static void handleText(SkPaint *paint, const jchar* text, jsize len, |
| 92 | int bidiFlags, jfloat x, jfloat y,SkCanvas *canvas, SkPath *path); |
| 93 | }; |
| 94 | |
| 95 | } |