blob: c98f74543a99a9ad0f3c588a0a213e2036a660b3 [file] [log] [blame]
Doug Feltf7cb1f72010-07-01 16:20:43 -07001/*
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
23namespace android {
24
Fabrice Di Megliodd347df2011-02-17 13:22:08 -080025#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 Feltf7cb1f72010-07-01 16:20:43 -070037class TextLayout {
38public:
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 Guye8e62a42010-07-23 18:55:21 -070078
79 static bool prepareText(SkPaint *paint, const jchar* text, jsize len, jint bidiFlags,
Romain Guy92262982010-07-26 11:17:54 -070080 const jchar** outText, int32_t* outBytes, jchar** outBuffer);
Romain Guy61c8c9c2010-08-09 20:48:09 -070081 static bool prepareRtlTextRun(const jchar* context, jsize start, jsize& count,
82 jsize contextCount, jchar* shaped);
83
Doug Feltf7cb1f72010-07-01 16:20:43 -070084
85private:
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}