Home | History | Annotate | Download | only in graphics
      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 #include "TextLayoutCache.h"
     24 
     25 namespace android {
     26 
     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 
     39 /**
     40  * Turn on for using the Cache
     41  */
     42 #define USE_TEXT_LAYOUT_CACHE 1
     43 
     44 enum {
     45     kBidi_LTR = 0,
     46     kBidi_RTL = 1,
     47     kBidi_Default_LTR = 2,
     48     kBidi_Default_RTL = 3,
     49     kBidi_Force_LTR = 4,
     50     kBidi_Force_RTL = 5,
     51 
     52     kBidi_Mask = 0x7
     53 };
     54 
     55 enum {
     56     kDirection_LTR = 0,
     57     kDirection_RTL = 1,
     58 
     59     kDirection_Mask = 0x1
     60 };
     61 
     62 class TextLayout {
     63 public:
     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 getTextRunAdvancesICU(SkPaint* paint, const jchar* chars, jint start,
     70                                    jint count, jint contextCount, jint dirFlags,
     71                                    jfloat* resultAdvances, jfloat& resultTotalAdvance);
     72 
     73     static void getTextPath(SkPaint* paint, const jchar* text, jsize len,
     74                             jint bidiFlags, jfloat x, jfloat y, SkPath* path);
     75 
     76     static void drawTextOnPath(SkPaint* paint, const jchar* text, jsize len,
     77                                int bidiFlags, jfloat hOffset, jfloat vOffset,
     78                                SkPath* path, SkCanvas* canvas);
     79 
     80 private:
     81     static bool needsLayout(const jchar* text, jint len, jint bidiFlags);
     82 
     83     static void handleText(SkPaint* paint, const jchar* text, jsize len,
     84                            int bidiFlags, jfloat x, jfloat y, SkPath* path);
     85 
     86     static void computeAdvancesWithICU(SkPaint* paint, const UChar* chars,
     87             size_t start, size_t count, size_t contextCount, int dirFlags,
     88             jfloat* outAdvances, jfloat* outTotalAdvance);
     89 };
     90 } // namespace android
     91