blob: fa388c8ed74f6c721d70de8d3e8ee6152aa8fd2b [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
Fabrice Di Megliod313c662011-02-24 19:56:18 -080023#include "TextLayoutCache.h"
24
Doug Feltf7cb1f72010-07-01 16:20:43 -070025namespace android {
26
Fabrice Di Megliodd347df2011-02-17 13:22:08 -080027#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 Megliod313c662011-02-24 19:56:18 -080039/**
40 * Turn on for using the Cache
41 */
42#define USE_TEXT_LAYOUT_CACHE 1
43
Fabrice Di Meglio689e5152011-04-13 16:07:37 -070044enum {
Fabrice Di Meglio689e5152011-04-13 16:07:37 -070045 kDirection_LTR = 0,
46 kDirection_RTL = 1,
47
48 kDirection_Mask = 0x1
49};
50
Doug Feltf7cb1f72010-07-01 16:20:43 -070051class TextLayout {
52public:
53
Fabrice Di Megliod313c662011-02-24 19:56:18 -080054 static void getTextRunAdvances(SkPaint* paint, const jchar* chars, jint start,
Fabrice Di Meglio6d9fe5b2013-02-11 18:27:34 -080055 jint count, jint contextCount,
Fabrice Di Meglio79df5322011-09-19 15:17:56 -070056 jfloat* resultAdvances, jfloat* resultTotalAdvance);
Doug Feltf7cb1f72010-07-01 16:20:43 -070057
Fabrice Di Megliod313c662011-02-24 19:56:18 -080058 static void getTextPath(SkPaint* paint, const jchar* text, jsize len,
Fabrice Di Meglio6d9fe5b2013-02-11 18:27:34 -080059 jfloat x, jfloat y, SkPath* path);
Doug Feltf7cb1f72010-07-01 16:20:43 -070060
61 static void drawTextOnPath(SkPaint* paint, const jchar* text, jsize len,
Fabrice Di Meglio6d9fe5b2013-02-11 18:27:34 -080062 jfloat hOffset, jfloat vOffset,
Doug Feltf7cb1f72010-07-01 16:20:43 -070063 SkPath* path, SkCanvas* canvas);
Doug Feltf7cb1f72010-07-01 16:20:43 -070064
65private:
Fabrice Di Megliod313c662011-02-24 19:56:18 -080066 static void handleText(SkPaint* paint, const jchar* text, jsize len,
Fabrice Di Meglio6d9fe5b2013-02-11 18:27:34 -080067 jfloat x, jfloat y, SkPath* path);
Doug Feltf7cb1f72010-07-01 16:20:43 -070068};
Fabrice Di Megliofcf2be12011-04-05 17:02:36 -070069} // namespace android