OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkLua.h" | 8 #include "SkLua.h" |
9 | 9 |
10 #if SK_SUPPORT_GPU | 10 #if SK_SUPPORT_GPU |
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 if (lua_isstring(L, 2) && lua_isnumber(L, 3) && lua_isnumber(L, 4)) { | 549 if (lua_isstring(L, 2) && lua_isnumber(L, 3) && lua_isnumber(L, 4)) { |
550 size_t len; | 550 size_t len; |
551 const char* text = lua_tolstring(L, 2, &len); | 551 const char* text = lua_tolstring(L, 2, &len); |
552 get_ref<SkCanvas>(L, 1)->drawText(text, len, | 552 get_ref<SkCanvas>(L, 1)->drawText(text, len, |
553 lua2scalar(L, 3), lua2scalar(L, 4), | 553 lua2scalar(L, 3), lua2scalar(L, 4), |
554 *get_obj<SkPaint>(L, 5)); | 554 *get_obj<SkPaint>(L, 5)); |
555 } | 555 } |
556 return 0; | 556 return 0; |
557 } | 557 } |
558 | 558 |
| 559 static int lcanvas_drawTextBlob(lua_State* L) { |
| 560 const SkTextBlob* blob = get_ref<SkTextBlob>(L, 2); |
| 561 SkScalar x = lua2scalar(L, 3); |
| 562 SkScalar y = lua2scalar(L, 4); |
| 563 const SkPaint& paint = *get_obj<SkPaint>(L, 5); |
| 564 get_ref<SkCanvas>(L, 1)->drawTextBlob(blob, x, y, paint); |
| 565 return 0; |
| 566 } |
| 567 |
559 static int lcanvas_getSaveCount(lua_State* L) { | 568 static int lcanvas_getSaveCount(lua_State* L) { |
560 lua_pushnumber(L, get_ref<SkCanvas>(L, 1)->getSaveCount()); | 569 lua_pushnumber(L, get_ref<SkCanvas>(L, 1)->getSaveCount()); |
561 return 1; | 570 return 1; |
562 } | 571 } |
563 | 572 |
564 static int lcanvas_getTotalMatrix(lua_State* L) { | 573 static int lcanvas_getTotalMatrix(lua_State* L) { |
565 SkLua(L).pushMatrix(get_ref<SkCanvas>(L, 1)->getTotalMatrix()); | 574 SkLua(L).pushMatrix(get_ref<SkCanvas>(L, 1)->getTotalMatrix()); |
566 return 1; | 575 return 1; |
567 } | 576 } |
568 | 577 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
674 { "drawColor", lcanvas_drawColor }, | 683 { "drawColor", lcanvas_drawColor }, |
675 { "drawPaint", lcanvas_drawPaint }, | 684 { "drawPaint", lcanvas_drawPaint }, |
676 { "drawRect", lcanvas_drawRect }, | 685 { "drawRect", lcanvas_drawRect }, |
677 { "drawOval", lcanvas_drawOval }, | 686 { "drawOval", lcanvas_drawOval }, |
678 { "drawCircle", lcanvas_drawCircle }, | 687 { "drawCircle", lcanvas_drawCircle }, |
679 { "drawImage", lcanvas_drawImage }, | 688 { "drawImage", lcanvas_drawImage }, |
680 { "drawImageRect", lcanvas_drawImageRect }, | 689 { "drawImageRect", lcanvas_drawImageRect }, |
681 { "drawPath", lcanvas_drawPath }, | 690 { "drawPath", lcanvas_drawPath }, |
682 { "drawPicture", lcanvas_drawPicture }, | 691 { "drawPicture", lcanvas_drawPicture }, |
683 { "drawText", lcanvas_drawText }, | 692 { "drawText", lcanvas_drawText }, |
| 693 { "drawTextBlob", lcanvas_drawTextBlob }, |
684 { "getSaveCount", lcanvas_getSaveCount }, | 694 { "getSaveCount", lcanvas_getSaveCount }, |
685 { "getTotalMatrix", lcanvas_getTotalMatrix }, | 695 { "getTotalMatrix", lcanvas_getTotalMatrix }, |
686 { "getClipStack", lcanvas_getClipStack }, | 696 { "getClipStack", lcanvas_getClipStack }, |
687 #if SK_SUPPORT_GPU | 697 #if SK_SUPPORT_GPU |
688 { "getReducedClipStack", SkLua::lcanvas_getReducedClipStack }, | 698 { "getReducedClipStack", SkLua::lcanvas_getReducedClipStack }, |
689 #endif | 699 #endif |
690 { "save", lcanvas_save }, | 700 { "save", lcanvas_save }, |
691 { "saveLayer", lcanvas_saveLayer }, | 701 { "saveLayer", lcanvas_saveLayer }, |
692 { "restore", lcanvas_restore }, | 702 { "restore", lcanvas_restore }, |
693 { "scale", lcanvas_scale }, | 703 { "scale", lcanvas_scale }, |
(...skipping 996 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1690 | 1700 |
1691 static const struct luaL_Reg gSkPicture_Methods[] = { | 1701 static const struct luaL_Reg gSkPicture_Methods[] = { |
1692 { "width", lpicture_width }, | 1702 { "width", lpicture_width }, |
1693 { "height", lpicture_height }, | 1703 { "height", lpicture_height }, |
1694 { "__gc", lpicture_gc }, | 1704 { "__gc", lpicture_gc }, |
1695 { NULL, NULL } | 1705 { NULL, NULL } |
1696 }; | 1706 }; |
1697 | 1707 |
1698 /////////////////////////////////////////////////////////////////////////////// | 1708 /////////////////////////////////////////////////////////////////////////////// |
1699 | 1709 |
| 1710 static int ltextblob_bounds(lua_State* L) { |
| 1711 SkLua(L).pushRect(get_ref<SkTextBlob>(L, 1)->bounds()); |
| 1712 return 1; |
| 1713 } |
| 1714 |
| 1715 static int ltextblob_gc(lua_State* L) { |
| 1716 SkSafeUnref(get_ref<SkTextBlob>(L, 1)); |
| 1717 return 0; |
| 1718 } |
| 1719 |
| 1720 static const struct luaL_Reg gSkTextBlob_Methods[] = { |
| 1721 { "bounds", ltextblob_bounds }, |
| 1722 { "__gc", ltextblob_gc }, |
| 1723 { NULL, NULL } |
| 1724 }; |
| 1725 |
| 1726 /////////////////////////////////////////////////////////////////////////////// |
| 1727 |
1700 static int ltypeface_gc(lua_State* L) { | 1728 static int ltypeface_gc(lua_State* L) { |
1701 SkSafeUnref(get_ref<SkTypeface>(L, 1)); | 1729 SkSafeUnref(get_ref<SkTypeface>(L, 1)); |
1702 return 0; | 1730 return 0; |
1703 } | 1731 } |
1704 | 1732 |
1705 static const struct luaL_Reg gSkTypeface_Methods[] = { | 1733 static const struct luaL_Reg gSkTypeface_Methods[] = { |
1706 { "__gc", ltypeface_gc }, | 1734 { "__gc", ltypeface_gc }, |
1707 { NULL, NULL } | 1735 { NULL, NULL } |
1708 }; | 1736 }; |
1709 | 1737 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1802 static int lsk_newPictureRecorder(lua_State* L) { | 1830 static int lsk_newPictureRecorder(lua_State* L) { |
1803 push_new<SkPictureRecorder>(L); | 1831 push_new<SkPictureRecorder>(L); |
1804 return 1; | 1832 return 1; |
1805 } | 1833 } |
1806 | 1834 |
1807 static int lsk_newRRect(lua_State* L) { | 1835 static int lsk_newRRect(lua_State* L) { |
1808 push_new<SkRRect>(L)->setEmpty(); | 1836 push_new<SkRRect>(L)->setEmpty(); |
1809 return 1; | 1837 return 1; |
1810 } | 1838 } |
1811 | 1839 |
| 1840 #include "SkTextBox.h" |
| 1841 // Sk.newTextBlob(text, rect, paint) |
| 1842 static int lsk_newTextBlob(lua_State* L) { |
| 1843 const char* text = lua_tolstring(L, 1, NULL); |
| 1844 SkRect bounds; |
| 1845 lua2rect(L, 2, &bounds); |
| 1846 const SkPaint& paint = *get_obj<SkPaint>(L, 3); |
| 1847 |
| 1848 SkTextBox box; |
| 1849 box.setMode(SkTextBox::kLineBreak_Mode); |
| 1850 box.setBox(bounds); |
| 1851 box.setText(text, strlen(text), paint); |
| 1852 |
| 1853 SkScalar newBottom; |
| 1854 SkAutoTUnref<SkTextBlob> blob(box.snapshotTextBlob(&newBottom)); |
| 1855 push_ref<SkTextBlob>(L, blob); |
| 1856 SkLua(L).pushScalar(newBottom); |
| 1857 return 2; |
| 1858 } |
| 1859 |
1812 static int lsk_newTypeface(lua_State* L) { | 1860 static int lsk_newTypeface(lua_State* L) { |
1813 const char* name = NULL; | 1861 const char* name = NULL; |
1814 int style = SkTypeface::kNormal; | 1862 int style = SkTypeface::kNormal; |
1815 | 1863 |
1816 int count = lua_gettop(L); | 1864 int count = lua_gettop(L); |
1817 if (count > 0 && lua_isstring(L, 1)) { | 1865 if (count > 0 && lua_isstring(L, 1)) { |
1818 name = lua_tolstring(L, 1, NULL); | 1866 name = lua_tolstring(L, 1, NULL); |
1819 if (count > 1 && lua_isnumber(L, 2)) { | 1867 if (count > 1 && lua_isnumber(L, 2)) { |
1820 style = lua_tointegerx(L, 2, NULL) & SkTypeface::kBoldItalic; | 1868 style = lua_tointegerx(L, 2, NULL) & SkTypeface::kBoldItalic; |
1821 } | 1869 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1870 setfield_function(L, "newDocumentPDF", lsk_newDocumentPDF); | 1918 setfield_function(L, "newDocumentPDF", lsk_newDocumentPDF); |
1871 setfield_function(L, "loadImage", lsk_loadImage); | 1919 setfield_function(L, "loadImage", lsk_loadImage); |
1872 setfield_function(L, "newBlurImageFilter", lsk_newBlurImageFilter); | 1920 setfield_function(L, "newBlurImageFilter", lsk_newBlurImageFilter); |
1873 setfield_function(L, "newLinearGradient", lsk_newLinearGradient); | 1921 setfield_function(L, "newLinearGradient", lsk_newLinearGradient); |
1874 setfield_function(L, "newMatrix", lsk_newMatrix); | 1922 setfield_function(L, "newMatrix", lsk_newMatrix); |
1875 setfield_function(L, "newPaint", lsk_newPaint); | 1923 setfield_function(L, "newPaint", lsk_newPaint); |
1876 setfield_function(L, "newPath", lsk_newPath); | 1924 setfield_function(L, "newPath", lsk_newPath); |
1877 setfield_function(L, "newPictureRecorder", lsk_newPictureRecorder); | 1925 setfield_function(L, "newPictureRecorder", lsk_newPictureRecorder); |
1878 setfield_function(L, "newRRect", lsk_newRRect); | 1926 setfield_function(L, "newRRect", lsk_newRRect); |
1879 setfield_function(L, "newRasterSurface", lsk_newRasterSurface); | 1927 setfield_function(L, "newRasterSurface", lsk_newRasterSurface); |
| 1928 setfield_function(L, "newTextBlob", lsk_newTextBlob); |
1880 setfield_function(L, "newTypeface", lsk_newTypeface); | 1929 setfield_function(L, "newTypeface", lsk_newTypeface); |
1881 lua_pop(L, 1); // pop off the Sk table | 1930 lua_pop(L, 1); // pop off the Sk table |
1882 } | 1931 } |
1883 | 1932 |
1884 #define REG_CLASS(L, C) \ | 1933 #define REG_CLASS(L, C) \ |
1885 do { \ | 1934 do { \ |
1886 luaL_newmetatable(L, get_mtname<C>()); \ | 1935 luaL_newmetatable(L, get_mtname<C>()); \ |
1887 lua_pushvalue(L, -1); \ | 1936 lua_pushvalue(L, -1); \ |
1888 lua_setfield(L, -2, "__index"); \ | 1937 lua_setfield(L, -2, "__index"); \ |
1889 luaL_setfuncs(L, g##C##_Methods, 0); \ | 1938 luaL_setfuncs(L, g##C##_Methods, 0); \ |
1890 lua_pop(L, 1); /* pop off the meta-table */ \ | 1939 lua_pop(L, 1); /* pop off the meta-table */ \ |
1891 } while (0) | 1940 } while (0) |
1892 | 1941 |
1893 void SkLua::Load(lua_State* L) { | 1942 void SkLua::Load(lua_State* L) { |
1894 register_Sk(L); | 1943 register_Sk(L); |
1895 REG_CLASS(L, SkCanvas); | 1944 REG_CLASS(L, SkCanvas); |
1896 REG_CLASS(L, SkDocument); | 1945 REG_CLASS(L, SkDocument); |
1897 REG_CLASS(L, SkImage); | 1946 REG_CLASS(L, SkImage); |
1898 REG_CLASS(L, SkImageFilter); | 1947 REG_CLASS(L, SkImageFilter); |
| 1948 REG_CLASS(L, SkMatrix); |
1899 REG_CLASS(L, SkPaint); | 1949 REG_CLASS(L, SkPaint); |
1900 REG_CLASS(L, SkPath); | 1950 REG_CLASS(L, SkPath); |
1901 REG_CLASS(L, SkPathEffect); | 1951 REG_CLASS(L, SkPathEffect); |
1902 REG_CLASS(L, SkPicture); | 1952 REG_CLASS(L, SkPicture); |
1903 REG_CLASS(L, SkPictureRecorder); | 1953 REG_CLASS(L, SkPictureRecorder); |
1904 REG_CLASS(L, SkRRect); | 1954 REG_CLASS(L, SkRRect); |
1905 REG_CLASS(L, SkShader); | 1955 REG_CLASS(L, SkShader); |
1906 REG_CLASS(L, SkSurface); | 1956 REG_CLASS(L, SkSurface); |
| 1957 REG_CLASS(L, SkTextBlob); |
1907 REG_CLASS(L, SkTypeface); | 1958 REG_CLASS(L, SkTypeface); |
1908 REG_CLASS(L, SkMatrix); | |
1909 } | 1959 } |
1910 | 1960 |
1911 extern "C" int luaopen_skia(lua_State* L); | 1961 extern "C" int luaopen_skia(lua_State* L); |
1912 extern "C" int luaopen_skia(lua_State* L) { | 1962 extern "C" int luaopen_skia(lua_State* L) { |
1913 SkLua::Load(L); | 1963 SkLua::Load(L); |
1914 return 0; | 1964 return 0; |
1915 } | 1965 } |
OLD | NEW |