SlideShare a Scribd company logo
1 of 11
Download to read offline
ソースコード読もう会

              Canvas#drawText に潜るよ




              発表者:ちいといつ




              2012年6月26日
              日本アンドロイドの会 京都支部




12年6月26日火曜日
今日は,Canvas#drawText に潜ります。
         Canvas#drawText はビットマップに文字列を描画するメソッドで,画像に
         文字を描画したい時や,View を継承したカスタムViewで文字を描画するの
         によく用いられます。
         また,Label や Button などのキャプションも内部的には
         Canvas#drawText を使用しています。(多分)




12年6月26日火曜日
Canvas#drawText
         /mydroid/frameworks/base/graphics/java/android/graphics/Canvas.java


         いきなりネイティブを呼んでる。


         ・パラメータの mNativeCanvasってなんだろう? → 次ページCanvasの
         コンストラクタ
                 Canvas.java:1358

                  /**
               * Draw the text, with origin at (x,y), using the specified paint. The
               * origin is interpreted based on the Align setting in the paint.
               *
               * @param text The text to be drawn
               * @param x The x-coordinate of the origin of the text being drawn
               * @param y The y-coordinate of the origin of the text being drawn
               * @param paint The paint used for the text (e.g. color, size, style)
               */
              public void drawText(String text, float x, float y, Paint paint) {
                 native_drawText(mNativeCanvas, text, 0, text.length(), x, y, paint.mBidiFlags,
                      paint.mNativePaint);
              }




12年6月26日火曜日
Canvas コンストラクタ:
          mNativeCanvasの型は final int
          final int mNativeCanvas;


          mNativeCanvas に initRasterの戻り値を設定。
          initRasterはネイティブ関数
          private static native int initRaster(int nativeBitmapOrZero);


              ・ bitmap.ni()が気になります → 次ページ


                Canvas.java:122

              /**
               * Construct a canvas with the specified bitmap to draw into. The bitmap
               * must be mutable.
               *
               * <p>The initial target density of the canvas is the same as the given
               * bitmap's density.
               *
               * @param bitmap Specifies a mutable bitmap for the canvas to draw into.
               */
              public Canvas(Bitmap bitmap) {
                 if (!bitmap.isMutable()) {
                    throw new IllegalStateException(
                              "Immutable bitmap passed to Canvas constructor");
                 }
                 throwIfRecycled(bitmap);
                 mNativeCanvas = initRaster(bitmap.ni());
                 mFinalizer = new CanvasFinalizer(mNativeCanvas);
                 mBitmap = bitmap;
                 mDensity = bitmap.mDensity;
              }


12年6月26日火曜日
/mydroid/frameworks/base/graphics/java/android/graphics/Bitmap.java


         Bitmap#ni()

         ・本筋に戻って native_drawText を見ます → 次ページ




               Bitmap.java:1222

          /* package */ final int ni() {
              return mNativeBitmap;
            }




12年6月26日火曜日
/mydroid/frameworks/base/core/jni/android/graphics/Canvas.cpp
      class 名は SkCanvasGlue
      966行目から,Javaから呼ぶためのテーブルのようなもの
      SkCanvasGlue::drawText〜 が本体と思われる


      ・ 文字列を受け取ってるっぽい SkCanvasGlue:: drawText__StringIIFFIPaint を見ます →次ページ




          class SkCanvasGlue {



          Canvas.cpp:966

        {"native_drawText","(I[CIIFFII)V",
          (void*) SkCanvasGlue::drawText___CIIFFIPaint},
        {"native_drawText","(ILjava/lang/String;IIFFII)V",
          (void*) SkCanvasGlue::drawText__StringIIFFIPaint},
        {"native_drawTextRun","(I[CIIIIFFII)V",
          (void*) SkCanvasGlue::drawTextRun___CIIIIFFIPaint},
        {"native_drawTextRun","(ILjava/lang/String;IIIIFFII)V",
          (void*) SkCanvasGlue::drawTextRun__StringIIIIFFIPaint},
        {"native_drawPosText","(I[CII[FI)V",
          (void*) SkCanvasGlue::drawPosText___CII_FPaint},
        {"native_drawPosText","(ILjava/lang/String;[FI)V",
          (void*) SkCanvasGlue::drawPosText__String_FPaint},
        {"native_drawTextOnPath","(I[CIIIFFII)V",
          (void*) SkCanvasGlue::drawTextOnPath___CIIPathFFPaint},
        {"native_drawTextOnPath","(ILjava/lang/String;IFFII)V",
          (void*) SkCanvasGlue::drawTextOnPath__StringPathFFPaint},




12年6月26日火曜日
/mydroid/frameworks/base/core/jni/android/graphics/Canvas.cpp
      class 名は SkCanvasGlue


      最近は,C++でもJavaっぽく class 内に関数本体書くのがトレンドなん?



      ・ 次は TextLayout::drawText を見ます →次ページ



       class SkCanvasGlue {



       Canvas.cpp:743

          static void drawText__StringIIFFIPaint(JNIEnv* env, jobject,
                                SkCanvas* canvas, jstring text,
                                int start, int end,
                                jfloat x, jfloat y, int flags, SkPaint* paint) {
            const jchar* textArray = env->GetStringChars(text, NULL);
       #if RTL_USE_HARFBUZZ
            drawTextWithGlyphs(canvas, textArray, start, end, x, y, flags, paint);
       #else
            TextLayout::drawText(paint, textArray + start, end - start, flags, x, y, canvas);
       #endif
            env->ReleaseStringChars(text, textArray);
          }




12年6月26日火曜日
/mydroid/frameworks/base/core/jni/android/graphics/TextLayout.cpp


      TextLayout::drawText から → handleText → SkCanvas::drawText と呼び出している


      Skというキーワードがそろそろ気になります。
      ・ SkCanvas::drawText を見ます →次ページ


           TextLayout.cpp:284

      // Draws a paragraph of text on a single line, running bidi and shaping
      void TextLayout::drawText(SkPaint* paint, const jchar* text, jsize len,
                    int bidiFlags, jfloat x, jfloat y, SkCanvas* canvas) {
        handleText(paint, text, len, bidiFlags, x, y, canvas, NULL);
      }

           TextLayout.cpp:207

      void TextLayout::handleText(SkPaint *paint, const jchar* text, jsize len,
                       jint bidiFlags, jfloat x, jfloat y,SkCanvas *canvas, SkPath *path) {
        const jchar *workText;
        jchar *buffer = NULL;
        int32_t workBytes;
        if (prepareText(paint, text, len, bidiFlags, &workText, &workBytes, &buffer)) {
           SkScalar x_ = SkFloatToScalar(x);
           SkScalar y_ = SkFloatToScalar(y);
           if (canvas) {
              canvas->drawText(workText, workBytes, x_, y_, *paint);
           } else {
              paint->getTextPath(workText, workBytes, x_, y_, path);
           }
           free(buffer);
        }
      }

12年6月26日火曜日
/mydroid/external/skia/src/core/SkCanvas.cpp



     externalて,外部?
     skia て何?

     SkCanvas.cpp:1672

     void SkCanvas::drawText(const void* text, size_t byteLength,
                  SkScalar x, SkScalar y, const SkPaint& paint) {
       LOOPER_BEGIN(paint, SkDrawFilter::kText_Type)

       while (iter.next()) {
         SkDeviceFilteredPaint dfp(iter.fDevice, looper.paint());
         iter.fDevice->drawText(iter, text, byteLength, x, y, dfp.paint());
         DrawTextDecorations(iter, dfp.paint(),
                      static_cast<const char*>(text), byteLength, x, y);
       }




12年6月26日火曜日
Skia とは?



     http://en.wikipedia.org/wiki/Skia_Graphics_Engine



     Skiaグラフィックス·エンジンは、C++書かれたコンパクトなオープンソースの グラ
     フィックスライブラリ。
     もともとSkia社によって開発され,グーグル社に2005年に買収された。
     それは現在のところGoogle Chrome、Chrome OS、およびAndroidに使用され
     ている。




12年6月26日火曜日
Skiaのソースフォルダを見ると, svg も扱えるらしい。
         Chromeで使われてるんやから, そらそうか。


         本日の結論 :
         AndroidもSVG使えるようにしてよ

         以上
12年6月26日火曜日

More Related Content

Recently uploaded

Postman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By DanielPostman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By Danieldanielhu54
 
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)Hiroki Ichikura
 
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Yuma Ohgami
 
論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A surveyToru Tamaki
 
TSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdfTSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdftaisei2219
 
スマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムスマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムsugiuralab
 
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...Toru Tamaki
 
SOPを理解する 2024/04/19 の勉強会で発表されたものです
SOPを理解する       2024/04/19 の勉強会で発表されたものですSOPを理解する       2024/04/19 の勉強会で発表されたものです
SOPを理解する 2024/04/19 の勉強会で発表されたものですiPride Co., Ltd.
 
論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNetToru Tamaki
 
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略Ryo Sasaki
 

Recently uploaded (10)

Postman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By DanielPostman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By Daniel
 
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
 
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
 
論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey
 
TSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdfTSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdf
 
スマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムスマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システム
 
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
 
SOPを理解する 2024/04/19 の勉強会で発表されたものです
SOPを理解する       2024/04/19 の勉強会で発表されたものですSOPを理解する       2024/04/19 の勉強会で発表されたものです
SOPを理解する 2024/04/19 の勉強会で発表されたものです
 
論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet
 
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
 

Featured

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Featured (20)

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 

JAG京都 ソースコードを読む会

  • 1. ソースコード読もう会 Canvas#drawText に潜るよ 発表者:ちいといつ 2012年6月26日 日本アンドロイドの会 京都支部 12年6月26日火曜日
  • 2. 今日は,Canvas#drawText に潜ります。 Canvas#drawText はビットマップに文字列を描画するメソッドで,画像に 文字を描画したい時や,View を継承したカスタムViewで文字を描画するの によく用いられます。 また,Label や Button などのキャプションも内部的には Canvas#drawText を使用しています。(多分) 12年6月26日火曜日
  • 3. Canvas#drawText /mydroid/frameworks/base/graphics/java/android/graphics/Canvas.java いきなりネイティブを呼んでる。 ・パラメータの mNativeCanvasってなんだろう? → 次ページCanvasの コンストラクタ Canvas.java:1358 /** * Draw the text, with origin at (x,y), using the specified paint. The * origin is interpreted based on the Align setting in the paint. * * @param text The text to be drawn * @param x The x-coordinate of the origin of the text being drawn * @param y The y-coordinate of the origin of the text being drawn * @param paint The paint used for the text (e.g. color, size, style) */ public void drawText(String text, float x, float y, Paint paint) { native_drawText(mNativeCanvas, text, 0, text.length(), x, y, paint.mBidiFlags, paint.mNativePaint); } 12年6月26日火曜日
  • 4. Canvas コンストラクタ: mNativeCanvasの型は final int final int mNativeCanvas; mNativeCanvas に initRasterの戻り値を設定。 initRasterはネイティブ関数 private static native int initRaster(int nativeBitmapOrZero); ・ bitmap.ni()が気になります → 次ページ Canvas.java:122 /** * Construct a canvas with the specified bitmap to draw into. The bitmap * must be mutable. * * <p>The initial target density of the canvas is the same as the given * bitmap's density. * * @param bitmap Specifies a mutable bitmap for the canvas to draw into. */ public Canvas(Bitmap bitmap) { if (!bitmap.isMutable()) { throw new IllegalStateException( "Immutable bitmap passed to Canvas constructor"); } throwIfRecycled(bitmap); mNativeCanvas = initRaster(bitmap.ni()); mFinalizer = new CanvasFinalizer(mNativeCanvas); mBitmap = bitmap; mDensity = bitmap.mDensity; } 12年6月26日火曜日
  • 5. /mydroid/frameworks/base/graphics/java/android/graphics/Bitmap.java Bitmap#ni() ・本筋に戻って native_drawText を見ます → 次ページ Bitmap.java:1222 /* package */ final int ni() { return mNativeBitmap; } 12年6月26日火曜日
  • 6. /mydroid/frameworks/base/core/jni/android/graphics/Canvas.cpp class 名は SkCanvasGlue 966行目から,Javaから呼ぶためのテーブルのようなもの SkCanvasGlue::drawText〜 が本体と思われる ・ 文字列を受け取ってるっぽい SkCanvasGlue:: drawText__StringIIFFIPaint を見ます →次ページ class SkCanvasGlue { Canvas.cpp:966 {"native_drawText","(I[CIIFFII)V", (void*) SkCanvasGlue::drawText___CIIFFIPaint}, {"native_drawText","(ILjava/lang/String;IIFFII)V", (void*) SkCanvasGlue::drawText__StringIIFFIPaint}, {"native_drawTextRun","(I[CIIIIFFII)V", (void*) SkCanvasGlue::drawTextRun___CIIIIFFIPaint}, {"native_drawTextRun","(ILjava/lang/String;IIIIFFII)V", (void*) SkCanvasGlue::drawTextRun__StringIIIIFFIPaint}, {"native_drawPosText","(I[CII[FI)V", (void*) SkCanvasGlue::drawPosText___CII_FPaint}, {"native_drawPosText","(ILjava/lang/String;[FI)V", (void*) SkCanvasGlue::drawPosText__String_FPaint}, {"native_drawTextOnPath","(I[CIIIFFII)V", (void*) SkCanvasGlue::drawTextOnPath___CIIPathFFPaint}, {"native_drawTextOnPath","(ILjava/lang/String;IFFII)V", (void*) SkCanvasGlue::drawTextOnPath__StringPathFFPaint}, 12年6月26日火曜日
  • 7. /mydroid/frameworks/base/core/jni/android/graphics/Canvas.cpp class 名は SkCanvasGlue 最近は,C++でもJavaっぽく class 内に関数本体書くのがトレンドなん? ・ 次は TextLayout::drawText を見ます →次ページ class SkCanvasGlue { Canvas.cpp:743 static void drawText__StringIIFFIPaint(JNIEnv* env, jobject, SkCanvas* canvas, jstring text, int start, int end, jfloat x, jfloat y, int flags, SkPaint* paint) { const jchar* textArray = env->GetStringChars(text, NULL); #if RTL_USE_HARFBUZZ drawTextWithGlyphs(canvas, textArray, start, end, x, y, flags, paint); #else TextLayout::drawText(paint, textArray + start, end - start, flags, x, y, canvas); #endif env->ReleaseStringChars(text, textArray); } 12年6月26日火曜日
  • 8. /mydroid/frameworks/base/core/jni/android/graphics/TextLayout.cpp TextLayout::drawText から → handleText → SkCanvas::drawText と呼び出している Skというキーワードがそろそろ気になります。 ・ SkCanvas::drawText を見ます →次ページ TextLayout.cpp:284 // Draws a paragraph of text on a single line, running bidi and shaping void TextLayout::drawText(SkPaint* paint, const jchar* text, jsize len, int bidiFlags, jfloat x, jfloat y, SkCanvas* canvas) { handleText(paint, text, len, bidiFlags, x, y, canvas, NULL); } TextLayout.cpp:207 void TextLayout::handleText(SkPaint *paint, const jchar* text, jsize len, jint bidiFlags, jfloat x, jfloat y,SkCanvas *canvas, SkPath *path) { const jchar *workText; jchar *buffer = NULL; int32_t workBytes; if (prepareText(paint, text, len, bidiFlags, &workText, &workBytes, &buffer)) { SkScalar x_ = SkFloatToScalar(x); SkScalar y_ = SkFloatToScalar(y); if (canvas) { canvas->drawText(workText, workBytes, x_, y_, *paint); } else { paint->getTextPath(workText, workBytes, x_, y_, path); } free(buffer); } } 12年6月26日火曜日
  • 9. /mydroid/external/skia/src/core/SkCanvas.cpp externalて,外部? skia て何? SkCanvas.cpp:1672 void SkCanvas::drawText(const void* text, size_t byteLength, SkScalar x, SkScalar y, const SkPaint& paint) { LOOPER_BEGIN(paint, SkDrawFilter::kText_Type) while (iter.next()) { SkDeviceFilteredPaint dfp(iter.fDevice, looper.paint()); iter.fDevice->drawText(iter, text, byteLength, x, y, dfp.paint()); DrawTextDecorations(iter, dfp.paint(), static_cast<const char*>(text), byteLength, x, y); } 12年6月26日火曜日
  • 10. Skia とは? http://en.wikipedia.org/wiki/Skia_Graphics_Engine Skiaグラフィックス·エンジンは、C++書かれたコンパクトなオープンソースの グラ フィックスライブラリ。 もともとSkia社によって開発され,グーグル社に2005年に買収された。 それは現在のところGoogle Chrome、Chrome OS、およびAndroidに使用され ている。 12年6月26日火曜日
  • 11. Skiaのソースフォルダを見ると, svg も扱えるらしい。 Chromeで使われてるんやから, そらそうか。 本日の結論 : AndroidもSVG使えるようにしてよ 以上 12年6月26日火曜日