diff --git a/.github/workflows/arm.yml b/.github/workflows/arm.yml index 6bb28247e..120561ca2 100644 --- a/.github/workflows/arm.yml +++ b/.github/workflows/arm.yml @@ -19,6 +19,7 @@ jobs: - name: Configure CMake run: | cmake -S . -B build \ + -DBUILD_SHARED_LIBS=OFF \ -DCMAKE_TOOLCHAIN_FILE=${DEVKITPRO}/cmake/3DS.cmake - name: Build run: make CXX_FLAGS="-w -DHB_NO_MT" diff --git a/.github/workflows/scorecard.yml b/.github/workflows/scorecard.yml index 608f6f3a4..1db98f57c 100644 --- a/.github/workflows/scorecard.yml +++ b/.github/workflows/scorecard.yml @@ -59,6 +59,6 @@ jobs: # Upload the results to GitHub's code scanning dashboard. - name: "Upload to code-scanning" - uses: github/codeql-action/upload-sarif@ff2f1c621b7f889edc0d3c761ac2e6a3f8cdb0dd # v4.37.7 + uses: github/codeql-action/upload-sarif@cdf488f595d80d6e07e03d4674febd5ab45fa938 # v4.37.9 with: sarif_file: results.sarif diff --git a/CMakeLists.txt b/CMakeLists.txt index a9359a369..762d36b96 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -175,7 +175,17 @@ set (HB_VERSION_MINOR ${CMAKE_MATCH_3}) set (HB_VERSION_MICRO ${CMAKE_MATCH_4}) ## Define sources and headers of the project -set (project_sources ${PROJECT_SOURCE_DIR}/src/harfbuzz.cc) # use amalgam source +# Keep sources in separate archive members so duplicate internal sources in +# dependent static libraries do not result in multiple definitions. +set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS + ${PROJECT_SOURCE_DIR}/src/harfbuzz.cc) +file(STRINGS ${PROJECT_SOURCE_DIR}/src/harfbuzz.cc project_source_includes + REGEX "^#include \".*\\.cc\"$") +foreach (project_source_include IN LISTS project_source_includes) + string(REGEX REPLACE "^#include \"(.*\\.cc)\"$" "\\1" + project_source ${project_source_include}) + list(APPEND project_sources ${PROJECT_SOURCE_DIR}/src/${project_source}) +endforeach () set (subset_project_sources ${PROJECT_SOURCE_DIR}/src/OT/Var/VARC/VARC.cc ${PROJECT_SOURCE_DIR}/src/OT/Var/VARC/VARC-subset.hh @@ -210,6 +220,7 @@ set (subset_project_sources ${PROJECT_SOURCE_DIR}/src/hb-subset.cc ${PROJECT_SOURCE_DIR}/src/hb-subset.hh ${PROJECT_SOURCE_DIR}/src/hb-repacker.hh + ${PROJECT_SOURCE_DIR}/src/hb-result.hh ${PROJECT_SOURCE_DIR}/src/graph/graph.hh ${PROJECT_SOURCE_DIR}/src/graph/gsubgpos-graph.hh ${PROJECT_SOURCE_DIR}/src/graph/gsubgpos-context.hh @@ -639,7 +650,7 @@ if (HB_BUILD_SUBSET) if (MINGW) target_compile_options(harfbuzz-subset PRIVATE "-Wa,-mbig-obj") endif() - + if (BUILD_SHARED_LIBS) if (BUILD_FRAMEWORK) set_target_properties(harfbuzz harfbuzz-subset PROPERTIES @@ -1256,7 +1267,7 @@ if (NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL) ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR} + FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT runtime OPTIONAL ) make_pkgconfig_pc_file("harfbuzz-gobject") diff --git a/NEWS b/NEWS index 490808bcd..04133500e 100644 --- a/NEWS +++ b/NEWS @@ -1,12 +1,62 @@ +Overview of changes leading to 14.4.0 +Wednesday, August 26, 2026 +===================================== +- Glyph positions and extents now saturate instead of overflowing. +- Arabic Windows-1256 fallback shaping is now enabled on all platforms. +- Fix cluster values and a dropped glyph advance in the Graphite shaper. +- Fix `avar` axis value mapping in fonts that repeat the boundary entries. +- Fix `avar` version 2 partial instancing. +- Fix `COLR` sweep gradient truncation and unbounded memory use. +- Faster subsetting, especially for large `GSUB`/`GPOS` and `CFF` tables. +- Faster extraction of the experimental glyph dependency graph. +- Various shaping speedups. +- Various fixes for crashes and hangs with malformed fonts. +- Various fixes to the experimental raster, vector, and GPU libraries. +- Various improvements to the HarfRust integration shaper. +- The DirectWrite backend no longer uses the C++ runtime. +- Various build, portability, and fuzzing fixes. + +- New API: + +hb_set_intersects() + + Overview of changes leading to 14.3.1 Thursday, August 13, 2026 ===================================== - Various fuzzing and build fixes. +- Add public draw and paint work-budget APIs. Rendering backends can expose a + persistent policy and a live counter so nested outline traversal consumes the + same finite budget as emitted output. - Various subsetting fixes. - Fix AAT insertion at the end of the text. - Fix various rendering bugs in the experimental GPU library. - WASM shaper code can now read the user features. +- New API: + * Common: + +HB_BUDGET_DEFAULT + +HB_BUDGET_UNLIMITED + * Draw: + +hb_draw_set_budget_func_t + +hb_draw_get_budget_func_t + +hb_draw_get_budget_remaining_func_t + +hb_draw_funcs_set_set_budget_func() + +hb_draw_funcs_set_get_budget_func() + +hb_draw_funcs_set_get_budget_remaining_func() + +hb_draw_set_budget() + +hb_draw_get_budget() + +hb_draw_get_budget_remaining() + * Paint: + +hb_paint_set_budget_func_t + +hb_paint_get_budget_func_t + +hb_paint_get_budget_remaining_func_t + +hb_paint_funcs_set_set_budget_func() + +hb_paint_funcs_set_get_budget_func() + +hb_paint_funcs_set_get_budget_remaining_func() + +hb_paint_set_budget() + +hb_paint_get_budget() + +hb_paint_get_budget_remaining() + Overview of changes leading to 14.3.0 Friday, July 31, 2026 diff --git a/docs/harfbuzz-docs.xml b/docs/harfbuzz-docs.xml index 224e1ceae..5423a8c05 100644 --- a/docs/harfbuzz-docs.xml +++ b/docs/harfbuzz-docs.xml @@ -137,6 +137,7 @@ API Index Index of deprecated API + Index of new symbols in 14.4.0 Index of new symbols in 14.3.0 Index of new symbols in 14.2.0 Index of new symbols in 14.1.0 diff --git a/docs/harfbuzz-sections.txt b/docs/harfbuzz-sections.txt index 5537e7b67..a4ccec17f 100644 --- a/docs/harfbuzz-sections.txt +++ b/docs/harfbuzz-sections.txt @@ -126,6 +126,8 @@ hb_buffer_diff_flags_t
hb-common +HB_BUDGET_DEFAULT +HB_BUDGET_UNLIMITED HB_TAG HB_UNTAG hb_tag_from_string @@ -235,6 +237,15 @@ hb_draw_cubic_to_func_t hb_draw_funcs_set_cubic_to_func hb_draw_close_path_func_t hb_draw_funcs_set_close_path_func +hb_draw_set_budget_func_t +hb_draw_funcs_set_set_budget_func +hb_draw_get_budget_func_t +hb_draw_funcs_set_get_budget_func +hb_draw_get_budget_remaining_func_t +hb_draw_funcs_set_get_budget_remaining_func +hb_draw_set_budget +hb_draw_get_budget +hb_draw_get_budget_remaining hb_draw_move_to hb_draw_line_to hb_draw_quadratic_to @@ -261,6 +272,16 @@ hb_paint_funcs_get_user_data hb_paint_funcs_make_immutable hb_paint_funcs_is_immutable +hb_paint_set_budget_func_t +hb_paint_funcs_set_set_budget_func +hb_paint_get_budget_func_t +hb_paint_funcs_set_get_budget_func +hb_paint_get_budget_remaining_func_t +hb_paint_funcs_set_get_budget_remaining_func +hb_paint_set_budget +hb_paint_get_budget +hb_paint_get_budget_remaining + hb_paint_push_transform_func_t hb_paint_funcs_set_push_transform_func hb_paint_pop_transform_func_t diff --git a/meson.build b/meson.build index 71cba6bd8..3497294b5 100644 --- a/meson.build +++ b/meson.build @@ -1,6 +1,6 @@ project('harfbuzz', ['c', 'cpp'], meson_version: '>= 0.60.0', - version: '14.3.1', + version: '14.4.0', default_options: [ 'cpp_eh=none', # Just to support msvc, we are passing -fno-exceptions also anyway # 'cpp_rtti=false', # Do NOT enable, wraps inherit it and ICU needs RTTI diff --git a/perf/benchmark-set.cc b/perf/benchmark-set.cc index 098082186..ede90facd 100644 --- a/perf/benchmark-set.cc +++ b/perf/benchmark-set.cc @@ -118,6 +118,28 @@ BENCHMARK(BM_SetIteration) {{1 << 10, 1 << 16}, // Set Size {2, 512}}); // Density +/* Range iteration of sets of varying sizes. */ +static void BM_SetNextRange(benchmark::State& state) { + unsigned set_size = state.range(0); + unsigned max_value = state.range(0) * state.range(1); + + hb_set_t* original = hb_set_create (); + RandomSet(set_size, max_value, original); + assert(hb_set_get_population(original) == set_size); + + hb_codepoint_t first = HB_SET_VALUE_INVALID; + hb_codepoint_t last = HB_SET_VALUE_INVALID; + for (auto _ : state) { + hb_set_next_range (original, &first, &last); + } + + hb_set_destroy(original); +} +BENCHMARK(BM_SetNextRange) + ->Ranges( + {{1 << 10, 1 << 16}, // Set Size + {2, 512}}); // Density + /* Set copy. */ static void BM_SetCopy(benchmark::State& state) { unsigned set_size = state.range(0); diff --git a/perf/benchmark-shape.cc b/perf/benchmark-shape.cc index ad8ee3c68..a185522c6 100644 --- a/perf/benchmark-shape.cc +++ b/perf/benchmark-shape.cc @@ -43,7 +43,9 @@ struct test_input_t static test_input_t *tests = default_tests; static unsigned num_tests = sizeof (default_tests) / sizeof (default_tests[0]); -const char *variation = nullptr; +static const char *variations_string = nullptr; +static hb_variation_t *variations = nullptr; +static unsigned num_variations = 0; const char *direction = nullptr; static bool shape (hb_buffer_t *buf, @@ -83,12 +85,8 @@ static void BM_Shape (benchmark::State &state, hb_face_destroy (face); } - if (variation) - { - hb_variation_t var; - hb_variation_from_string (variation, -1, &var); - hb_font_set_variations (font, &var, 1); - } + if (variations) + hb_font_set_variations (font, variations, num_variations); hb_blob_t *text_blob = hb_blob_create_from_file_or_fail (input.text_path); assert (text_blob); @@ -137,21 +135,48 @@ static void test_shaper (const char *shaper, ->Unit(benchmark::kMillisecond); } -static const char *font_file = nullptr; -static const char *text_file = nullptr; +static bool +parse_variations () +{ + if (!variations_string || !*variations_string) + return true; + + const char *p = variations_string; + while (p) + { + num_variations++; + p = strchr (p, ','); + if (p) p++; + } + + variations = (hb_variation_t *) calloc (num_variations, sizeof (*variations)); + if (!variations) + return false; + + p = variations_string; + num_variations = 0; + while (p) + { + const char *end = strchr (p, ','); + if (hb_variation_from_string (p, end ? end - p : -1, + &variations[num_variations])) + num_variations++; + p = end ? end + 1 : nullptr; + } + + return true; +} static GOptionEntry entries[] = { - {"font-file", 0, 0, G_OPTION_ARG_STRING, &font_file, "Font file-path to benchmark", "FONTFILE"}, - {"text-file", 0, 0, G_OPTION_ARG_STRING, &text_file, "Text file-path to benchmark", "TEXTFILE"}, - {"variations", 0, 0, G_OPTION_ARG_STRING, &variation, "Variations to apply during shaping", "VARIATIONS"}, + {"variations", 0, 0, G_OPTION_ARG_STRING, &variations_string, "Comma-separated font variations to apply during shaping", "VARIATIONS"}, {"direction", 0, 0, G_OPTION_ARG_STRING, &direction, "Direction to apply during shaping", "DIRECTION"}, {nullptr} }; static void print_usage (const char *prgname) { - g_print ("Usage: %s [OPTIONS] [FONTFILE]\n", prgname); + g_print ("Usage: %s [OPTIONS] [FONTFILE TEXTFILE]...\n", prgname); } int main(int argc, char** argv) @@ -191,39 +216,41 @@ int main(int argc, char** argv) argc--; argv++; - if (!font_file && argc) + if (argc % 2) { - font_file = *argv; - argv++; - argc--; - } - if (!text_file && argc) - { - text_file = *argv; - argv++; - argc--; - } - - if (argc) - { - g_printerr ("Unexpected arguments: "); - for (int i = 0; i < argc; i++) - g_printerr ("%s ", argv[i]); - g_printerr ("\n\n"); + g_printerr ("Font and text files must be provided in pairs.\n\n"); print_usage (prgname); return 1; } - test_input_t static_test = {}; - if (font_file && text_file) + unsigned custom_num_tests = argc / 2; + if (custom_num_tests) { - if (font_file && text_file) + tests = (test_input_t *) calloc (custom_num_tests, sizeof (*tests)); + if (!tests) { - static_test.font_path = font_file; - static_test.text_path = text_file; - tests = &static_test; - num_tests = 1; + g_printerr ("Failed to allocate test inputs.\n"); + return 1; } + + unsigned i = 0; + while (argc) + { + tests[i].font_path = argv[0]; + tests[i].text_path = argv[1]; + i++; + argc -= 2; + argv += 2; + } + num_tests = custom_num_tests; + } + + if (!parse_variations ()) + { + g_printerr ("Failed to allocate font variations.\n"); + if (tests != default_tests) + free (tests); + return 1; } for (unsigned i = 0; i < num_tests; i++) @@ -236,4 +263,8 @@ int main(int argc, char** argv) benchmark::RunSpecifiedBenchmarks(); benchmark::Shutdown(); + + free (variations); + if (tests != default_tests) + free (tests); } diff --git a/perf/texts/COPYING b/perf/texts/COPYING new file mode 100644 index 000000000..f91f8ee62 --- /dev/null +++ b/perf/texts/COPYING @@ -0,0 +1,31 @@ +ja-runs.txt +=========== + +Derived from the copyright-expired Japanese novel "Wagahai wa Neko de +Aru" (吾輩は猫である) by Natsume Soseki (夏目漱石), first published in +1905 and 1906. The source text was prepared and distributed by Aozora +Bunko, which permits free reproduction, redistribution, sharing, and +adaptation of its copyright-expired files: + + https://www.aozora.gr.jp/guide/kijyunn.html + +Work and source-file information: + + https://www.aozora.gr.jp/cards/000148/card789.html + https://www.aozora.gr.jp/cards/000148/files/789_ruby_5639.zip + +Downloaded source ZIP SHA-256: + + 6545750b89ee2c57f215a65079eeab56ee7c997373b7b86e5b00ae74fe69208f + +Source edition: "Natsume Soseki Zenshu 1", Chikuma Bunko, Chikuma +Shobo, first printing dated September 29, 1987. Text entered by +柴田卓治. Proofread by 渡部峰子, おのしげひこ, 田尻幹二, +高橋真也, しず, and 瀬戸さえ子. + +For this performance corpus, the Shift-JIS source was converted to +UTF-8; its header, footer, ruby readings, and Aozora annotations were +removed; and a 100,000-character sample of Han, Hiragana, Katakana, or +Inherited characters was retained from the beginning of the work. Each +line is one Unicode-script run. Common and other scripts are omitted +and act as run boundaries. diff --git a/perf/texts/ja-runs.txt b/perf/texts/ja-runs.txt new file mode 100644 index 000000000..5b373d6e8 --- /dev/null +++ b/perf/texts/ja-runs.txt @@ -0,0 +1,45245 @@ +一 +吾輩 +は +猫 +である +名前 +はまだ +無 +い +どこで +生 +れたかとんと +見当 +がつかぬ +何 +でも +薄暗 +いじめじめした +所 +で +ニャ +ニャ +泣 +いていた +事 +だけは +記憶 +している +吾輩 +はここで +始 +めて +人間 +というものを +見 +た +しかもあとで +聞 +くとそれは +書生 +という +人間中 +で +一番獰悪 +な +種族 +であったそうだ +この +書生 +というのは +時々我々 +を +捕 +えて +煮 +て +食 +うという +話 +である +しかしその +当時 +は +何 +という +考 +もなかったから +別段恐 +しいとも +思 +わなかった +ただ +彼 +の +掌 +に +載 +せられて +ス +と +持 +ち +上 +げられた +時何 +だか +フワフワ +した +感 +じがあったばかりである +掌 +の +上 +で +少 +し +落 +ちついて +書生 +の +顔 +を +見 +たのがいわゆる +人間 +というものの +見始 +であろう +この +時妙 +なものだと +思 +った +感 +じが +今 +でも +残 +っている +第一毛 +をもって +装飾 +されべきはずの +顔 +がつるつるしてまるで +薬缶 +だ +その +後猫 +にもだいぶ +逢 +ったがこんな +片輪 +には +一度 +も +出会 +わした +事 +がない +のみならず +顔 +の +真中 +があまりに +突起 +している +そうしてその +穴 +の +中 +から +時々 +ぷうぷうと +煙 +を +吹 +く +どうも +咽 +せぽくて +実 +に +弱 +った +これが +人間 +の +飲 +む +煙草 +というものである +事 +はようやくこの +頃知 +った +この +書生 +の +掌 +の +裏 +でしばらくはよい +心持 +に +坐 +っておったが +しばらくすると +非常 +な +速力 +で +運転 +し +始 +めた +書生 +が +動 +くのか +自分 +だけが +動 +くのか +分 +らないが +無暗 +に +眼 +が +廻 +る +胸 +が +悪 +くなる +到底助 +からないと +思 +っていると +どさりと +音 +がして +眼 +から +火 +が +出 +た +それまでは +記憶 +しているがあとは +何 +の +事 +やらいくら +考 +え +出 +そうとしても +分 +らない +ふと +気 +が +付 +いて +見 +ると +書生 +はいない +たくさんおった +兄弟 +が +一疋 +も +見 +えぬ +肝心 +の +母親 +さえ +姿 +を +隠 +してしまった +その +上今 +までの +所 +とは +違 +って +無暗 +に +明 +るい +眼 +を +明 +いていられぬくらいだ +はてな +何 +でも +容子 +がおかしいと +のそのそ +這 +い +出 +して +見 +ると +非常 +に +痛 +い +吾輩 +は +藁 +の +上 +から +急 +に +笹原 +の +中 +へ +棄 +てられたのである +ようやくの +思 +いで +笹原 +を +這 +い +出 +すと +向 +うに +大 +きな +池 +がある +吾輩 +は +池 +の +前 +に +坐 +ってどうしたらよかろうと +考 +えて +見 +た +別 +にこれという +分別 +も +出 +ない +しばらくして +泣 +いたら +書生 +がまた +迎 +に +来 +てくれるかと +考 +え +付 +いた +ニャ +ニャ +と +試 +みにやって +見 +たが +誰 +も +来 +ない +そのうち +池 +の +上 +をさらさらと +風 +が +渡 +って +日 +が +暮 +れかかる +腹 +が +非常 +に +減 +って +来 +た +泣 +きたくても +声 +が +出 +ない +仕方 +がない +何 +でもよいから +食物 +のある +所 +まであるこうと +決心 +をしてそろりそろりと +池 +を +左 +りに +廻 +り +始 +めた +どうも +非常 +に +苦 +しい +そこを +我慢 +して +無理 +やりに +這 +って +行 +くとようやくの +事 +で +何 +となく +人間臭 +い +所 +へ +出 +た +ここへ +這入 +ったら +どうにかなると +思 +って +竹垣 +の +崩 +れた +穴 +から +とある +邸内 +にもぐり +込 +んだ +縁 +は +不思議 +なもので +もしこの +竹垣 +が +破 +れていなかったなら +吾輩 +はついに +路傍 +に +餓死 +したかも +知 +れんのである +一樹 +の +蔭 +とはよく +云 +ったものだ +この +垣根 +の +穴 +は +今日 +に +至 +るまで +吾輩 +が +隣家 +の +三毛 +を +訪問 +する +時 +の +通路 +になっている +さて +邸 +へは +忍 +び +込 +んだもののこれから +先 +どうして +善 +いか +分 +らない +そのうちに +暗 +くなる +腹 +は +減 +る +寒 +さは +寒 +し +雨 +が +降 +って +来 +るという +始末 +でもう +一刻 +の +猶予 +が +出来 +なくなった +仕方 +がないからとにかく +明 +るくて +暖 +かそうな +方 +へ +方 +へとあるいて +行 +く +今 +から +考 +えるとその +時 +はすでに +家 +の +内 +に +這入 +っておったのだ +ここで +吾輩 +は +彼 +の +書生以外 +の +人間 +を +再 +び +見 +るべき +機会 +に +遭遇 +したのである +第一 +に +逢 +ったのがおさんである +これは +前 +の +書生 +より +一層乱暴 +な +方 +で +吾輩 +を +見 +るや +否 +やいきなり +頸筋 +をつかんで +表 +へ +抛 +り +出 +した +いやこれは +駄目 +だと +思 +ったから +眼 +をねぶって +運 +を +天 +に +任 +せていた +しかしひもじいのと +寒 +いのにはどうしても +我慢 +が +出来 +ん +吾輩 +は +再 +びおさんの +隙 +を +見 +て +台所 +へ +這 +い +上 +った +すると +間 +もなくまた +投 +げ +出 +された +吾輩 +は +投 +げ +出 +されては +這 +い +上 +り +這 +い +上 +っては +投 +げ +出 +され +何 +でも +同 +じ +事 +を +四五遍繰 +り +返 +したのを +記憶 +している +その +時 +におさんと +云 +う +者 +はつくづくいやになった +この +間 +おさんの +三馬 +を +偸 +んでこの +返報 +をしてやってから +やっと +胸 +の +痞 +が +下 +りた +吾輩 +が +最後 +につまみ +出 +されようとしたときに +この +家 +の +主人 +が +騒々 +しい +何 +だといいながら +出 +て +来 +た +下女 +は +吾輩 +をぶら +下 +げて +主人 +の +方 +へ +向 +けてこの +宿 +なしの +小猫 +がいくら +出 +しても +出 +しても +御台所 +へ +上 +って +来 +て +困 +りますという +主人 +は +鼻 +の +下 +の +黒 +い +毛 +を +撚 +りながら +吾輩 +の +顔 +をしばらく +眺 +めておったが +やがてそんなら +内 +へ +置 +いてやれといったまま +奥 +へ +這入 +ってしまった +主人 +はあまり +口 +を +聞 +かぬ +人 +と +見 +えた +下女 +は +口惜 +しそうに +吾輩 +を +台所 +へ +抛 +り +出 +した +かくして +吾輩 +はついにこの +家 +を +自分 +の +住家 +と +極 +める +事 +にしたのである +吾輩 +の +主人 +は +滅多 +に +吾輩 +と +顔 +を +合 +せる +事 +がない +職業 +は +教師 +だそうだ +学校 +から +帰 +ると +終日書斎 +に +這入 +ったぎりほとんど +出 +て +来 +る +事 +がない +家 +のものは +大変 +な +勉強家 +だと +思 +っている +当人 +も +勉強家 +であるかのごとく +見 +せている +しかし +実際 +はうちのものがいうような +勤勉家 +ではない +吾輩 +は +時々忍 +び +足 +に +彼 +の +書斎 +を +覗 +いて +見 +るが +彼 +はよく +昼寝 +をしている +事 +がある +時々読 +みかけてある +本 +の +上 +に +涎 +をたらしている +彼 +は +胃弱 +で +皮膚 +の +色 +が +淡黄色 +を +帯 +びて +弾力 +のない +不活溌 +な +徴候 +をあらわしている +その +癖 +に +大飯 +を +食 +う +大飯 +を +食 +った +後 +で +タカジヤスタ +ゼ +を +飲 +む +飲 +んだ +後 +で +書物 +をひろげる +二三 +ペ +ジ +読 +むと +眠 +くなる +涎 +を +本 +の +上 +へ +垂 +らす +これが +彼 +の +毎夜繰 +り +返 +す +日課 +である +吾輩 +は +猫 +ながら +時々考 +える +事 +がある +教師 +というものは +実 +に +楽 +なものだ +人間 +と +生 +れたら +教師 +となるに +限 +る +こんなに +寝 +ていて +勤 +まるものなら +猫 +にでも +出来 +ぬ +事 +はないと +それでも +主人 +に +云 +わせると +教師 +ほどつらいものはないそうで +彼 +は +友達 +が +来 +る +度 +に +何 +とかかんとか +不平 +を +鳴 +らしている +吾輩 +がこの +家 +へ +住 +み +込 +んだ +当時 +は +主人以外 +のものにははなはだ +不人望 +であった +どこへ +行 +っても +跳 +ね +付 +けられて +相手 +にしてくれ +手 +がなかった +いかに +珍重 +されなかったかは +今日 +に +至 +るまで +名前 +さえつけてくれないのでも +分 +る +吾輩 +は +仕方 +がないから +出来得 +る +限 +り +吾輩 +を +入 +れてくれた +主人 +の +傍 +にいる +事 +をつとめた +朝主人 +が +新聞 +を +読 +むときは +必 +ず +彼 +の +膝 +の +上 +に +乗 +る +彼 +が +昼寝 +をするときは +必 +ずその +背中 +に +乗 +る +これはあながち +主人 +が +好 +きという +訳 +ではないが +別 +に +構 +い +手 +がなかったからやむを +得 +んのである +その +後 +いろいろ +経験 +の +上 +朝 +は +飯櫃 +の +上 +夜 +は +炬燵 +の +上 +天気 +のよい +昼 +は +椽側 +へ +寝 +る +事 +とした +しかし +一番心持 +の +好 +いのは +夜 +に +入 +ってここのうちの +小供 +の +寝床 +へもぐり +込 +んでいっしょにねる +事 +である +この +小供 +というのは +五 +つと +三 +つで +夜 +になると +二人 +が +一 +つ +床 +へ +入 +って +一間 +へ +寝 +る +吾輩 +はいつでも +彼等 +の +中間 +に +己 +れを +容 +るべき +余地 +を +見出 +してどうにか +こうにか +割 +り +込 +むのであるが +運悪 +く +小供 +の +一人 +が +眼 +を +醒 +ますが +最後大変 +な +事 +になる +小供 +は +ことに +小 +さい +方 +が +質 +がわるい +猫 +が +来 +た +猫 +が +来 +たといって +夜中 +でも +何 +でも +大 +きな +声 +で +泣 +き +出 +すのである +すると +例 +の +神経胃弱性 +の +主人 +は +必 +ず +眼 +をさまして +次 +の +部屋 +から +飛 +び +出 +してくる +現 +にせんだってなどは +物指 +で +尻 +ぺたをひどく +叩 +かれた +吾輩 +は +人間 +と +同居 +して +彼等 +を +観察 +すればするほど +彼等 +は +我儘 +なものだと +断言 +せざるを +得 +ないようになった +ことに +吾輩 +が +時々同衾 +する +小供 +のごときに +至 +っては +言語同断 +である +自分 +の +勝手 +な +時 +は +人 +を +逆 +さにしたり +頭 +へ +袋 +をかぶせたり +抛 +り +出 +したり +へっついの +中 +へ +押 +し +込 +んだりする +しかも +吾輩 +の +方 +で +少 +しでも +手出 +しをしようものなら +家内総 +がかりで +追 +い +廻 +して +迫害 +を +加 +える +この +間 +もちょっと +畳 +で +爪 +を +磨 +いだら +細君 +が +非常 +に +怒 +ってそれから +容易 +に +座敷 +へ +入 +れない +台所 +の +板 +の +間 +で +他 +が +顫 +えていても +一向平気 +なものである +吾輩 +の +尊敬 +する +筋向 +の +白君 +などは +逢 +う +度毎 +に +人間 +ほど +不人情 +なものはないと +言 +っておらるる +白君 +は +先日玉 +のような +子猫 +を +四疋産 +まれたのである +ところがそこの +家 +の +書生 +が +三日目 +にそいつを +裏 +の +池 +へ +持 +って +行 +って +四疋 +ながら +棄 +てて +来 +たそうだ +白君 +は +涙 +を +流 +してその +一部始終 +を +話 +した +上 +どうしても +我等猫族 +が +親子 +の +愛 +を +完 +くして +美 +しい +家族的生活 +をするには +人間 +と +戦 +ってこれを +剿滅 +せねばならぬといわれた +一々 +もっともの +議論 +と +思 +う +また +隣 +りの +三毛君 +などは +人間 +が +所有権 +という +事 +を +解 +していないといって +大 +に +憤慨 +している +元来我々同族間 +では +目刺 +の +頭 +でも +鰡 +の +臍 +でも +一番先 +に +見付 +けたものがこれを +食 +う +権利 +があるものとなっている +もし +相手 +がこの +規約 +を +守 +らなければ +腕力 +に +訴 +えて +善 +いくらいのものだ +しかるに +彼等人間 +は +毫 +もこの +観念 +がないと +見 +えて +我等 +が +見付 +けた +御馳走 +は +必 +ず +彼等 +のために +掠奪 +せらるるのである +彼等 +はその +強力 +を +頼 +んで +正当 +に +吾人 +が +食 +い +得 +べきものを +奪 +ってすましている +白君 +は +軍人 +の +家 +におり +三毛君 +は +代言 +の +主人 +を +持 +っている +吾輩 +は +教師 +の +家 +に +住 +んでいるだけ +こんな +事 +に +関 +すると +両君 +よりもむしろ +楽天 +である +ただその +日 +その +日 +がどうにかこうにか +送 +られればよい +いくら +人間 +だって +そういつまでも +栄 +える +事 +もあるまい +まあ +気 +を +永 +く +猫 +の +時節 +を +待 +つがよかろう +我儘 +で +思 +い +出 +したからちょっと +吾輩 +の +家 +の +主人 +がこの +我儘 +で +失敗 +した +話 +をしよう +元来 +この +主人 +は +何 +といって +人 +に +勝 +れて +出来 +る +事 +もないが +何 +にでもよく +手 +を +出 +したがる +俳句 +をやってほととぎすへ +投書 +をしたり +新体詩 +を +明星 +へ +出 +したり +間違 +いだらけの +英文 +をかいたり +時 +によると +弓 +に +凝 +ったり +謡 +を +習 +ったり +またあるときは +ヴァイオリン +などを +ブ +ブ +鳴 +らしたりするが +気 +の +毒 +な +事 +には +どれもこれも +物 +になっておらん +その +癖 +やり +出 +すと +胃弱 +の +癖 +にいやに +熱心 +だ +後架 +の +中 +で +謡 +をうたって +近所 +で +後架先生 +と +渾名 +をつけられているにも +関 +せず +一向平気 +なもので +やはりこれは +平 +の +宗盛 +にて +候 +を +繰返 +している +みんながそら +宗盛 +だと +吹 +き +出 +すくらいである +この +主人 +がどういう +考 +になったものか +吾輩 +の +住 +み +込 +んでから +一月 +ばかり +後 +のある +月 +の +月給日 +に +大 +きな +包 +みを +提 +げてあわただしく +帰 +って +来 +た +何 +を +買 +って +来 +たのかと +思 +うと +水彩絵具 +と +毛筆 +と +ワットマン +という +紙 +で +今日 +から +謡 +や +俳句 +をやめて +絵 +をかく +決心 +と +見 +えた +果 +して +翌日 +から +当分 +の +間 +というものは +毎日毎日書斎 +で +昼寝 +もしないで +絵 +ばかりかいている +しかしそのかき +上 +げたものを +見 +ると +何 +をかいたものやら +誰 +にも +鑑定 +がつかない +当人 +もあまり +甘 +くないと +思 +ったものか +ある +日 +その +友人 +で +美学 +とかをやっている +人 +が +来 +た +時 +に +下 +のような +話 +をしているのを +聞 +いた +どうも +甘 +くかけないものだね +人 +のを +見 +ると +何 +でもないようだが +自 +ら +筆 +をとって +見 +ると +今更 +のようにむずかしく +感 +ずる +これは +主人 +の +述懐 +である +なるほど +詐 +りのない +処 +だ +彼 +の +友 +は +金縁 +の +眼鏡越 +に +主人 +の +顔 +を +見 +ながら +そう +初 +めから +上手 +にはかけないさ +第一室内 +の +想像 +ばかりで +画 +がかける +訳 +のものではない +昔 +し +以太利 +の +大家 +アンドレア +デル +サルト +が +言 +った +事 +がある +画 +をかくなら +何 +でも +自然 +その +物 +を +写 +せ +天 +に +星辰 +あり +地 +に +露華 +あり +飛 +ぶに +禽 +あり +走 +るに +獣 +あり +池 +に +金魚 +あり +枯木 +に +寒鴉 +あり +自然 +はこれ +一幅 +の +大活画 +なりと +どうだ +君 +も +画 +らしい +画 +をかこうと +思 +うならちと +写生 +をしたら +へえ +アンドレア +デル +サルト +がそんな +事 +をいった +事 +があるかい +ちっとも +知 +らなかった +なるほどこりゃもっともだ +実 +にその +通 +りだ +と +主人 +は +無暗 +に +感心 +している +金縁 +の +裏 +には +嘲 +けるような +笑 +が +見 +えた +その +翌日吾輩 +は +例 +のごとく +椽側 +に +出 +て +心持善 +く +昼寝 +をしていたら +主人 +が +例 +になく +書斎 +から +出 +て +来 +て +吾輩 +の +後 +ろで +何 +かしきりにやっている +ふと +眼 +が +覚 +めて +何 +をしているかと +一分 +ばかり +細目 +に +眼 +をあけて +見 +ると +彼 +は +余念 +もなく +アンドレア +デル +サルト +を +極 +め +込 +んでいる +吾輩 +はこの +有様 +を +見 +て +覚 +えず +失笑 +するのを +禁 +じ +得 +なかった +彼 +は +彼 +の +友 +に +揶揄 +せられたる +結果 +としてまず +手初 +めに +吾輩 +を +写生 +しつつあるのである +吾輩 +はすでに +十分寝 +た +欠伸 +がしたくてたまらない +しかしせっかく +主人 +が +熱心 +に +筆 +を +執 +っているのを +動 +いては +気 +の +毒 +だと +思 +って +じっと +辛棒 +しておった +彼 +は +今吾輩 +の +輪廓 +をかき +上 +げて +顔 +のあたりを +色彩 +っている +吾輩 +は +自白 +する +吾輩 +は +猫 +として +決 +して +上乗 +の +出来 +ではない +背 +といい +毛並 +といい +顔 +の +造作 +といいあえて +他 +の +猫 +に +勝 +るとは +決 +して +思 +っておらん +しかしいくら +不器量 +の +吾輩 +でも +今吾輩 +の +主人 +に +描 +き +出 +されつつあるような +妙 +な +姿 +とは +どうしても +思 +われない +第一色 +が +違 +う +吾輩 +は +波斯産 +の +猫 +のごとく +黄 +を +含 +める +淡灰色 +に +漆 +のごとき +斑入 +りの +皮膚 +を +有 +している +これだけは +誰 +が +見 +ても +疑 +うべからざる +事実 +と +思 +う +しかるに +今主人 +の +彩色 +を +見 +ると +黄 +でもなければ +黒 +でもない +灰色 +でもなければ +褐色 +でもない +さればとてこれらを +交 +ぜた +色 +でもない +ただ +一種 +の +色 +であるというよりほかに +評 +し +方 +のない +色 +である +その +上不思議 +な +事 +は +眼 +がない +もっともこれは +寝 +ているところを +写生 +したのだから +無理 +もないが +眼 +らしい +所 +さえ +見 +えないから +盲猫 +だか +寝 +ている +猫 +だか +判然 +しないのである +吾輩 +は +心中 +ひそかにいくら +アンドレア +デル +サルト +でもこれではしようがないと +思 +った +しかしその +熱心 +には +感服 +せざるを +得 +ない +なるべくなら +動 +かずにおってやりたいと +思 +ったが +さっきから +小便 +が +催 +うしている +身内 +の +筋肉 +はむずむずする +最早一分 +も +猶予 +が +出来 +ぬ +仕儀 +となったから +やむをえず +失敬 +して +両足 +を +前 +へ +存分 +のして +首 +を +低 +く +押 +し +出 +してあ +あと +大 +なる +欠伸 +をした +さてこうなって +見 +ると +もうおとなしくしていても +仕方 +がない +どうせ +主人 +の +予定 +は +打 +ち +壊 +わしたのだから +ついでに +裏 +へ +行 +って +用 +を +足 +そうと +思 +ってのそのそ +這 +い +出 +した +すると +主人 +は +失望 +と +怒 +りを +掻 +き +交 +ぜたような +声 +をして +座敷 +の +中 +から +この +馬鹿野郎 +と +怒鳴 +った +この +主人 +は +人 +を +罵 +るときは +必 +ず +馬鹿野郎 +というのが +癖 +である +ほかに +悪口 +の +言 +いようを +知 +らないのだから +仕方 +がないが +今 +まで +辛棒 +した +人 +の +気 +も +知 +らないで +無暗 +に +馬鹿野郎呼 +わりは +失敬 +だと +思 +う +それも +平生吾輩 +が +彼 +の +背中 +へ +乗 +る +時 +に +少 +しは +好 +い +顔 +でもするならこの +漫罵 +も +甘 +んじて +受 +けるが +こっちの +便利 +になる +事 +は +何一 +つ +快 +くしてくれた +事 +もないのに +小便 +に +立 +ったのを +馬鹿野郎 +とは +酷 +い +元来人間 +というものは +自己 +の +力量 +に +慢 +じてみんな +増長 +している +少 +し +人間 +より +強 +いものが +出 +て +来 +て +窘 +めてやらなくてはこの +先 +どこまで +増長 +するか +分 +らない +我儘 +もこのくらいなら +我慢 +するが +吾輩 +は +人間 +の +不徳 +についてこれよりも +数倍悲 +しむべき +報道 +を +耳 +にした +事 +がある +吾輩 +の +家 +の +裏 +に +十坪 +ばかりの +茶園 +がある +広 +くはないが +瀟洒 +とした +心持 +ち +好 +く +日 +の +当 +る +所 +だ +うちの +小供 +があまり +騒 +いで +楽々昼寝 +の +出来 +ない +時 +や +あまり +退屈 +で +腹加減 +のよくない +折 +などは +吾輩 +はいつでもここへ +出 +て +浩然 +の +気 +を +養 +うのが +例 +である +ある +小春 +の +穏 +かな +日 +の +二時頃 +であったが +吾輩 +は +昼飯後快 +よく +一睡 +した +後 +運動 +かたがたこの +茶園 +へと +歩 +を +運 +ばした +茶 +の +木 +の +根 +を +一本一本嗅 +ぎながら +西側 +の +杉垣 +のそばまでくると +枯菊 +を +押 +し +倒 +してその +上 +に +大 +きな +猫 +が +前後不覚 +に +寝 +ている +彼 +は +吾輩 +の +近 +づくのも +一向心付 +かざるごとく +また +心付 +くも +無頓着 +なるごとく +大 +きな +鼾 +をして +長々 +と +体 +を +横 +えて +眠 +っている +他 +の +庭内 +に +忍 +び +入 +りたるものがかくまで +平気 +に +睡 +られるものかと +吾輩 +は +窃 +かにその +大胆 +なる +度胸 +に +驚 +かざるを +得 +なかった +彼 +は +純粋 +の +黒猫 +である +わずかに +午 +を +過 +ぎたる +太陽 +は +透明 +なる +光線 +を +彼 +の +皮膚 +の +上 +に +抛 +げかけて +きらきらする +柔毛 +の +間 +より +眼 +に +見 +えぬ +炎 +でも +燃 +え +出 +ずるように +思 +われた +彼 +は +猫中 +の +大王 +とも +云 +うべきほどの +偉大 +なる +体格 +を +有 +している +吾輩 +の +倍 +はたしかにある +吾輩 +は +嘆賞 +の +念 +と +好奇 +の +心 +に +前後 +を +忘 +れて +彼 +の +前 +に +佇立 +して +余念 +もなく +眺 +めていると +静 +かなる +小春 +の +風 +が +杉垣 +の +上 +から +出 +たる +梧桐 +の +枝 +を +軽 +く +誘 +ってばらばらと +二三枚 +の +葉 +が +枯菊 +の +茂 +みに +落 +ちた +大王 +はかっとその +真丸 +の +眼 +を +開 +いた +今 +でも +記憶 +している +その +眼 +は +人間 +の +珍重 +する +琥珀 +というものよりも +遥 +かに +美 +しく +輝 +いていた +彼 +は +身動 +きもしない +双眸 +の +奥 +から +射 +るごとき +光 +を +吾輩 +の +矮小 +なる +額 +の +上 +にあつめて +御 +めえは +一体何 +だと +云 +った +大王 +にしては +少々言葉 +が +卑 +しいと +思 +ったが +何 +しろその +声 +の +底 +に +犬 +をも +挫 +しぐべき +力 +が +籠 +っているので +吾輩 +は +少 +なからず +恐 +れを +抱 +いた +しかし +挨拶 +をしないと +険呑 +だと +思 +ったから +吾輩 +は +猫 +である +名前 +はまだない +となるべく +平気 +を +装 +って +冷然 +と +答 +えた +しかしこの +時吾輩 +の +心臓 +はたしかに +平時 +よりも +烈 +しく +鼓動 +しておった +彼 +は +大 +に +軽蔑 +せる +調子 +で +何 +猫 +だ +猫 +が +聞 +いてあきれらあ +全 +てえどこに +住 +んでるんだ +随分傍若無人 +である +吾輩 +はここの +教師 +の +家 +にいるのだ +どうせそんな +事 +だろうと +思 +った +いやに +瘠 +せてるじゃねえか +と +大王 +だけに +気焔 +を +吹 +きかける +言葉付 +から +察 +するとどうも +良家 +の +猫 +とも +思 +われない +しかしその +膏切 +って +肥満 +しているところを +見 +ると +御馳走 +を +食 +ってるらしい +豊 +かに +暮 +しているらしい +吾輩 +は +そう +云 +う +君 +は +一体誰 +だい +と +聞 +かざるを +得 +なかった +己 +れあ +車屋 +の +黒 +よ +昂然 +たるものだ +車屋 +の +黒 +はこの +近辺 +で +知 +らぬ +者 +なき +乱暴猫 +である +しかし +車屋 +だけに +強 +いばかりでちっとも +教育 +がないからあまり +誰 +も +交際 +しない +同盟敬遠主義 +の +的 +になっている +奴 +だ +吾輩 +は +彼 +の +名 +を +聞 +いて +少々尻 +こそばゆき +感 +じを +起 +すと +同時 +に +一方 +では +少々軽侮 +の +念 +も +生 +じたのである +吾輩 +はまず +彼 +がどのくらい +無学 +であるかを +試 +してみようと +思 +って +左 +の +問答 +をして +見 +た +一体車屋 +と +教師 +とはどっちがえらいだろう +車屋 +の +方 +が +強 +いに +極 +っていらあな +御 +めえのうちの +主人 +を +見 +ねえ +まるで +骨 +と +皮 +ばかりだぜ +君 +も +車屋 +の +猫 +だけに +大分強 +そうだ +車屋 +にいると +御馳走 +が +食 +えると +見 +えるね +何 +におれなんざ +どこの +国 +へ +行 +ったって +食 +い +物 +に +不自由 +はしねえつもりだ +御 +めえなんかも +茶畠 +ばかりぐるぐる +廻 +っていねえで +ちっと +己 +の +後 +へくっ +付 +いて +来 +て +見 +ねえ +一 +と +月 +とたたねえうちに +見違 +えるように +太 +れるぜ +追 +ってそう +願 +う +事 +にしよう +しかし +家 +は +教師 +の +方 +が +車屋 +より +大 +きいのに +住 +んでいるように +思 +われる +箆棒 +め +うちなんかいくら +大 +きくたって +腹 +の +足 +しになるもんか +彼 +は +大 +に +肝癪 +に +障 +った +様子 +で +寒竹 +をそいだような +耳 +をしきりとぴく +付 +かせてあららかに +立 +ち +去 +った +吾輩 +が +車屋 +の +黒 +と +知己 +になったのはこれからである +その +後吾輩 +は +度々黒 +と +邂逅 +する +邂逅 +する +毎 +に +彼 +は +車屋相当 +の +気焔 +を +吐 +く +先 +に +吾輩 +が +耳 +にしたという +不徳事件 +も +実 +は +黒 +から +聞 +いたのである +或 +る +日例 +のごとく +吾輩 +と +黒 +は +暖 +かい +茶畠 +の +中 +で +寝転 +びながらいろいろ +雑談 +をしていると +彼 +はいつもの +自慢話 +しをさも +新 +しそうに +繰 +り +返 +したあとで +吾輩 +に +向 +って +下 +のごとく +質問 +した +御 +めえは +今 +までに +鼠 +を +何匹 +とった +事 +がある +智識 +は +黒 +よりも +余程発達 +しているつもりだが +腕力 +と +勇気 +とに +至 +っては +到底黒 +の +比較 +にはならないと +覚悟 +はしていたものの +この +問 +に +接 +したる +時 +は +さすがに +極 +りが +善 +くはなかった +けれども +事実 +は +事実 +で +詐 +る +訳 +には +行 +かないから +吾輩 +は +実 +はとろうとろうと +思 +ってまだ +捕 +らない +と +答 +えた +黒 +は +彼 +の +鼻 +の +先 +からぴんと +突張 +っている +長 +い +髭 +をびりびりと +震 +わせて +非常 +に +笑 +った +元来黒 +は +自慢 +をする +丈 +にどこか +足 +りないところがあって +彼 +の +気焔 +を +感心 +したように +咽喉 +をころころ +鳴 +らして +謹聴 +していればはなはだ +御 +しやすい +猫 +である +吾輩 +は +彼 +と +近付 +になってから +直 +にこの +呼吸 +を +飲 +み +込 +んだからこの +場合 +にもなまじい +己 +れを +弁護 +してますます +形勢 +をわるくするのも +愚 +である +いっその +事彼 +に +自分 +の +手柄話 +をしゃべらして +御茶 +を +濁 +すに +若 +くはないと +思案 +を +定 +めた +そこでおとなしく +君 +などは +年 +が +年 +であるから +大分 +とったろう +とそそのかして +見 +た +果然彼 +は +墻壁 +の +欠所 +に +吶喊 +して +来 +た +たんとでもねえが +三四十 +はとったろう +とは +得意気 +なる +彼 +の +答 +であった +彼 +はなお +語 +をつづけて +鼠 +の +百 +や +二百 +は +一人 +でいつでも +引 +き +受 +けるがいたちってえ +奴 +は +手 +に +合 +わねえ +一度 +いたちに +向 +って +酷 +い +目 +に +逢 +った +へえなるほど +と +相槌 +を +打 +つ +黒 +は +大 +きな +眼 +をぱちつかせて +云 +う +去年 +の +大掃除 +の +時 +だ +うちの +亭主 +が +石灰 +の +袋 +を +持 +って +椽 +の +下 +へ +這 +い +込 +んだら +御 +めえ +大 +きないたちの +野郎 +が +面喰 +って +飛 +び +出 +したと +思 +いねえ +ふん +と +感心 +して +見 +せる +いたちってけども +何鼠 +の +少 +し +大 +きいぐれえのものだ +こん +畜生 +って +気 +で +追 +っかけてとうとう +泥溝 +の +中 +へ +追 +い +込 +んだと +思 +いねえ +うまくやったね +と +喝采 +してやる +ところが +御 +めえいざってえ +段 +になると +奴 +め +最後 +っ +屁 +をこきゃがった +臭 +えの +臭 +くねえのってそれからってえものはいたちを +見 +ると +胸 +が +悪 +くならあ +彼 +はここに +至 +ってあたかも +去年 +の +臭気 +を +今 +なお +感 +ずるごとく +前足 +を +揚 +げて +鼻 +の +頭 +を +二三遍 +なで +廻 +わした +吾輩 +も +少々気 +の +毒 +な +感 +じがする +ちっと +景気 +を +付 +けてやろうと +思 +って +しかし +鼠 +なら +君 +に +睨 +まれては +百年目 +だろう +君 +はあまり +鼠 +を +捕 +るのが +名人 +で +鼠 +ばかり +食 +うものだからそんなに +肥 +って +色 +つやが +善 +いのだろう +黒 +の +御機嫌 +をとるためのこの +質問 +は +不思議 +にも +反対 +の +結果 +を +呈出 +した +彼 +は +喟然 +として +大息 +していう +考 +げえるとつまらねえ +いくら +稼 +いで +鼠 +をとったって +一 +てえ +人間 +ほどふてえ +奴 +は +世 +の +中 +にいねえぜ +人 +のとった +鼠 +をみんな +取 +り +上 +げやがって +交番 +へ +持 +って +行 +きゃあがる +交番 +じゃ +誰 +が +捕 +ったか +分 +らねえからそのたんびに +五銭 +ずつくれるじゃねえか +うちの +亭主 +なんか +己 +の +御蔭 +でもう +壱円五十銭 +くらい +儲 +けていやがる +癖 +に +碌 +なものを +食 +わせた +事 +もありゃしねえ +おい +人間 +てものあ +体 +の +善 +い +泥棒 +だぜ +さすが +無学 +の +黒 +もこのくらいの +理窟 +はわかると +見 +えてすこぶる +怒 +った +容子 +で +背中 +の +毛 +を +逆立 +てている +吾輩 +は +少々気味 +が +悪 +くなったから +善 +い +加減 +にその +場 +を +胡魔化 +して +家 +へ +帰 +った +この +時 +から +吾輩 +は +決 +して +鼠 +をとるまいと +決心 +した +しかし +黒 +の +子分 +になって +鼠以外 +の +御馳走 +を +猟 +ってあるく +事 +もしなかった +御馳走 +を +食 +うよりも +寝 +ていた +方 +が +気楽 +でいい +教師 +の +家 +にいると +猫 +も +教師 +のような +性質 +になると +見 +える +要心 +しないと +今 +に +胃弱 +になるかも +知 +れない +教師 +といえば +吾輩 +の +主人 +も +近頃 +に +至 +っては +到底水彩画 +において +望 +のない +事 +を +悟 +ったものと +見 +えて +十二月一日 +の +日記 +にこんな +事 +をかきつけた +と +云 +う +人 +に +今日 +の +会 +で +始 +めて +出逢 +った +あの +人 +は +大分放蕩 +をした +人 +だと +云 +うがなるほど +通人 +らしい +風采 +をしている +こう +云 +う +質 +の +人 +は +女 +に +好 +かれるものだから +が +放蕩 +をしたと +云 +うよりも +放蕩 +をするべく +余儀 +なくせられたと +云 +うのが +適当 +であろう +あの +人 +の +妻君 +は +芸者 +だそうだ +羨 +ましい +事 +である +元来放蕩家 +を +悪 +くいう +人 +の +大部分 +は +放蕩 +をする +資格 +のないものが +多 +い +また +放蕩家 +をもって +自任 +する +連中 +のうちにも +放蕩 +する +資格 +のないものが +多 +い +これらは +余儀 +なくされないのに +無理 +に +進 +んでやるのである +あたかも +吾輩 +の +水彩画 +に +於 +けるがごときもので +到底卒業 +する +気 +づかいはない +しかるにも +関 +せず +自分 +だけは +通人 +だと +思 +って +済 +している +料理屋 +の +酒 +を +飲 +んだり +待合 +へ +這入 +るから +通人 +となり +得 +るという +論 +が +立 +つなら +吾輩 +も +一廉 +の +水彩画家 +になり +得 +る +理窟 +だ +吾輩 +の +水彩画 +のごときはかかない +方 +がましであると +同 +じように +愚昧 +なる +通人 +よりも +山出 +しの +大野暮 +の +方 +が +遥 +かに +上等 +だ +通人論 +はちょっと +首肯 +しかねる +また +芸者 +の +妻君 +を +羨 +しいなどというところは +教師 +としては +口 +にすべからざる +愚劣 +の +考 +であるが +自己 +の +水彩画 +における +批評眼 +だけはたしかなものだ +主人 +はかくのごとく +自知 +の +明 +あるにも +関 +せずその +自惚心 +はなかなか +抜 +けない +中二日置 +いて +十二月四日 +の +日記 +にこんな +事 +を +書 +いている +昨夜 +は +僕 +が +水彩画 +をかいて +到底物 +にならんと +思 +って +そこらに +抛 +って +置 +いたのを +誰 +かが +立派 +な +額 +にして +欄間 +に +懸 +けてくれた +夢 +を +見 +た +さて +額 +になったところを +見 +ると +我 +ながら +急 +に +上手 +になった +非常 +に +嬉 +しい +これなら +立派 +なものだと +独 +りで +眺 +め +暮 +らしていると +夜 +が +明 +けて +眼 +が +覚 +めてやはり +元 +の +通 +り +下手 +である +事 +が +朝日 +と +共 +に +明瞭 +になってしまった +主人 +は +夢 +の +裡 +まで +水彩画 +の +未練 +を +背負 +ってあるいていると +見 +える +これでは +水彩画家 +は +無論夫子 +の +所謂通人 +にもなれない +質 +だ +主人 +が +水彩画 +を +夢 +に +見 +た +翌日例 +の +金縁眼鏡 +の +美学者 +が +久 +し +振 +りで +主人 +を +訪問 +した +彼 +は +座 +につくと +劈頭第一 +に +画 +はどうかね +と +口 +を +切 +った +主人 +は +平気 +な +顔 +をして +君 +の +忠告 +に +従 +って +写生 +を +力 +めているが +なるほど +写生 +をすると +今 +まで +気 +のつかなかった +物 +の +形 +や +色 +の +精細 +な +変化 +などがよく +分 +るようだ +西洋 +では +昔 +しから +写生 +を +主張 +した +結果今日 +のように +発達 +したものと +思 +われる +さすが +アンドレア +デル +サルト +だ +と +日記 +の +事 +はおくびにも +出 +さないで +また +アンドレア +デル +サルト +に +感心 +する +美学者 +は +笑 +いながら +実 +は +君 +あれは +出鱈目 +だよ +と +頭 +を +掻 +く +何 +が +と +主人 +はまだ +わられた +事 +に +気 +がつかない +何 +がって +君 +のしきりに +感服 +している +アンドレア +デル +サルト +さ +あれは +僕 +のちょっと +捏造 +した +話 +だ +君 +がそんなに +真面目 +に +信 +じようとは +思 +わなかった +ハハハハ +と +大喜悦 +の +体 +である +吾輩 +は +椽側 +でこの +対話 +を +聞 +いて +彼 +の +今日 +の +日記 +にはいかなる +事 +が +記 +さるるであろうかと +予 +め +想像 +せざるを +得 +なかった +この +美学者 +はこんな +好加減 +な +事 +を +吹 +き +散 +らして +人 +を +担 +ぐのを +唯一 +の +楽 +にしている +男 +である +彼 +は +アンドレア +デル +サルト +事件 +が +主人 +の +情線 +にいかなる +響 +を +伝 +えたかを +毫 +も +顧慮 +せざるもののごとく +得意 +になって +下 +のような +事 +を +饒舌 +った +いや +時々冗談 +を +言 +うと +人 +が +真 +に +受 +けるので +大 +に +滑稽的美感 +を +挑撥 +するのは +面白 +い +せんだってある +学生 +に +ニコラス +ニックルベ +が +ギボン +に +忠告 +して +彼 +の +一世 +の +大著述 +なる +仏国革命史 +を +仏語 +で +書 +くのをやめにして +英文 +で +出版 +させたと +言 +ったら +その +学生 +がまた +馬鹿 +に +記憶 +の +善 +い +男 +で +日本文学会 +の +演説会 +で +真面目 +に +僕 +の +話 +した +通 +りを +繰 +り +返 +したのは +滑稽 +であった +ところがその +時 +の +傍聴者 +は +約百名 +ばかりであったが +皆熱心 +にそれを +傾聴 +しておった +それからまだ +面白 +い +話 +がある +せんだって +或 +る +文学者 +のいる +席 +で +ハリソン +の +歴史小説 +セオファ +ノ +の +話 +しが +出 +たから +僕 +はあれは +歴史小説 +の +中 +で +白眉 +である +ことに +女主人公 +が +死 +ぬところは +鬼気人 +を +襲 +うようだと +評 +したら +僕 +の +向 +うに +坐 +っている +知 +らんと +云 +った +事 +のない +先生 +が +そうそうあすこは +実 +に +名文 +だといった +それで +僕 +はこの +男 +もやはり +僕同様 +この +小説 +を +読 +んでおらないという +事 +を +知 +った +神経胃弱性 +の +主人 +は +眼 +を +丸 +くして +問 +いかけた +そんな +出鱈目 +をいってもし +相手 +が +読 +んでいたらどうするつもりだ +あたかも +人 +を +欺 +くのは +差支 +ない +ただ +化 +の +皮 +があらわれた +時 +は +困 +るじゃないかと +感 +じたもののごとくである +美学者 +は +少 +しも +動 +じない +なにその +時 +ゃ +別 +の +本 +と +間違 +えたとか +何 +とか +云 +うばかりさ +と +云 +ってけらけら +笑 +っている +この +美学者 +は +金縁 +の +眼鏡 +は +掛 +けているがその +性質 +が +車屋 +の +黒 +に +似 +たところがある +主人 +は +黙 +って +日 +の +出 +を +輪 +に +吹 +いて +吾輩 +にはそんな +勇気 +はないと +云 +わんばかりの +顔 +をしている +美学者 +はそれだから +画 +をかいても +駄目 +だという +目付 +で +しかし +冗談 +は +冗談 +だが +画 +というものは +実際 +むずかしいものだよ +レオナルド +ダ +ヴィンチ +は +門下生 +に +寺院 +の +壁 +のしみを +写 +せと +教 +えた +事 +があるそうだ +なるほど +雪隠 +などに +這入 +って +雨 +の +漏 +る +壁 +を +余念 +なく +眺 +めていると +なかなかうまい +模様画 +が +自然 +に +出来 +ているぜ +君注意 +して +写生 +して +見給 +えきっと +面白 +いものが +出来 +るから +また +欺 +すのだろう +いえこれだけはたしかだよ +実際奇警 +な +語 +じゃないか +ダ +ヴィンチ +でもいいそうな +事 +だあね +なるほど +奇警 +には +相違 +ないな +と +主人 +は +半分降参 +をした +しかし +彼 +はまだ +雪隠 +で +写生 +はせぬようだ +車屋 +の +黒 +はその +後跛 +になった +彼 +の +光沢 +ある +毛 +は +漸々色 +が +褪 +めて +抜 +けて +来 +る +吾輩 +が +琥珀 +よりも +美 +しいと +評 +した +彼 +の +眼 +には +眼脂 +が +一杯 +たまっている +ことに +著 +るしく +吾輩 +の +注意 +を +惹 +いたのは +彼 +の +元気 +の +消沈 +とその +体格 +の +悪 +くなった +事 +である +吾輩 +が +例 +の +茶園 +で +彼 +に +逢 +った +最後 +の +日 +どうだと +云 +って +尋 +ねたら +いたちの +最後屁 +と +肴屋 +の +天秤棒 +には +懲々 +だ +といった +赤松 +の +間 +に +二三段 +の +紅 +を +綴 +った +紅葉 +は +昔 +しの +夢 +のごとく +散 +ってつくばいに +近 +く +代 +る +代 +る +花弁 +をこぼした +紅白 +の +山茶花 +も +残 +りなく +落 +ち +尽 +した +三間半 +の +南向 +の +椽側 +に +冬 +の +日脚 +が +早 +く +傾 +いて +木枯 +の +吹 +かない +日 +はほとんど +稀 +になってから +吾輩 +の +昼寝 +の +時間 +も +狭 +められたような +気 +がする +主人 +は +毎日学校 +へ +行 +く +帰 +ると +書斎 +へ +立 +て +籠 +る +人 +が +来 +ると +教師 +が +厭 +だ +厭 +だという +水彩画 +も +滅多 +にかかない +タカジヤスタ +ゼ +も +功能 +がないといってやめてしまった +小供 +は +感心 +に +休 +まないで +幼稚園 +へかよう +帰 +ると +唱歌 +を +歌 +って +毬 +をついて +時々吾輩 +を +尻尾 +でぶら +下 +げる +吾輩 +は +御馳走 +も +食 +わないから +別段肥 +りもしないが +まずまず +健康 +で +跛 +にもならずにその +日 +その +日 +を +暮 +している +鼠 +は +決 +して +取 +らない +おさんは +未 +だに +嫌 +いである +名前 +はまだつけてくれないが +欲 +をいっても +際限 +がないから +生涯 +この +教師 +の +家 +で +無名 +の +猫 +で +終 +るつもりだ +二 +吾輩 +は +新年来多少有名 +になったので +猫 +ながらちょっと +鼻 +が +高 +く +感 +ぜらるるのはありがたい +元朝早々主人 +の +許 +へ +一枚 +の +絵端書 +が +来 +た +これは +彼 +の +交友某画家 +からの +年始状 +であるが +上部 +を +赤 +下部 +を +深緑 +りで +塗 +って +その +真中 +に +一 +の +動物 +が +蹲踞 +っているところを +パステル +で +書 +いてある +主人 +は +例 +の +書斎 +でこの +絵 +を +横 +から +見 +たり +竪 +から +眺 +めたりして +うまい +色 +だなという +すでに +一応感服 +したものだから +もうやめにするかと +思 +うとやはり +横 +から +見 +たり +竪 +から +見 +たりしている +からだを +拗 +じ +向 +けたり +手 +を +延 +ばして +年寄 +が +三世相 +を +見 +るようにしたり +または +窓 +の +方 +へむいて +鼻 +の +先 +まで +持 +って +来 +たりして +見 +ている +早 +くやめてくれないと +膝 +が +揺 +れて +険呑 +でたまらない +ようやくの +事 +で +動揺 +があまり +劇 +しくなくなったと +思 +ったら +小 +さな +声 +で +一体何 +をかいたのだろうと +云 +う +主人 +は +絵端書 +の +色 +には +感服 +したが +かいてある +動物 +の +正体 +が +分 +らぬので +さっきから +苦心 +をしたものと +見 +える +そんな +分 +らぬ +絵端書 +かと +思 +いながら +寝 +ていた +眼 +を +上品 +に +半 +ば +開 +いて +落 +ちつき +払 +って +見 +ると +紛 +れもない +自分 +の +肖像 +だ +主人 +のように +アンドレア +デル +サルト +を +極 +め +込 +んだものでもあるまいが +画家 +だけに +形体 +も +色彩 +もちゃんと +整 +って +出来 +ている +誰 +が +見 +たって +猫 +に +相違 +ない +少 +し +眼識 +のあるものなら +猫 +の +中 +でも +他 +の +猫 +じゃない +吾輩 +である +事 +が +判然 +とわかるように +立派 +に +描 +いてある +このくらい +明瞭 +な +事 +を +分 +らずにかくまで +苦心 +するかと +思 +うと +少 +し +人間 +が +気 +の +毒 +になる +出来 +る +事 +ならその +絵 +が +吾輩 +であると +云 +う +事 +を +知 +らしてやりたい +吾輩 +であると +云 +う +事 +はよし +分 +らないにしても +せめて +猫 +であるという +事 +だけは +分 +らしてやりたい +しかし +人間 +というものは +到底吾輩猫属 +の +言語 +を +解 +し +得 +るくらいに +天 +の +恵 +に +浴 +しておらん +動物 +であるから +残念 +ながらそのままにしておいた +ちょっと +読者 +に +断 +っておきたいが +元来人間 +が +何 +ぞというと +猫々 +と +事 +もなげに +軽侮 +の +口調 +をもって +吾輩 +を +評価 +する +癖 +があるははなはだよくない +人間 +の +糟 +から +牛 +と +馬 +が +出来 +て +牛 +と +馬 +の +糞 +から +猫 +が +製造 +されたごとく +考 +えるのは +自分 +の +無智 +に +心付 +かんで +高慢 +な +顔 +をする +教師 +などにはありがちの +事 +でもあろうが +はたから +見 +てあまり +見 +っともいい +者 +じゃない +いくら +猫 +だって +そう +粗末簡便 +には +出来 +ぬ +よそ +目 +には +一列一体 +平等無差別 +どの +猫 +も +自家固有 +の +特色 +などはないようであるが +猫 +の +社会 +に +這入 +って +見 +るとなかなか +複雑 +なもので +十人十色 +という +人間界 +の +語 +はそのままここにも +応用 +が +出来 +るのである +目付 +でも +鼻付 +でも +毛並 +でも +足並 +でも +みんな +違 +う +髯 +の +張 +り +具合 +から +耳 +の +立 +ち +按排 +尻尾 +の +垂 +れ +加減 +に +至 +るまで +同 +じものは +一 +つもない +器量 +不器量 +好 +き +嫌 +い +粋無粋 +の +数 +を +悉 +くして +千差万別 +と +云 +っても +差支 +えないくらいである +そのように +判然 +たる +区別 +が +存 +しているにもかかわらず +人間 +の +眼 +はただ +向上 +とか +何 +とかいって +空 +ばかり +見 +ているものだから +吾輩 +の +性質 +は +無論相貌 +の +末 +を +識別 +する +事 +すら +到底出来 +ぬのは +気 +の +毒 +だ +同類相求 +むとは +昔 +しからある +語 +だそうだがその +通 +り +餅屋 +は +餅屋 +猫 +は +猫 +で +猫 +の +事 +ならやはり +猫 +でなくては +分 +らぬ +いくら +人間 +が +発達 +したってこればかりは +駄目 +である +いわんや +実際 +をいうと +彼等 +が +自 +ら +信 +じているごとくえらくも +何 +ともないのだからなおさらむずかしい +またいわんや +同情 +に +乏 +しい +吾輩 +の +主人 +のごときは +相互 +を +残 +りなく +解 +するというが +愛 +の +第一義 +であるということすら +分 +らない +男 +なのだから +仕方 +がない +彼 +は +性 +の +悪 +い +牡蠣 +のごとく +書斎 +に +吸 +い +付 +いて +かつて +外界 +に +向 +って +口 +を +開 +いた +事 +がない +それで +自分 +だけはすこぶる +達観 +したような +面構 +をしているのはちょっとおかしい +達観 +しない +証拠 +には +現 +に +吾輩 +の +肖像 +が +眼 +の +前 +にあるのに +少 +しも +悟 +った +様子 +もなく +今年 +は +征露 +の +第二年目 +だから +大方熊 +の +画 +だろうなどと +気 +の +知 +れぬことをいってすましているのでもわかる +吾輩 +が +主人 +の +膝 +の +上 +で +眼 +をねむりながらかく +考 +えていると +やがて +下女 +が +第二 +の +絵端書 +を +持 +って +来 +た +見 +ると +活版 +で +舶来 +の +猫 +が +四五疋 +ずらりと +行列 +して +ペン +を +握 +ったり +書物 +を +開 +いたり +勉強 +をしている +その +内 +の +一疋 +は +席 +を +離 +れて +机 +の +角 +で +西洋 +の +猫 +じゃ +猫 +じゃを +躍 +っている +その +上 +に +日本 +の +墨 +で +吾輩 +は +猫 +である +と +黒々 +とかいて +右 +の +側 +に +書 +を +読 +むや +躍 +るや +猫 +の +春一日 +という +俳句 +さえ +認 +められてある +これは +主人 +の +旧門下生 +より +来 +たので +誰 +が +見 +たって +一見 +して +意味 +がわかるはずであるのに +迂濶 +な +主人 +はまだ +悟 +らないと +見 +えて +不思議 +そうに +首 +を +捻 +って +はてな +今年 +は +猫 +の +年 +かなと +独言 +を +言 +った +吾輩 +がこれほど +有名 +になったのを +未 +だ +気 +が +着 +かずにいると +見 +える +ところへ +下女 +がまた +第三 +の +端書 +を +持 +ってくる +今度 +は +絵端書 +ではない +恭賀新年 +とかいて +傍 +らに +乍恐縮 +かの +猫 +へも +宜 +しく +御伝声奉願上候 +とある +いかに +迂遠 +な +主人 +でもこう +明 +らさまに +書 +いてあれば +分 +るものと +見 +えてようやく +気 +が +付 +いたように +フン +と +言 +いながら +吾輩 +の +顔 +を +見 +た +その +眼付 +が +今 +までとは +違 +って +多少尊敬 +の +意 +を +含 +んでいるように +思 +われた +今 +まで +世間 +から +存在 +を +認 +められなかった +主人 +が +急 +に +一個 +の +新面目 +を +施 +こしたのも +全 +く +吾輩 +の +御蔭 +だと +思 +えばこのくらいの +眼付 +は +至当 +だろうと +考 +える +おりから +門 +の +格子 +が +チリン +チリン +チリリリリン +と +鳴 +る +大方来客 +であろう +来客 +なら +下女 +が +取次 +に +出 +る +吾輩 +は +肴屋 +の +梅公 +がくる +時 +のほかは +出 +ない +事 +に +極 +めているのだから +平気 +で +もとのごとく +主人 +の +膝 +に +坐 +っておった +すると +主人 +は +高利貸 +にでも +飛 +び +込 +まれたように +不安 +な +顔付 +をして +玄関 +の +方 +を +見 +る +何 +でも +年賀 +の +客 +を +受 +けて +酒 +の +相手 +をするのが +厭 +らしい +人間 +もこのくらい +偏屈 +になれば +申 +し +分 +はない +そんなら +早 +くから +外出 +でもすればよいのにそれほどの +勇気 +も +無 +い +いよいよ +牡蠣 +の +根性 +をあらわしている +しばらくすると +下女 +が +来 +て +寒月 +さんがおいでになりましたという +この +寒月 +という +男 +はやはり +主人 +の +旧門下生 +であったそうだが +今 +では +学校 +を +卒業 +して +何 +でも +主人 +より +立派 +になっているという +話 +しである +この +男 +がどういう +訳 +か +よく +主人 +の +所 +へ +遊 +びに +来 +る +来 +ると +自分 +を +恋 +っている +女 +が +有 +りそうな +無 +さそうな +世 +の +中 +が +面白 +そうな +つまらなそうな +凄 +いような +艶 +っぽいような +文句 +ばかり +並 +べては +帰 +る +主人 +のようなしなびかけた +人間 +を +求 +めて +わざわざこんな +話 +しをしに +来 +るのからして +合点 +が +行 +かぬが +あの +牡蠣的主人 +がそんな +談話 +を +聞 +いて +時々相槌 +を +打 +つのはなお +面白 +い +しばらく +御無沙汰 +をしました +実 +は +去年 +の +暮 +から +大 +に +活動 +しているものですから +出 +よう +出 +ようと +思 +っても +ついこの +方角 +へ +足 +が +向 +かないので +と +羽織 +の +紐 +をひねくりながら +謎見 +たような +事 +をいう +どっちの +方角 +へ +足 +が +向 +くかね +と +主人 +は +真面目 +な +顔 +をして +黒木綿 +の +紋付羽織 +の +袖口 +を +引張 +る +この +羽織 +は +木綿 +でゆきが +短 +かい +下 +からべんべら +者 +が +左右 +へ +五分 +くらいずつはみ +出 +している +エヘヘヘ +少 +し +違 +った +方角 +で +と +寒月君 +が +笑 +う +見 +ると +今日 +は +前歯 +が +一枚欠 +けている +君歯 +をどうかしたかね +と +主人 +は +問題 +を +転 +じた +ええ +実 +はある +所 +で +椎茸 +を +食 +いましてね +何 +を +食 +ったって +その +少 +し +椎茸 +を +食 +ったんで +椎茸 +の +傘 +を +前歯 +で +噛 +み +切 +ろうとしたらぼろりと +歯 +が +欠 +けましたよ +椎茸 +で +前歯 +がかけるなんざ +何 +だか +爺々臭 +いね +俳句 +にはなるかも +知 +れないが +恋 +にはならんようだな +と +平手 +で +吾輩 +の +頭 +を +軽 +く +叩 +く +ああその +猫 +が +例 +のですか +なかなか +肥 +ってるじゃありませんか +それなら +車屋 +の +黒 +にだって +負 +けそうもありませんね +立派 +なものだ +と +寒月君 +は +大 +に +吾輩 +を +賞 +める +近頃大分大 +きくなったのさ +と +自慢 +そうに +頭 +をぽかぽかなぐる +賞 +められたのは +得意 +であるが +頭 +が +少々痛 +い +一昨夜 +もちょいと +合奏会 +をやりましてね +と +寒月君 +はまた +話 +しをもとへ +戻 +す +どこで +どこでもそりゃ +御聞 +きにならんでもよいでしょう +ヴァイオリン +が +三挺 +と +ピヤノ +の +伴奏 +でなかなか +面白 +かったです +ヴァイオリン +も +三挺 +くらいになると +下手 +でも +聞 +かれるものですね +二人 +は +女 +で +私 +がその +中 +へまじりましたが +自分 +でも +善 +く +弾 +けたと +思 +いました +ふん +そしてその +女 +というのは +何者 +かね +と +主人 +は +羨 +ましそうに +問 +いかける +元来主人 +は +平常枯木寒巌 +のような +顔付 +はしているものの +実 +のところは +決 +して +婦人 +に +冷淡 +な +方 +ではない +かつて +西洋 +の +或 +る +小説 +を +読 +んだら +その +中 +にある +一人物 +が +出 +て +来 +て +それが +大抵 +の +婦人 +には +必 +ずちょっと +惚 +れる +勘定 +をして +見 +ると +往来 +を +通 +る +婦人 +の +七割弱 +には +恋着 +するという +事 +が +諷刺的 +に +書 +いてあったのを +見 +て +これは +真理 +だと +感心 +したくらいな +男 +である +そんな +浮気 +な +男 +が +何故牡蠣的生涯 +を +送 +っているかと +云 +うのは +吾輩猫 +などには +到底分 +らない +或人 +は +失恋 +のためだとも +云 +うし +或人 +は +胃弱 +のせいだとも +云 +うし +また +或人 +は +金 +がなくて +臆病 +な +性質 +だからだとも +云 +う +どっちにしたって +明治 +の +歴史 +に +関係 +するほどな +人物 +でもないのだから +構 +わない +しかし +寒月君 +の +女連 +れを +羨 +まし +気 +に +尋 +ねた +事 +だけは +事実 +である +寒月君 +は +面白 +そうに +口取 +の +蒲鉾 +を +箸 +で +挟 +んで +半分前歯 +で +食 +い +切 +った +吾輩 +はまた +欠 +けはせぬかと +心配 +したが +今度 +は +大丈夫 +であった +なに +二人 +とも +去 +る +所 +の +令嬢 +ですよ +御存 +じの +方 +じゃありません +と +余所余所 +しい +返事 +をする +ナ +ル +と +主人 +は +引張 +ったが +ほど +を +略 +して +考 +えている +寒月君 +はもう +善 +い +加減 +な +時分 +だと +思 +ったものか +どうも +好 +い +天気 +ですな +御閑 +ならごいっしょに +散歩 +でもしましょうか +旅順 +が +落 +ちたので +市中 +は +大変 +な +景気 +ですよ +と +促 +がして +見 +る +主人 +は +旅順 +の +陥落 +より +女連 +の +身元 +を +聞 +きたいと +云 +う +顔 +で +しばらく +考 +え +込 +んでいたがようやく +決心 +をしたものと +見 +えて +それじゃ +出 +るとしよう +と +思 +い +切 +って +立 +つ +やはり +黒木綿 +の +紋付羽織 +に +兄 +の +紀念 +とかいう +二十年来着古 +るした +結城紬 +の +綿入 +を +着 +たままである +いくら +結城紬 +が +丈夫 +だって +こう +着 +つづけではたまらない +所々 +が +薄 +くなって +日 +に +透 +かして +見 +ると +裏 +からつぎを +当 +てた +針 +の +目 +が +見 +える +主人 +の +服装 +には +師走 +も +正月 +もない +ふだん +着 +も +余所 +ゆきもない +出 +るときは +懐手 +をしてぶらりと +出 +る +ほかに +着 +る +物 +がないからか +有 +っても +面倒 +だから +着換 +えないのか +吾輩 +には +分 +らぬ +ただしこれだけは +失恋 +のためとも +思 +われない +両人 +が +出 +て +行 +ったあとで +吾輩 +はちょっと +失敬 +して +寒月君 +の +食 +い +切 +った +蒲鉾 +の +残 +りを +頂戴 +した +吾輩 +もこの +頃 +では +普通一般 +の +猫 +ではない +まず +桃川如燕以後 +の +猫 +か +グレ +の +金魚 +を +偸 +んだ +猫 +くらいの +資格 +は +充分 +あると +思 +う +車屋 +の +黒 +などは +固 +より +眼中 +にない +蒲鉾 +の +一切 +くらい +頂戴 +したって +人 +からかれこれ +云 +われる +事 +もなかろう +それにこの +人目 +を +忍 +んで +間食 +をするという +癖 +は +何 +も +吾等猫族 +に +限 +った +事 +ではない +うちの +御三 +などはよく +細君 +の +留守中 +に +餅菓子 +などを +失敬 +しては +頂戴 +し +頂戴 +しては +失敬 +している +御三 +ばかりじゃない +現 +に +上品 +な +仕付 +を +受 +けつつあると +細君 +から +吹聴 +せられている +小児 +ですらこの +傾向 +がある +四五日前 +のことであったが +二人 +の +小供 +が +馬鹿 +に +早 +くから +眼 +を +覚 +まして +まだ +主人夫婦 +の +寝 +ている +間 +に +対 +い +合 +うて +食卓 +に +着 +いた +彼等 +は +毎朝主人 +の +食 +う +麺麭 +の +幾分 +に +砂糖 +をつけて +食 +うのが +例 +であるが +この +日 +はちょうど +砂糖壺 +が +卓 +の +上 +に +置 +かれて +匙 +さえ +添 +えてあった +いつものように +砂糖 +を +分配 +してくれるものがないので +大 +きい +方 +がやがて +壺 +の +中 +から +一匙 +の +砂糖 +をすくい +出 +して +自分 +の +皿 +の +上 +へあけた +すると +小 +さいのが +姉 +のした +通 +り +同分量 +の +砂糖 +を +同方法 +で +自分 +の +皿 +の +上 +にあけた +少 +らく +両人 +は +睨 +み +合 +っていたが +大 +きいのがまた +匙 +をとって +一杯 +をわが +皿 +の +上 +に +加 +えた +小 +さいのもすぐ +匙 +をとってわが +分量 +を +姉 +と +同一 +にした +すると +姉 +がまた +一杯 +すくった +妹 +も +負 +けずに +一杯 +を +附加 +した +姉 +がまた +壺 +へ +手 +を +懸 +ける +妹 +がまた +匙 +をとる +見 +ている +間 +に +一杯一杯一杯 +と +重 +なって +ついには +両人 +の +皿 +には +山盛 +の +砂糖 +が +堆 +くなって +壺 +の +中 +には +一匙 +の +砂糖 +も +余 +っておらんようになったとき +主人 +が +寝 +ぼけ +眼 +を +擦 +りながら +寝室 +を +出 +て +来 +てせっかくしゃくい +出 +した +砂糖 +を +元 +のごとく +壺 +の +中 +へ +入 +れてしまった +こんなところを +見 +ると +人間 +は +利己主義 +から +割 +り +出 +した +公平 +という +念 +は +猫 +より +優 +っているかも +知 +れぬが +智慧 +はかえって +猫 +より +劣 +っているようだ +そんなに +山盛 +にしないうちに +早 +く +甞 +めてしまえばいいにと +思 +ったが +例 +のごとく +吾輩 +の +言 +う +事 +などは +通 +じないのだから +気 +の +毒 +ながら +御櫃 +の +上 +から +黙 +って +見物 +していた +寒月君 +と +出掛 +けた +主人 +はどこをどう +歩行 +いたものか +その +晩遅 +く +帰 +って +来 +て +翌日食卓 +に +就 +いたのは +九時頃 +であった +例 +の +御櫃 +の +上 +から +拝見 +していると +主人 +はだまって +雑煮 +を +食 +っている +代 +えては +食 +い +代 +えては +食 +う +餅 +の +切 +れは +小 +さいが +何 +でも +六切 +か +七切食 +って +最後 +の +一切 +れを +椀 +の +中 +へ +残 +して +もうよそうと +箸 +を +置 +いた +他人 +がそんな +我儘 +をすると +なかなか +承知 +しないのであるが +主人 +の +威光 +を +振 +り +廻 +わして +得意 +なる +彼 +は +濁 +った +汁 +の +中 +に +焦 +げ +爛 +れた +餅 +の +死骸 +を +見 +て +平気 +ですましている +妻君 +が +袋戸 +の +奥 +から +タカジヤスタ +ゼ +を +出 +して +卓 +の +上 +に +置 +くと +主人 +は +それは +利 +かないから +飲 +まん +という +でもあなた +澱粉質 +のものには +大変功能 +があるそうですから +召 +し +上 +ったらいいでしょう +と +飲 +ませたがる +澱粉 +だろうが +何 +だろうが +駄目 +だよ +と +頑固 +に +出 +る +あなたはほんとに +厭 +きっぽい +と +細君 +が +独言 +のようにいう +厭 +きっぽいのじゃない +薬 +が +利 +かんのだ +それだってせんだってじゅうは +大変 +によく +利 +くよく +利 +くとおっしゃって +毎日毎日上 +ったじゃありませんか +こないだうちは +利 +いたのだよ +この +頃 +は +利 +かないのだよ +と +対句 +のような +返事 +をする +そんなに +飲 +んだり +止 +めたりしちゃ +いくら +功能 +のある +薬 +でも +利 +く +気遣 +いはありません +もう +少 +し +辛防 +がよくなくっちゃあ +胃弱 +なんぞはほかの +病気 +たあ +違 +って +直 +らないわねえ +とお +盆 +を +持 +って +控 +えた +御三 +を +顧 +みる +それは +本当 +のところでございます +もう +少 +し +召 +し +上 +ってご +覧 +にならないと +とても +善 +い +薬 +か +悪 +い +薬 +かわかりますまい +と +御三 +は +一 +も +二 +もなく +細君 +の +肩 +を +持 +つ +何 +でもいい +飲 +まんのだから +飲 +まんのだ +女 +なんかに +何 +がわかるものか +黙 +っていろ +どうせ +女 +ですわ +と +細君 +が +タカジヤスタ +ゼ +を +主人 +の +前 +へ +突 +き +付 +けて +是非詰腹 +を +切 +らせようとする +主人 +は +何 +にも +云 +わず +立 +って +書斎 +へ +這入 +る +細君 +と +御三 +は +顔 +を +見合 +せてにやにやと +笑 +う +こんなときに +後 +からくっ +付 +いて +行 +って +膝 +の +上 +へ +乗 +ると +大変 +な +目 +に +逢 +わされるから +そっと +庭 +から +廻 +って +書斎 +の +椽側 +へ +上 +って +障子 +の +隙 +から +覗 +いて +見 +ると +主人 +は +エピクテタス +とか +云 +う +人 +の +本 +を +披 +いて +見 +ておった +もしそれが +平常 +の +通 +りわかるならちょっとえらいところがある +五六分 +するとその +本 +を +叩 +き +付 +けるように +机 +の +上 +へ +抛 +り +出 +す +大方 +そんな +事 +だろうと +思 +いながらなお +注意 +していると +今度 +は +日記帳 +を +出 +して +下 +のような +事 +を +書 +きつけた +寒月 +と +根津 +上野 +池 +の +端 +神田辺 +を +散歩 +池 +の +端 +の +待合 +の +前 +で +芸者 +が +裾模様 +の +春着 +をきて +羽根 +をついていた +衣装 +は +美 +しいが +顔 +はすこぶるまずい +何 +となくうちの +猫 +に +似 +ていた +何 +も +顔 +のまずい +例 +に +特 +に +吾輩 +を +出 +さなくっても +よさそうなものだ +吾輩 +だって +喜多床 +へ +行 +って +顔 +さえ +剃 +って +貰 +やあ +そんなに +人間 +と +異 +ったところはありゃしない +人間 +はこう +自惚 +れているから +困 +る +宝丹 +の +角 +を +曲 +るとまた +一人芸者 +が +来 +た +これは +背 +のすらりとした +撫肩 +の +恰好 +よく +出来上 +った +女 +で +着 +ている +薄紫 +の +衣服 +も +素直 +に +着 +こなされて +上品 +に +見 +えた +白 +い +歯 +を +出 +して +笑 +いながら +源 +ちゃん +昨夕 +は +つい +忙 +がしかったもんだから +と +云 +った +ただしその +声 +は +旅鴉 +のごとく +皺枯 +れておったので +せっかくの +風采 +も +大 +に +下落 +したように +感 +ぜられたから +いわゆる +源 +ちゃんなるもののいかなる +人 +なるかを +振 +り +向 +いて +見 +るも +面倒 +になって +懐手 +のまま +御成道 +へ +出 +た +寒月 +は +何 +となくそわそわしているごとく +見 +えた +人間 +の +心理 +ほど +解 +し +難 +いものはない +この +主人 +の +今 +の +心 +は +怒 +っているのだか +浮 +かれているのだか +または +哲人 +の +遺書 +に +一道 +の +慰安 +を +求 +めつつあるのか +ちっとも +分 +らない +世 +の +中 +を +冷笑 +しているのか +世 +の +中 +へ +交 +りたいのだか +くだらぬ +事 +に +肝癪 +を +起 +しているのか +物外 +に +超然 +としているのだかさっぱり +見当 +が +付 +かぬ +猫 +などはそこへ +行 +くと +単純 +なものだ +食 +いたければ +食 +い +寝 +たければ +寝 +る +怒 +るときは +一生懸命 +に +怒 +り +泣 +くときは +絶体絶命 +に +泣 +く +第一日記 +などという +無用 +のものは +決 +してつけない +つける +必要 +がないからである +主人 +のように +裏表 +のある +人間 +は +日記 +でも +書 +いて +世間 +に +出 +されない +自己 +の +面目 +を +暗室内 +に +発揮 +する +必要 +があるかも +知 +れないが +我等猫属 +に +至 +ると +行住坐臥 +行屎送尿 +ことごとく +真正 +の +日記 +であるから +別段 +そんな +面倒 +な +手数 +をして +己 +れの +真面目 +を +保存 +するには +及 +ばぬと +思 +う +日記 +をつけるひまがあるなら +椽側 +に +寝 +ているまでの +事 +さ +神田 +の +某亭 +で +晩餐 +を +食 +う +久 +し +振 +りで +正宗 +を +二三杯飲 +んだら +今朝 +は +胃 +の +具合 +が +大変 +いい +胃弱 +には +晩酌 +が +一番 +だと +思 +う +タカジヤスタ +ゼ +は +無論 +いかん +誰 +が +何 +と +云 +っても +駄目 +だ +どうしたって +利 +かないものは +利 +かないのだ +無暗 +に +タカジヤスタ +ゼ +を +攻撃 +する +独 +りで +喧嘩 +をしているようだ +今朝 +の +肝癪 +がちょっとここへ +尾 +を +出 +す +人間 +の +日記 +の +本色 +はこう +云 +う +辺 +に +存 +するのかも +知 +れない +せんだって +は +朝飯 +を +廃 +すると +胃 +がよくなると +云 +うたから +二三日朝飯 +をやめて +見 +たが +腹 +がぐうぐう +鳴 +るばかりで +功能 +はない +は +是非香 +の +物 +を +断 +てと +忠告 +した +彼 +の +説 +によるとすべて +胃病 +の +源因 +は +漬物 +にある +漬物 +さえ +断 +てば +胃病 +の +源 +を +涸 +らす +訳 +だから +本復 +は +疑 +なしという +論法 +であった +それから +一週間 +ばかり +香 +の +物 +に +箸 +を +触 +れなかったが +別段 +の +験 +も +見 +えなかったから +近頃 +はまた +食 +い +出 +した +に +聞 +くとそれは +按腹揉療治 +に +限 +る +ただし +普通 +のではゆかぬ +皆川流 +という +古流 +な +揉 +み +方 +で +一二度 +やらせれば +大抵 +の +胃病 +は +根治出来 +る +安井息軒 +も +大変 +この +按摩術 +を +愛 +していた +坂本竜馬 +のような +豪傑 +でも +時々 +は +治療 +をうけたと +云 +うから +早速上根岸 +まで +出掛 +けて +揉 +まして +見 +た +ところが +骨 +を +揉 +まなければ +癒 +らぬとか +臓腑 +の +位置 +を +一度顛倒 +しなければ +根治 +がしにくいとかいって +それはそれは +残酷 +な +揉 +み +方 +をやる +後 +で +身体 +が +綿 +のようになって +昏睡病 +にかかったような +心持 +ちがしたので +一度 +で +閉口 +してやめにした +君 +は +是非固形体 +を +食 +うなという +それから +一日牛乳 +ばかり +飲 +んで +暮 +して +見 +たが +この +時 +は +腸 +の +中 +でどぼりどぼりと +音 +がして +大水 +でも +出 +たように +思 +われて +終夜眠 +れなかった +氏 +は +横膈膜 +で +呼吸 +して +内臓 +を +運動 +させれば +自然 +と +胃 +の +働 +きが +健全 +になる +訳 +だから +試 +しにやって +御覧 +という +これも +多少 +やったが +何 +となく +腹中 +が +不安 +で +困 +る +それに +時々思 +い +出 +したように +一心不乱 +にかかりはするものの +五六分立 +つと +忘 +れてしまう +忘 +れまいとすると +横膈膜 +が +気 +になって +本 +を +読 +む +事 +も +文章 +をかく +事 +も +出来 +ぬ +美学者 +の +迷亭 +がこの +体 +を +見 +て +産気 +のついた +男 +じゃあるまいし +止 +すがいいと +冷 +かしたからこの +頃 +は +廃 +してしまった +先生 +は +蕎麦 +を +食 +ったらよかろうと +云 +うから +早速 +かけともりをかわるがわる +食 +ったが +これは +腹 +が +下 +るばかりで +何等 +の +功能 +もなかった +余 +は +年来 +の +胃弱 +を +直 +すために +出来得 +る +限 +りの +方法 +を +講 +じて +見 +たがすべて +駄目 +である +ただ +昨夜寒月 +と +傾 +けた +三杯 +の +正宗 +はたしかに +利目 +がある +これからは +毎晩二三杯 +ずつ +飲 +む +事 +にしよう +これも +決 +して +長 +く +続 +く +事 +はあるまい +主人 +の +心 +は +吾輩 +の +眼球 +のように +間断 +なく +変化 +している +何 +をやっても +永持 +のしない +男 +である +その +上日記 +の +上 +で +胃病 +をこんなに +心配 +している +癖 +に +表向 +は +大 +に +痩我慢 +をするからおかしい +せんだってその +友人 +で +某 +という +学者 +が +尋 +ねて +来 +て +一種 +の +見地 +から +すべての +病気 +は +父祖 +の +罪悪 +と +自己 +の +罪悪 +の +結果 +にほかならないと +云 +う +議論 +をした +大分研究 +したものと +見 +えて +条理 +が +明晰 +で +秩序 +が +整然 +として +立派 +な +説 +であった +気 +の +毒 +ながらうちの +主人 +などは +到底 +これを +反駁 +するほどの +頭脳 +も +学問 +もないのである +しかし +自分 +が +胃病 +で +苦 +しんでいる +際 +だから +何 +とかかんとか +弁解 +をして +自己 +の +面目 +を +保 +とうと +思 +った +者 +と +見 +えて +君 +の +説 +は +面白 +いが +あの +カ +ライル +は +胃弱 +だったぜ +とあたかも +カ +ライル +が +胃弱 +だから +自分 +の +胃弱 +も +名誉 +であると +云 +ったような +見当違 +いの +挨拶 +をした +すると +友人 +は +カ +ライル +が +胃弱 +だって +胃弱 +の +病人 +が +必 +ず +カ +ライル +にはなれないさ +と +極 +め +付 +けたので +主人 +は +黙然 +としていた +かくのごとく +虚栄心 +に +富 +んでいるものの +実際 +はやはり +胃弱 +でない +方 +がいいと +見 +えて +今夜 +から +晩酌 +を +始 +めるなどというのはちょっと +滑稽 +だ +考 +えて +見 +ると +今朝雑煮 +をあんなにたくさん +食 +ったのも +昨夜寒月君 +と +正宗 +をひっくり +返 +した +影響 +かも +知 +れない +吾輩 +もちょっと +雑煮 +が +食 +って +見 +たくなった +吾輩 +は +猫 +ではあるが +大抵 +のものは +食 +う +車屋 +の +黒 +のように +横丁 +の +肴屋 +まで +遠征 +をする +気力 +はないし +新道 +の +二絃琴 +の +師匠 +の +所 +の +三毛 +のように +贅沢 +は +無論云 +える +身分 +でない +従 +って +存外嫌 +は +少 +ない +方 +だ +小供 +の +食 +いこぼした +麺麭 +も +食 +うし +餅菓子 +の +もなめる +香 +の +物 +はすこぶるまずいが +経験 +のため +沢庵 +を +二切 +ばかりやった +事 +がある +食 +って +見 +ると +妙 +なもので +大抵 +のものは +食 +える +あれは +嫌 +だ +これは +嫌 +だと +云 +うのは +贅沢 +な +我儘 +で +到底教師 +の +家 +にいる +猫 +などの +口 +にすべきところでない +主人 +の +話 +しによると +仏蘭西 +に +バルザック +という +小説家 +があったそうだ +この +男 +が +大 +の +贅沢屋 +で +もっともこれは +口 +の +贅沢屋 +ではない +小説家 +だけに +文章 +の +贅沢 +を +尽 +したという +事 +である +バルザック +が +或 +る +日自分 +の +書 +いている +小説中 +の +人間 +の +名 +をつけようと +思 +っていろいろつけて +見 +たが +どうしても +気 +に +入 +らない +ところへ +友人 +が +遊 +びに +来 +たのでいっしょに +散歩 +に +出掛 +けた +友人 +は +固 +より +何 +も +知 +らずに +連 +れ +出 +されたのであるが +バルザック +は +兼 +ねて +自分 +の +苦心 +している +名 +を +目付 +ようという +考 +えだから +往来 +へ +出 +ると +何 +もしないで +店先 +の +看板 +ばかり +見 +て +歩行 +いている +ところがやはり +気 +に +入 +った +名 +がない +友人 +を +連 +れて +無暗 +にあるく +友人 +は +訳 +がわからずにくっ +付 +いて +行 +く +彼等 +はついに +朝 +から +晩 +まで +巴理 +を +探険 +した +その +帰 +りがけに +バルザック +はふとある +裁縫屋 +の +看板 +が +目 +についた +見 +るとその +看板 +に +マ +カス +という +名 +がかいてある +バルザック +は +手 +を +拍 +って +これだこれだこれに +限 +る +マ +カス +は +好 +い +名 +じゃないか +マ +カス +の +上 +へ +という +頭文字 +をつける +すると +申 +し +分 +のない +名 +が +出来 +る +でなくてはいかん +は +実 +にうまい +どうも +自分 +で +作 +った +名 +はうまくつけたつもりでも +何 +となく +故意 +とらしいところがあって +面白 +くない +ようやくの +事 +で +気 +に +入 +った +名 +が +出来 +た +と +友人 +の +迷惑 +はまるで +忘 +れて +一人嬉 +しがったというが +小説中 +の +人間 +の +名前 +をつけるに +一日巴理 +を +探険 +しなくてはならぬようでは +随分手数 +のかかる +話 +だ +贅沢 +もこのくらい +出来 +れば +結構 +なものだが +吾輩 +のように +牡蠣的主人 +を +持 +つ +身 +の +上 +ではとてもそんな +気 +は +出 +ない +何 +でもいい +食 +えさえすれば +という +気 +になるのも +境遇 +のしからしむるところであろう +だから +今雑煮 +が +食 +いたくなったのも +決 +して +贅沢 +の +結果 +ではない +何 +でも +食 +える +時 +に +食 +っておこうという +考 +から +主人 +の +食 +い +剰 +した +雑煮 +がもしや +台所 +に +残 +っていはすまいかと +思 +い +出 +したからである +台所 +へ +廻 +って +見 +る +今朝見 +た +通 +りの +餅 +が +今朝見 +た +通 +りの +色 +で +椀 +の +底 +に +膠着 +している +白状 +するが +餅 +というものは +今 +まで +一辺 +も +口 +に +入 +れた +事 +がない +見 +るとうまそうにもあるし +また +少 +しは +気味 +がわるくもある +前足 +で +上 +にかかっている +菜 +っ +葉 +を +掻 +き +寄 +せる +爪 +を +見 +ると +餅 +の +上皮 +が +引 +き +掛 +ってねばねばする +嗅 +いで +見 +ると +釜 +の +底 +の +飯 +を +御櫃 +へ +移 +す +時 +のような +香 +がする +食 +おうかな +やめようかな +とあたりを +見廻 +す +幸 +か +不幸 +か +誰 +もいない +御三 +は +暮 +も +春 +も +同 +じような +顔 +をして +羽根 +をついている +小供 +は +奥座敷 +で +何 +とおっしゃる +兎 +さん +を +歌 +っている +食 +うとすれば +今 +だ +もしこの +機 +をはずすと +来年 +までは +餅 +というものの +味 +を +知 +らずに +暮 +してしまわねばならぬ +吾輩 +はこの +刹那 +に +猫 +ながら +一 +の +真理 +を +感得 +した +得難 +き +機会 +はすべての +動物 +をして +好 +まざる +事 +をも +敢 +てせしむ +吾輩 +は +実 +を +云 +うとそんなに +雑煮 +を +食 +いたくはないのである +否椀底 +の +様子 +を +熟視 +すればするほど +気味 +が +悪 +くなって +食 +うのが +厭 +になったのである +この +時 +もし +御三 +でも +勝手口 +を +開 +けたなら +奥 +の +小供 +の +足音 +がこちらへ +近付 +くのを +聞 +き +得 +たなら +吾輩 +は +惜気 +もなく +椀 +を +見棄 +てたろう +しかも +雑煮 +の +事 +は +来年 +まで +念頭 +に +浮 +ばなかったろう +ところが +誰 +も +来 +ない +いくら +躇 +していても +誰 +も +来 +ない +早 +く +食 +わぬか +食 +わぬかと +催促 +されるような +心持 +がする +吾輩 +は +椀 +の +中 +を +覗 +き +込 +みながら +早 +く +誰 +か +来 +てくれればいいと +念 +じた +やはり +誰 +も +来 +てくれない +吾輩 +はとうとう +雑煮 +を +食 +わなければならぬ +最後 +にからだ +全体 +の +重量 +を +椀 +の +底 +へ +落 +すようにして +あぐりと +餅 +の +角 +を +一寸 +ばかり +食 +い +込 +んだ +このくらい +力 +を +込 +めて +食 +い +付 +いたのだから +大抵 +なものなら +噛 +み +切 +れる +訳 +だが +驚 +いた +もうよかろうと +思 +って +歯 +を +引 +こうとすると +引 +けない +もう +一辺噛 +み +直 +そうとすると +動 +きがとれない +餅 +は +魔物 +だなと +疳 +づいた +時 +はすでに +遅 +かった +沼 +へでも +落 +ちた +人 +が +足 +を +抜 +こうと +焦慮 +るたびにぶくぶく +深 +く +沈 +むように +噛 +めば +噛 +むほど +口 +が +重 +くなる +歯 +が +動 +かなくなる +歯答 +えはあるが +歯答 +えがあるだけでどうしても +始末 +をつける +事 +が +出来 +ない +美学者迷亭先生 +がかつて +吾輩 +の +主人 +を +評 +して +君 +は +割 +り +切 +れない +男 +だといった +事 +があるが +なるほどうまい +事 +をいったものだ +この +餅 +も +主人 +と +同 +じようにどうしても +割 +り +切 +れない +噛 +んでも +噛 +んでも +三 +で +十 +を +割 +るごとく +尽未来際方 +のつく +期 +はあるまいと +思 +われた +この +煩悶 +の +際吾輩 +は +覚 +えず +第二 +の +真理 +に +逢着 +した +すべての +動物 +は +直覚的 +に +事物 +の +適不適 +を +予知 +す +真理 +はすでに +二 +つまで +発明 +したが +餅 +がくっ +付 +いているので +毫 +も +愉快 +を +感 +じない +歯 +が +餅 +の +肉 +に +吸収 +されて +抜 +けるように +痛 +い +早 +く +食 +い +切 +って +逃 +げないと +御三 +が +来 +る +小供 +の +唱歌 +もやんだようだ +きっと +台所 +へ +馳 +け +出 +して +来 +るに +相違 +ない +煩悶 +の +極尻尾 +をぐるぐる +振 +って +見 +たが +何等 +の +功能 +もない +耳 +を +立 +てたり +寝 +かしたりしたが +駄目 +である +考 +えて +見 +ると +耳 +と +尻尾 +は +餅 +と +何等 +の +関係 +もない +要 +するに +振 +り +損 +の +立 +て +損 +の +寝 +かし +損 +であると +気 +が +付 +いたからやめにした +ようやくの +事 +これは +前足 +の +助 +けを +借 +りて +餅 +を +払 +い +落 +すに +限 +ると +考 +え +付 +いた +まず +右 +の +方 +をあげて +口 +の +周囲 +を +撫 +で +廻 +す +撫 +でたくらいで +割 +り +切 +れる +訳 +のものではない +今度 +は +左 +りの +方 +を +伸 +して +口 +を +中心 +として +急劇 +に +円 +を +劃 +して +見 +る +そんな +呪 +いで +魔 +は +落 +ちない +辛防 +が +肝心 +だと +思 +って +左右交 +る +交 +るに +動 +かしたがやはり +依然 +として +歯 +は +餅 +の +中 +にぶら +下 +っている +ええ +面倒 +だと +両足 +を +一度 +に +使 +う +すると +不思議 +な +事 +にこの +時 +だけは +後足二本 +で +立 +つ +事 +が +出来 +た +何 +だか +猫 +でないような +感 +じがする +猫 +であろうが +あるまいがこうなった +日 +にゃあ +構 +うものか +何 +でも +餅 +の +魔 +が +落 +ちるまでやるべしという +意気込 +みで +無茶苦茶 +に +顔中引 +っ +掻 +き +廻 +す +前足 +の +運動 +が +猛烈 +なのでややともすると +中心 +を +失 +って +倒 +れかかる +倒 +れかかるたびに +後足 +で +調子 +をとらなくてはならぬから +一 +つ +所 +にいる +訳 +にも +行 +かんので +台所中 +あちら +こちらと +飛 +んで +廻 +る +我 +ながらよくこんなに +器用 +に +起 +っていられたものだと +思 +う +第三 +の +真理 +が +驀地 +に +現前 +する +危 +きに +臨 +めば +平常 +なし +能 +わざるところのものを +為 +し +能 +う +之 +を +天祐 +という +幸 +に +天祐 +を +享 +けたる +吾輩 +が +一生懸命餅 +の +魔 +と +戦 +っていると +何 +だか +足音 +がして +奥 +より +人 +が +来 +るような +気合 +である +ここで +人 +に +来 +られては +大変 +だと +思 +って +いよいよ +躍起 +となって +台所 +をかけ +廻 +る +足音 +はだんだん +近付 +いてくる +ああ +残念 +だが +天祐 +が +少 +し +足 +りない +とうとう +小供 +に +見付 +けられた +あら +猫 +が +御雑煮 +を +食 +べて +踊 +を +踊 +っている +と +大 +きな +声 +をする +この +声 +を +第一 +に +聞 +きつけたのが +御三 +である +羽根 +も +羽子板 +も +打 +ち +遣 +って +勝手 +から +あらまあ +と +飛込 +んで +来 +る +細君 +は +縮緬 +の +紋付 +で +いやな +猫 +ねえ +と +仰 +せられる +主人 +さえ +書斎 +から +出 +て +来 +て +この +馬鹿野郎 +といった +面白 +い +面白 +いと +云 +うのは +小供 +ばかりである +そうしてみんな +申 +し +合 +せたようにげらげら +笑 +っている +腹 +は +立 +つ +苦 +しくはある +踊 +はやめる +訳 +にゆかぬ +弱 +った +ようやく +笑 +いがやみそうになったら +五 +つになる +女 +の +子 +が +御 +かあ +様 +猫 +も +随分 +ね +といったので +狂瀾 +を +既倒 +に +何 +とかするという +勢 +でまた +大変笑 +われた +人間 +の +同情 +に +乏 +しい +実行 +も +大分見聞 +したが +この +時 +ほど +恨 +めしく +感 +じた +事 +はなかった +ついに +天祐 +もどっかへ +消 +え +失 +せて +在来 +の +通 +り +四 +つ +這 +になって +眼 +を +白黒 +するの +醜態 +を +演 +ずるまでに +閉口 +した +さすが +見殺 +しにするのも +気 +の +毒 +と +見 +えて +まあ +餅 +をとってやれ +と +主人 +が +御三 +に +命 +ずる +御三 +はもっと +踊 +らせようじゃありませんかという +眼付 +で +細君 +を +見 +る +細君 +は +踊 +は +見 +たいが +殺 +してまで +見 +る +気 +はないのでだまっている +取 +ってやらんと +死 +んでしまう +早 +くとってやれ +と +主人 +は +再 +び +下女 +を +顧 +みる +御三 +は +御馳走 +を +半分食 +べかけて +夢 +から +起 +された +時 +のように +気 +のない +顔 +をして +餅 +をつかんでぐいと +引 +く +寒月君 +じゃないが +前歯 +がみんな +折 +れるかと +思 +った +どうも +痛 +いの +痛 +くないのって +餅 +の +中 +へ +堅 +く +食 +い +込 +んでいる +歯 +を +情 +け +容赦 +もなく +引張 +るのだからたまらない +吾輩 +が +すべての +安楽 +は +困苦 +を +通過 +せざるべからず +と +云 +う +第四 +の +真理 +を +経験 +して +けろけろとあたりを +見廻 +した +時 +には +家人 +はすでに +奥座敷 +へ +這入 +ってしまっておった +こんな +失敗 +をした +時 +には +内 +にいて +御三 +なんぞに +顔 +を +見 +られるのも +何 +となくばつが +悪 +い +いっその +事気 +を +易 +えて +新道 +の +二絃琴 +の +御師匠 +さんの +所 +の +三毛子 +でも +訪問 +しようと +台所 +から +裏 +へ +出 +た +三毛子 +はこの +近辺 +で +有名 +な +美貌家 +である +吾輩 +は +猫 +には +相違 +ないが +物 +の +情 +けは +一通 +り +心得 +ている +うちで +主人 +の +苦 +い +顔 +を +見 +たり +御三 +の +険突 +を +食 +って +気分 +が +勝 +れん +時 +は +必 +ずこの +異性 +の +朋友 +の +許 +を +訪問 +していろいろな +話 +をする +すると +いつの +間 +にか +心 +が +晴々 +して +今 +までの +心配 +も +苦労 +も +何 +もかも +忘 +れて +生 +れ +変 +ったような +心持 +になる +女性 +の +影響 +というものは +実 +に +莫大 +なものだ +杉垣 +の +隙 +から +いるかなと +思 +って +見渡 +すと +三毛子 +は +正月 +だから +首輪 +の +新 +しいのをして +行儀 +よく +椽側 +に +坐 +っている +その +背中 +の +丸 +さ +加減 +が +言 +うに +言 +われんほど +美 +しい +曲線 +の +美 +を +尽 +している +尻尾 +の +曲 +がり +加減 +足 +の +折 +り +具合 +物憂 +げに +耳 +をちょいちょい +振 +る +景色 +なども +到底形容 +が +出来 +ん +ことによく +日 +の +当 +る +所 +に +暖 +かそうに +品 +よく +控 +えているものだから +身体 +は +静粛端正 +の +態度 +を +有 +するにも +関 +らず +天鵞毛 +を +欺 +くほどの +滑 +らかな +満身 +の +毛 +は +春 +の +光 +りを +反射 +して +風 +なきにむらむらと +微動 +するごとくに +思 +われる +吾輩 +はしばらく +恍惚 +として +眺 +めていたが +やがて +我 +に +帰 +ると +同時 +に +低 +い +声 +で +三毛子 +さん +三毛子 +さん +といいながら +前足 +で +招 +いた +三毛子 +は +あら +先生 +と +椽 +を +下 +りる +赤 +い +首輪 +につけた +鈴 +がちゃらちゃらと +鳴 +る +おや +正月 +になったら +鈴 +までつけたな +どうもいい +音 +だと +感心 +している +間 +に +吾輩 +の +傍 +に +来 +て +あら +先生 +おめでとう +と +尾 +を +左 +りへ +振 +る +吾等猫属間 +で +御互 +に +挨拶 +をするときには +尾 +を +棒 +のごとく +立 +てて +それを +左 +りへぐるりと +廻 +すのである +町内 +で +吾輩 +を +先生 +と +呼 +んでくれるのはこの +三毛子 +ばかりである +吾輩 +は +前回断 +わった +通 +りまだ +名 +はないのであるが +教師 +の +家 +にいるものだから +三毛子 +だけは +尊敬 +して +先生先生 +といってくれる +吾輩 +も +先生 +と +云 +われて +満更悪 +い +心持 +ちもしないから +はいはいと +返事 +をしている +やあおめでとう +大層立派 +に +御化粧 +が +出来 +ましたね +ええ +去年 +の +暮御師匠 +さんに +買 +って +頂 +いたの +宜 +いでしょう +とちゃらちゃら +鳴 +らして +見 +せる +なるほど +善 +い +音 +ですな +吾輩 +などは +生 +れてから +そんな +立派 +なものは +見 +た +事 +がないですよ +あらいやだ +みんなぶら +下 +げるのよ +とまたちゃらちゃら +鳴 +らす +いい +音 +でしょう +あたし +嬉 +しいわ +とちゃらちゃらちゃらちゃら +続 +け +様 +に +鳴 +らす +あなたのうちの +御師匠 +さんは +大変 +あなたを +可愛 +がっていると +見 +えますね +と +吾身 +に +引 +きくらべて +暗 +に +欣羨 +の +意 +を +洩 +らす +三毛子 +は +無邪気 +なものである +ほんとよ +まるで +自分 +の +小供 +のようよ +とあどけなく +笑 +う +猫 +だって +笑 +わないとは +限 +らない +人間 +は +自分 +よりほかに +笑 +えるものが +無 +いように +思 +っているのは +間違 +いである +吾輩 +が +笑 +うのは +鼻 +の +孔 +を +三角 +にして +咽喉仏 +を +震動 +させて +笑 +うのだから +人間 +にはわからぬはずである +一体 +あなたの +所 +の +御主人 +は +何 +ですか +あら +御主人 +だって +妙 +なのね +御師匠 +さんだわ +二絃琴 +の +御師匠 +さんよ +それは +吾輩 +も +知 +っていますがね +その +御身分 +は +何 +なんです +いずれ +昔 +しは +立派 +な +方 +なんでしょうな +ええ +君 +を +待 +つ +間 +の +姫小松 +障子 +の +内 +で +御師匠 +さんが +二絃琴 +を +弾 +き +出 +す +宜 +い +声 +でしょう +と +三毛子 +は +自慢 +する +宜 +いようだが +吾輩 +にはよくわからん +全体何 +というものですか +あれ +あれは +何 +とかってものよ +御師匠 +さんはあれが +大好 +きなの +御師匠 +さんはあれで +六十二 +よ +随分丈夫 +だわね +六十二 +で +生 +きているくらいだから +丈夫 +と +云 +わねばなるまい +吾輩 +は +はあ +と +返事 +をした +少 +し +間 +が +抜 +けたようだが +別 +に +名答 +も +出 +て +来 +なかったから +仕方 +がない +あれでも +もとは +身分 +が +大変好 +かったんだって +いつでもそうおっしゃるの +へえ +元 +は +何 +だったんです +何 +でも +天璋院様 +の +御祐筆 +の +妹 +の +御嫁 +に +行 +った +先 +きの +御 +っかさんの +甥 +の +娘 +なんだって +何 +ですって +あの +天璋院様 +の +御祐筆 +の +妹 +の +御嫁 +にいった +なるほど +少 +し +待 +って +下 +さい +天璋院様 +の +妹 +の +御祐筆 +の +あらそうじゃないの +天璋院様 +の +御祐筆 +の +妹 +の +よろしい +分 +りました +天璋院様 +のでしょう +ええ +御祐筆 +のでしょう +そうよ +御嫁 +に +行 +った +妹 +の +御嫁 +に +行 +ったですよ +そうそう +間違 +った +妹 +の +御嫁 +に +入 +った +先 +きの +御 +っかさんの +甥 +の +娘 +なんですとさ +御 +っかさんの +甥 +の +娘 +なんですか +ええ +分 +ったでしょう +いいえ +何 +だか +混雑 +して +要領 +を +得 +ないですよ +詰 +るところ +天璋院様 +の +何 +になるんですか +あなたもよっぽど +分 +らないのね +だから +天璋院様 +の +御祐筆 +の +妹 +の +御嫁 +に +行 +った +先 +きの +御 +っかさんの +甥 +の +娘 +なんだって +先 +っきっから +言 +ってるんじゃありませんか +それはすっかり +分 +っているんですがね +それが +分 +りさえすればいいんでしょう +ええ +と +仕方 +がないから +降参 +をした +吾々 +は +時 +とすると +理詰 +の +虚言 +を +吐 +かねばならぬ +事 +がある +障子 +の +中 +で +二絃琴 +の +音 +がぱったりやむと +御師匠 +さんの +声 +で +三毛 +や +三毛 +や +御飯 +だよ +と +呼 +ぶ +三毛子 +は +嬉 +しそうに +あら +御師匠 +さんが +呼 +んでいらっしゃるから +私 +し +帰 +るわ +よくって +わるいと +云 +ったって +仕方 +がない +それじゃまた +遊 +びにいらっしゃい +と +鈴 +をちゃらちゃら +鳴 +らして +庭先 +までかけて +行 +ったが +急 +に +戻 +って +来 +て +あなた +大変色 +が +悪 +くってよ +どうかしやしなくって +と +心配 +そうに +問 +いかける +まさか +雑煮 +を +食 +って +踊 +りを +踊 +ったとも +云 +われないから +何別段 +の +事 +もありませんが +少 +し +考 +え +事 +をしたら +頭痛 +がしてね +あなたと +話 +しでもしたら +直 +るだろうと +思 +って +実 +は +出掛 +けて +来 +たのですよ +そう +御大事 +になさいまし +さようなら +少 +しは +名残 +り +惜 +し +気 +に +見 +えた +これで +雑煮 +の +元気 +もさっぱりと +回復 +した +いい +心持 +になった +帰 +りに +例 +の +茶園 +を +通 +り +抜 +けようと +思 +って +霜柱 +の +融 +けかかったのを +踏 +みつけながら +建仁寺 +の +崩 +れから +顔 +を +出 +すとまた +車屋 +の +黒 +が +枯菊 +の +上 +に +背 +を +山 +にして +欠伸 +をしている +近頃 +は +黒 +を +見 +て +恐怖 +するような +吾輩 +ではないが +話 +しをされると +面倒 +だから +知 +らぬ +顔 +をして +行 +き +過 +ぎようとした +黒 +の +性質 +として +他 +が +己 +れを +軽侮 +したと +認 +むるや +否 +や +決 +して +黙 +っていない +おい +名 +なしの +権兵衛 +近頃 +じゃ +乙 +う +高 +く +留 +ってるじゃあねえか +いくら +教師 +の +飯 +を +食 +ったって +そんな +高慢 +ちきな +面 +らあするねえ +人 +つけ +面白 +くもねえ +黒 +は +吾輩 +の +有名 +になったのを +まだ +知 +らんと +見 +える +説明 +してやりたいが +到底分 +る +奴 +ではないから +まず +一応 +の +挨拶 +をして +出来得 +る +限 +り +早 +く +御免蒙 +るに +若 +くはないと +決心 +した +いや +黒君 +おめでとう +不相変元気 +がいいね +と +尻尾 +を +立 +てて +左 +へくるりと +廻 +わす +黒 +は +尻尾 +を +立 +てたぎり +挨拶 +もしない +何 +おめでてえ +正月 +でおめでたけりゃ +御 +めえなんざあ +年 +が +年中 +おめでてえ +方 +だろう +気 +をつけろい +この +吹 +い +子 +の +向 +う +面 +め +吹 +い +子 +の +向 +うづらという +句 +は +罵詈 +の +言語 +であるようだが +吾輩 +には +了解 +が +出来 +なかった +ちょっと +伺 +がうが +吹 +い +子 +の +向 +うづらと +云 +うのはどう +云 +う +意味 +かね +へん +手 +めえが +悪体 +をつかれてる +癖 +に +その +訳 +を +聞 +きゃ +世話 +あねえ +だから +正月野郎 +だって +事 +よ +正月野郎 +は +詩的 +であるが +その +意味 +に +至 +ると +吹 +い +子 +の +何 +とかよりも +一層不明瞭 +な +文句 +である +参考 +のためちょっと +聞 +いておきたいが +聞 +いたって +明瞭 +な +答弁 +は +得 +られぬに +極 +まっているから +面 +と +対 +ったまま +無言 +で +立 +っておった +いささか +手持無沙汰 +の +体 +である +すると +突然黒 +のうちの +神 +さんが +大 +きな +声 +を +張 +り +揚 +げて +おや +棚 +へ +上 +げて +置 +いた +鮭 +がない +大変 +だ +またあの +黒 +の +畜生 +が +取 +ったんだよ +ほんとに +憎 +らしい +猫 +だっちゃありゃあしない +今 +に +帰 +って +来 +たら +どうするか +見 +ていやがれ +と +怒鳴 +る +初春 +の +長閑 +な +空気 +を +無遠慮 +に +震動 +させて +枝 +を +鳴 +らさぬ +君 +が +御代 +を +大 +に +俗了 +してしまう +黒 +は +怒鳴 +るなら +怒鳴 +りたいだけ +怒鳴 +っていろと +云 +わぬばかりに +横着 +な +顔 +をして +四角 +な +顋 +を +前 +へ +出 +しながら +あれを +聞 +いたかと +合図 +をする +今 +までは +黒 +との +応対 +で +気 +がつかなかったが +見 +ると +彼 +の +足 +の +下 +には +一切 +れ +二銭三厘 +に +相当 +する +鮭 +の +骨 +が +泥 +だらけになって +転 +がっている +君不相変 +やってるな +と +今 +までの +行 +き +掛 +りは +忘 +れて +つい +感投詞 +を +奉呈 +した +黒 +はそのくらいな +事 +ではなかなか +機嫌 +を +直 +さない +何 +がやってるでえ +この +野郎 +しゃけの +一切 +や +二切 +で +相変 +らずたあ +何 +だ +人 +を +見縊 +びった +事 +をいうねえ +憚 +りながら +車屋 +の +黒 +だあ +と +腕 +まくりの +代 +りに +右 +の +前足 +を +逆 +かに +肩 +の +辺 +まで +掻 +き +上 +げた +君 +が +黒君 +だと +云 +う +事 +は +始 +めから +知 +ってるさ +知 +ってるのに +相変 +らずやってるたあ +何 +だ +何 +だてえ +事 +よ +と +熱 +いのを +頻 +りに +吹 +き +懸 +ける +人間 +なら +胸倉 +をとられて +小突 +き +廻 +されるところである +少々辟易 +して +内心困 +った +事 +になったなと +思 +っていると +再 +び +例 +の +神 +さんの +大声 +が +聞 +える +ちょいと +西川 +さん +おい +西川 +さんてば +用 +があるんだよこの +人 +あ +牛肉 +を +一斤 +すぐ +持 +って +来 +るんだよ +いいかい +分 +ったかい +牛肉 +の +堅 +くないところを +一斤 +だよ +と +牛肉注文 +の +声 +が +四隣 +の +寂寞 +を +破 +る +へん +年 +に +一遍牛肉 +を +誂 +えると +思 +って +いやに +大 +きな +声 +を +出 +しゃあがらあ +牛肉一斤 +が +隣 +り +近所 +へ +自慢 +なんだから +始末 +に +終 +えねえ +阿魔 +だ +と +黒 +は +嘲 +りながら +四 +つ +足 +を +踏張 +る +吾輩 +は +挨拶 +のしようもないから +黙 +って +見 +ている +一斤 +くらいじゃあ +承知 +が +出来 +ねえんだが +仕方 +がねえ +いいから +取 +っときゃ +今 +に +食 +ってやらあ +と +自分 +のために +誂 +えたもののごとくいう +今度 +は +本当 +の +御馳走 +だ +結構結構 +と +吾輩 +はなるべく +彼 +を +帰 +そうとする +御 +めっちの +知 +った +事 +じゃねえ +黙 +っていろ +うるせえや +と +云 +いながら +突然後足 +で +霜柱 +の +崩 +れた +奴 +を +吾輩 +の +頭 +へばさりと +浴 +びせ +掛 +ける +吾輩 +が +驚 +ろいて +からだの +泥 +を +払 +っている +間 +に +黒 +は +垣根 +を +潜 +って +どこかへ +姿 +を +隠 +した +大方西川 +の +牛 +を +覘 +に +行 +ったものであろう +家 +へ +帰 +ると +座敷 +の +中 +が +いつになく +春 +めいて +主人 +の +笑 +い +声 +さえ +陽気 +に +聞 +える +はてなと +明 +け +放 +した +椽側 +から +上 +って +主人 +の +傍 +へ +寄 +って +見 +ると +見馴 +れぬ +客 +が +来 +ている +頭 +を +奇麗 +に +分 +けて +木綿 +の +紋付 +の +羽織 +に +小倉 +の +袴 +を +着 +けて +至極真面目 +そうな +書生体 +の +男 +である +主人 +の +手 +あぶりの +角 +を +見 +ると +春慶塗 +りの +巻煙草入 +れと +並 +んで +越智東風君 +を +紹介致候水島寒月 +という +名刺 +があるので +この +客 +の +名前 +も +寒月君 +の +友人 +であるという +事 +も +知 +れた +主客 +の +対話 +は +途中 +からであるから +前後 +がよく +分 +らんが +何 +でも +吾輩 +が +前回 +に +紹介 +した +美学者迷亭君 +の +事 +に +関 +しているらしい +それで +面白 +い +趣向 +があるから +是非 +いっしょに +来 +いとおっしゃるので +と +客 +は +落 +ちついて +云 +う +何 +ですか +その +西洋料理 +へ +行 +って +午飯 +を +食 +うのについて +趣向 +があるというのですか +と +主人 +は +茶 +を +続 +ぎ +足 +して +客 +の +前 +へ +押 +しやる +さあ +その +趣向 +というのが +その +時 +は +私 +にも +分 +らなかったんですが +いずれあの +方 +の +事 +ですから +何 +か +面白 +い +種 +があるのだろうと +思 +いまして +いっしょに +行 +きましたか +なるほど +ところが +驚 +いたのです +主人 +はそれ +見 +たかと +云 +わぬばかりに +膝 +の +上 +に +乗 +った +吾輩 +の +頭 +をぽかと +叩 +く +少 +し +痛 +い +また +馬鹿 +な +茶番見 +たような +事 +なんでしょう +あの +男 +はあれが +癖 +でね +と +急 +に +アンドレア +デル +サルト +事件 +を +思 +い +出 +す +へへ +君何 +か +変 +ったものを +食 +おうじゃないかとおっしゃるので +何 +を +食 +いました +まず +献立 +を +見 +ながらいろいろ +料理 +についての +御話 +しがありました +誂 +らえない +前 +にですか +ええ +それから +それから +首 +を +捻 +って +ボイ +の +方 +を +御覧 +になって +どうも +変 +ったものもないようだなとおっしゃると +ボイ +は +負 +けぬ +気 +で +鴨 +の +ロ +ス +か +小牛 +の +チャップ +などは +如何 +ですと +云 +うと +先生 +は +そんな +月並 +を +食 +いにわざわざここまで +来 +やしないとおっしゃるんで +ボイ +は +月並 +という +意味 +が +分 +らんものですから +妙 +な +顔 +をして +黙 +っていましたよ +そうでしょう +それから +私 +の +方 +を +御向 +きになって +君仏蘭西 +や +英吉利 +へ +行 +くと +随分天明調 +や +万葉調 +が +食 +えるんだが +日本 +じゃどこへ +行 +ったって +版 +で +圧 +したようで +どうも +西洋料理 +へ +這入 +る +気 +がしないと +云 +うような +大気 +で +全体 +あの +方 +は +洋行 +なすった +事 +があるのですかな +何迷亭 +が +洋行 +なんかするもんですか +そりゃ +金 +もあり +時 +もあり +行 +こうと +思 +えばいつでも +行 +かれるんですがね +大方 +これから +行 +くつもりのところを +過去 +に +見立 +てた +洒落 +なんでしょう +と +主人 +は +自分 +ながらうまい +事 +を +言 +ったつもりで +誘 +い +出 +し +笑 +をする +客 +はさまで +感服 +した +様子 +もない +そうですか +私 +はまたいつの +間 +に +洋行 +なさったかと +思 +って +つい +真面目 +に +拝聴 +していました +それに +見 +て +来 +たようになめくじの +ソップ +の +御話 +や +蛙 +の +シチュ +の +形容 +をなさるものですから +そりゃ +誰 +かに +聞 +いたんでしょう +うそをつく +事 +はなかなか +名人 +ですからね +どうもそうのようで +と +花瓶 +の +水仙 +を +眺 +める +少 +しく +残念 +の +気色 +にも +取 +られる +じゃ +趣向 +というのは +それなんですね +と +主人 +が +念 +を +押 +す +いえそれはほんの +冒頭 +なので +本論 +はこれからなのです +ふ +ん +と +主人 +は +好奇的 +な +感投詞 +を +挟 +む +それから +とてもなめくじや +蛙 +は +食 +おうっても +食 +えやしないから +まあ +トチメンボ +くらいなところで +負 +けとく +事 +にしようじゃないか +君 +と +御相談 +なさるものですから +私 +はつい +何 +の +気 +なしに +それがいいでしょう +といってしまったので +へ +とちめんぼうは +妙 +ですな +ええ +全 +く +妙 +なのですが +先生 +があまり +真面目 +だものですから +つい +気 +がつきませんでした +とあたかも +主人 +に +向 +って +麁忽 +を +詫 +びているように +見 +える +それからどうしました +と +主人 +は +無頓着 +に +聞 +く +客 +の +謝罪 +には +一向同情 +を +表 +しておらん +それから +ボイ +におい +トチメンボ +を +二人前持 +って +来 +いというと +ボイ +が +メンチボ +ですかと +聞 +き +直 +しましたが +先生 +はますます +真面目 +な +貌 +で +メンチボ +じゃない +トチメンボ +だと +訂正 +されました +なある +その +トチメンボ +という +料理 +は +一体 +あるんですか +さあ +私 +も +少 +しおかしいとは +思 +いましたがいかにも +先生 +が +沈着 +であるし +その +上 +あの +通 +りの +西洋通 +でいらっしゃるし +ことにその +時 +は +洋行 +なすったものと +信 +じ +切 +っていたものですから +私 +も +口 +を +添 +えて +トチメンボ +だ +トチメンボ +だと +ボイ +に +教 +えてやりました +ボイ +はどうしました +ボイ +がね +今考 +えると +実 +に +滑稽 +なんですがね +しばらく +思案 +していましてね +はなはだ +御気 +の +毒様 +ですが +今日 +は +トチメンボ +は +御生憎様 +で +メンチボ +なら +御二人前 +すぐに +出来 +ますと +云 +うと +先生 +は +非常 +に +残念 +な +様子 +で +それじゃせっかくここまで +来 +た +甲斐 +がない +どうか +トチメンボ +を +都合 +して +食 +わせてもらう +訳 +には +行 +くまいかと +ボイ +に +二十銭銀貨 +をやられると +ボイ +はそれではともかくも +料理番 +と +相談 +して +参 +りましょうと +奥 +へ +行 +きましたよ +大変 +トチメンボ +が +食 +いたかったと +見 +えますね +しばらくして +ボイ +が +出 +て +来 +て +真 +に +御生憎 +で +御誂 +ならこしらえますが +少々時間 +がかかります +と +云 +うと +迷亭先生 +は +落 +ちついたもので +どうせ +我々 +は +正月 +でひまなんだから +少 +し +待 +って +食 +って +行 +こうじゃないかと +云 +いながら +ポッケット +から +葉巻 +を +出 +してぷかりぷかり +吹 +かし +始 +められたので +私 +しも +仕方 +がないから +懐 +から +日本新聞 +を +出 +して +読 +み +出 +しました +すると +ボイ +はまた +奥 +へ +相談 +に +行 +きましたよ +いやに +手数 +が +掛 +りますな +と +主人 +は +戦争 +の +通信 +を +読 +むくらいの +意気込 +で +席 +を +前 +める +すると +ボイ +がまた +出 +て +来 +て +近頃 +は +トチメンボ +の +材料 +が +払底 +で +亀屋 +へ +行 +っても +横浜 +の +十五番 +へ +行 +っても +買 +われませんから +当分 +の +間 +は +御生憎様 +でと +気 +の +毒 +そうに +云 +うと +先生 +はそりゃ +困 +ったな +せっかく +来 +たのになあと +私 +の +方 +を +御覧 +になってしきりに +繰 +り +返 +さるるので +私 +も +黙 +っている +訳 +にも +参 +りませんから +どうも +遺憾 +ですな +遺憾極 +るですなと +調子 +を +合 +せたのです +ごもっともで +と +主人 +が +賛成 +する +何 +がごもっともだか +吾輩 +にはわからん +すると +ボイ +も +気 +の +毒 +だと +見 +えて +その +内材料 +が +参 +りましたら +どうか +願 +いますってんでしょう +先生 +が +材料 +は +何 +を +使 +うかねと +問 +われると +ボイ +はへへへへと +笑 +って +返事 +をしないんです +材料 +は +日本派 +の +俳人 +だろうと +先生 +が +押 +し +返 +して +聞 +くと +ボイ +はへえさようで +それだものだから +近頃 +は +横浜 +へ +行 +っても +買 +われませんので +まことにお +気 +の +毒様 +と +云 +いましたよ +アハハハ +それが +落 +ちなんですか +こりゃ +面白 +い +と +主人 +はいつになく +大 +きな +声 +で +笑 +う +膝 +が +揺 +れて +吾輩 +は +落 +ちかかる +主人 +はそれにも +頓着 +なく +笑 +う +アンドレア +デル +サルト +に +罹 +ったのは +自分一人 +でないと +云 +う +事 +を +知 +ったので +急 +に +愉快 +になったものと +見 +える +それから +二人 +で +表 +へ +出 +ると +どうだ +君 +うまく +行 +ったろう +橡面坊 +を +種 +に +使 +ったところが +面白 +かろうと +大得意 +なんです +敬服 +の +至 +りですと +云 +って +御別 +れしたようなものの +実 +は +午飯 +の +時刻 +が +延 +びたので +大変空腹 +になって +弱 +りましたよ +それは +御迷惑 +でしたろう +と +主人 +は +始 +めて +同情 +を +表 +する +これには +吾輩 +も +異存 +はない +しばらく +話 +しが +途切 +れて +吾輩 +の +咽喉 +を +鳴 +らす +音 +が +主客 +の +耳 +に +入 +る +東風君 +は +冷 +めたくなった +茶 +をぐっと +飲 +み +干 +して +実 +は +今日参 +りましたのは +少々先生 +に +御願 +があって +参 +ったので +と +改 +まる +はあ +何 +か +御用 +で +と +主人 +も +負 +けずに +済 +ます +御承知 +の +通 +り +文学美術 +が +好 +きなものですから +結構 +で +と +油 +を +注 +す +同志 +だけがよりましてせんだってから +朗読会 +というのを +組織 +しまして +毎月一回会合 +してこの +方面 +の +研究 +をこれから +続 +けたいつもりで +すでに +第一回 +は +去年 +の +暮 +に +開 +いたくらいであります +ちょっと +伺 +っておきますが +朗読会 +と +云 +うと +何 +か +節奏 +でも +附 +けて +詩歌文章 +の +類 +を +読 +むように +聞 +えますが +一体 +どんな +風 +にやるんです +まあ +初 +めは +古人 +の +作 +からはじめて +追々 +は +同人 +の +創作 +なんかもやるつもりです +古人 +の +作 +というと +白楽天 +の +琵琶行 +のようなものででもあるんですか +いいえ +蕪村 +の +春風馬堤曲 +の +種類 +ですか +いいえ +それじゃ +どんなものをやったんです +せんだっては +近松 +の +心中物 +をやりました +近松 +あの +浄瑠璃 +の +近松 +ですか +近松 +に +二人 +はない +近松 +といえば +戯曲家 +の +近松 +に +極 +っている +それを +聞 +き +直 +す +主人 +はよほど +愚 +だと +思 +っていると +主人 +は +何 +にも +分 +らずに +吾輩 +の +頭 +を +叮嚀 +に +撫 +でている +藪睨 +みから +惚 +れられたと +自認 +している +人間 +もある +世 +の +中 +だからこのくらいの +誤謬 +は +決 +して +驚 +くに +足 +らんと +撫 +でらるるがままにすましていた +ええ +と +答 +えて +東風子 +は +主人 +の +顔色 +を +窺 +う +それじゃ +一人 +で +朗読 +するのですか +または +役割 +を +極 +めてやるんですか +役 +を +極 +めて +懸合 +でやって +見 +ました +その +主意 +はなるべく +作中 +の +人物 +に +同情 +を +持 +ってその +性格 +を +発揮 +するのを +第一 +として +それに +手真似 +や +身振 +りを +添 +えます +白 +はなるべくその +時代 +の +人 +を +写 +し +出 +すのが +主 +で +御嬢 +さんでも +丁稚 +でも +その +人物 +が +出 +てきたようにやるんです +じゃ +まあ +芝居見 +たようなものじゃありませんか +ええ +衣装 +と +書割 +がないくらいなものですな +失礼 +ながらうまく +行 +きますか +まあ +第一回 +としては +成功 +した +方 +だと +思 +います +それでこの +前 +やったとおっしゃる +心中物 +というと +その +船頭 +が +御客 +を +乗 +せて +芳原 +へ +行 +く +所 +なんで +大変 +な +幕 +をやりましたな +と +教師 +だけにちょっと +首 +を +傾 +ける +鼻 +から +吹 +き +出 +した +日 +の +出 +の +煙 +りが +耳 +を +掠 +めて +顔 +の +横手 +へ +廻 +る +なあに +そんなに +大変 +な +事 +もないんです +登場 +の +人物 +は +御客 +と +船頭 +と +花魁 +と +仲居 +と +遣手 +と +見番 +だけですから +と +東風子 +は +平気 +なものである +主人 +は +花魁 +という +名 +をきいてちょっと +苦 +い +顔 +をしたが +仲居 +遣手 +見番 +という +術語 +について +明瞭 +の +智識 +がなかったと +見 +えてまず +質問 +を +呈出 +した +仲居 +というのは +娼家 +の +下婢 +にあたるものですかな +まだよく +研究 +はして +見 +ませんが +仲居 +は +茶屋 +の +下女 +で +遣手 +というのが +女部屋 +の +助役見 +たようなものだろうと +思 +います +東風子 +はさっき +その +人物 +が +出 +て +来 +るように +仮色 +を +使 +うと +云 +った +癖 +に +遣手 +や +仲居 +の +性格 +をよく +解 +しておらんらしい +なるほど +仲居 +は +茶屋 +に +隷属 +するもので +遣手 +は +娼家 +に +起臥 +する +者 +ですね +次 +に +見番 +と +云 +うのは +人間 +ですかまたは +一定 +の +場所 +を +指 +すのですか +もし +人間 +とすれば +男 +ですか +女 +ですか +見番 +は +何 +でも +男 +の +人間 +だと +思 +います +何 +を +司 +どっているんですかな +さあそこまではまだ +調 +べが +届 +いておりません +その +内調 +べて +見 +ましょう +これで +懸合 +をやった +日 +には +頓珍漢 +なものが +出来 +るだろうと +吾輩 +は +主人 +の +顔 +をちょっと +見上 +げた +主人 +は +存外真面目 +である +それで +朗読家 +は +君 +のほかにどんな +人 +が +加 +わったんですか +いろいろおりました +花魁 +が +法学士 +の +君 +でしたが +口髯 +を +生 +やして +女 +の +甘 +ったるいせりふを +使 +かうのですからちょっと +妙 +でした +それにその +花魁 +が +癪 +を +起 +すところがあるので +朗読 +でも +癪 +を +起 +さなくっちゃ +いけないんですか +と +主人 +は +心配 +そうに +尋 +ねる +ええとにかく +表情 +が +大事 +ですから +と +東風子 +はどこまでも +文芸家 +の +気 +でいる +うまく +癪 +が +起 +りましたか +と +主人 +は +警句 +を +吐 +く +癪 +だけは +第一回 +には +ちと +無理 +でした +と +東風子 +も +警句 +を +吐 +く +ところで +君 +は +何 +の +役割 +でした +と +主人 +が +聞 +く +私 +しは +船頭 +へ +君 +が +船頭 +君 +にして +船頭 +が +務 +まるものなら +僕 +にも +見番 +くらいはやれると +云 +ったような +語気 +を +洩 +らす +やがて +船頭 +は +無理 +でしたか +と +御世辞 +のないところを +打 +ち +明 +ける +東風子 +は +別段癪 +に +障 +った +様子 +もない +やはり +沈着 +な +口調 +で +その +船頭 +でせっかくの +催 +しも +竜頭蛇尾 +に +終 +りました +実 +は +会場 +の +隣 +りに +女学生 +が +四五人下宿 +していましてね +それがどうして +聞 +いたものか +その +日 +は +朗読会 +があるという +事 +を +どこかで +探知 +して +会場 +の +窓下 +へ +来 +て +傍聴 +していたものと +見 +えます +私 +しが +船頭 +の +仮色 +を +使 +って +ようやく +調子 +づいてこれなら +大丈夫 +と +思 +って +得意 +にやっていると +つまり +身振 +りがあまり +過 +ぎたのでしょう +今 +まで +耐 +らえていた +女学生 +が +一度 +にわっと +笑 +いだしたものですから +驚 +ろいた +事 +も +驚 +ろいたし +極 +りが +悪 +るい +事 +も +悪 +るいし +それで +腰 +を +折 +られてから +どうしても +後 +がつづけられないので +とうとうそれ +限 +りで +散会 +しました +第一回 +としては +成功 +だと +称 +する +朗読会 +がこれでは +失敗 +はどんなものだろうと +想像 +すると +笑 +わずにはいられない +覚 +えず +咽喉仏 +がごろごろ +鳴 +る +主人 +はいよいよ +柔 +かに +頭 +を +撫 +でてくれる +人 +を +笑 +って +可愛 +がられるのはありがたいが +いささか +無気味 +なところもある +それは +飛 +んだ +事 +で +と +主人 +は +正月早々弔詞 +を +述 +べている +第二回 +からは +もっと +奮発 +して +盛大 +にやるつもりなので +今日出 +ましたのも +全 +くそのためで +実 +は +先生 +にも +一 +つ +御入会 +の +上御尽力 +を +仰 +ぎたいので +僕 +にはとても +癪 +なんか +起 +せませんよ +と +消極的 +の +主人 +はすぐに +断 +わりかける +いえ +癪 +などは +起 +していただかんでもよろしいので +ここに +賛助員 +の +名簿 +が +と +云 +いながら +紫 +の +風呂敷 +から +大事 +そうに +小菊版 +の +帳面 +を +出 +す +これへどうか +御署名 +の +上御捺印 +を +願 +いたいので +と +帳面 +を +主人 +の +膝 +の +前 +へ +開 +いたまま +置 +く +見 +ると +現今知名 +な +文学博士 +文学士連中 +の +名 +が +行儀 +よく +勢揃 +をしている +はあ +賛成員 +にならん +事 +もありませんが +どんな +義務 +があるのですか +と +牡蠣先生 +は +掛念 +の +体 +に +見 +える +義務 +と +申 +して +別段是非願 +う +事 +もないくらいで +ただ +御名前 +だけを +御記入下 +さって +賛成 +の +意 +さえ +御表 +し +被下 +ればそれで +結構 +です +そんなら +這入 +ります +と +義務 +のかからぬ +事 +を +知 +るや +否 +や +主人 +は +急 +に +気軽 +になる +責任 +さえないと +云 +う +事 +が +分 +っておれば +謀叛 +の +連判状 +へでも +名 +を +書 +き +入 +れますと +云 +う +顔付 +をする +加之 +こう +知名 +の +学者 +が +名前 +を +列 +ねている +中 +に +姓名 +だけでも +入籍 +させるのは +今 +までこんな +事 +に +出合 +った +事 +のない +主人 +にとっては +無上 +の +光栄 +であるから +返事 +の +勢 +のあるのも +無理 +はない +ちょっと +失敬 +と +主人 +は +書斎 +へ +印 +をとりに +這入 +る +吾輩 +はぼたりと +畳 +の +上 +へ +落 +ちる +東風子 +は +菓子皿 +の +中 +の +カステラ +をつまんで +一口 +に +頬張 +る +モゴモゴ +しばらくは +苦 +しそうである +吾輩 +は +今朝 +の +雑煮事件 +をちょっと +思 +い +出 +す +主人 +が +書斎 +から +印形 +を +持 +って +出 +て +来 +た +時 +は +東風子 +の +胃 +の +中 +に +カステラ +が +落 +ちついた +時 +であった +主人 +は +菓子皿 +の +カステラ +が +一切足 +りなくなった +事 +には +気 +が +着 +かぬらしい +もし +気 +がつくとすれば +第一 +に +疑 +われるものは +吾輩 +であろう +東風子 +が +帰 +ってから +主人 +が +書斎 +に +入 +って +机 +の +上 +を +見 +ると +いつの +間 +にか +迷亭先生 +の +手紙 +が +来 +ている +新年 +の +御慶目出度申納候 +いつになく +出 +が +真面目 +だと +主人 +が +思 +う +迷亭先生 +の +手紙 +に +真面目 +なのはほとんどないので +この +間 +などは +其後別 +に +恋着 +せる +婦人 +も +無之 +いず +方 +より +艶書 +も +参 +らず +先 +ず +先 +ず +無事 +に +消光罷 +り +在 +り +候間 +乍憚御休心可被下候 +と +云 +うのが +来 +たくらいである +それに +較 +べるとこの +年始状 +は +例外 +にも +世間的 +である +一寸参堂仕 +り +度候 +えども +大兄 +の +消極主義 +に +反 +して +出来得 +る +限 +り +積極的方針 +を +以 +て +此千古未曾有 +の +新年 +を +迎 +うる +計画故 +毎日毎日目 +の +廻 +る +程 +の +多忙 +御推察願上候 +なるほどあの +男 +の +事 +だから +正月 +は +遊 +び +廻 +るのに +忙 +がしいに +違 +いないと +主人 +は +腹 +の +中 +で +迷亭君 +に +同意 +する +昨日 +は +一刻 +のひまを +偸 +み +東風子 +に +トチメンボ +の +御馳走 +を +致 +さんと +存 +じ +候処 +生憎材料払底 +の +為 +め +其意 +を +果 +さず +遺憾千万 +に +存候 +そろそろ +例 +の +通 +りになって +来 +たと +主人 +は +無言 +で +微笑 +する +明日 +は +某男爵 +の +歌留多会 +明後日 +は +審美学協会 +の +新年宴会 +其明日 +は +鳥部教授歓迎会 +其又明日 +は +うるさいなと +主人 +は +読 +みとばす +右 +の +如 +く +謡曲会 +俳句会 +短歌会 +新体詩会等 +会 +の +連発 +にて +当分 +の +間 +は +のべつ +幕無 +しに +出勤致 +し +候為 +め +不得已賀状 +を +以 +て +拝趨 +の +礼 +に +易 +え +候段不悪御宥恕被下度候 +別段 +くるにも +及 +ばんさと +主人 +は +手紙 +に +返事 +をする +今度御光来 +の +節 +は +久 +し +振 +りにて +晩餐 +でも +供 +し +度心得 +に +御座候 +寒厨何 +の +珍味 +も +無之候 +えども +せめては +トチメンボ +でもと +只今 +より +心掛居候 +まだ +トチメンボ +を +振 +り +廻 +している +失敬 +なと +主人 +はちょっとむっとする +然 +し +トチメンボ +は +近頃材料払底 +の +為 +め +ことに +依 +ると +間 +に +合 +い +兼候 +も +計 +りがたきにつき +其節 +は +孔雀 +の +舌 +でも +御風味 +に +入 +れ +可申候 +両天秤 +をかけたなと +主人 +は +あとが +読 +みたくなる +御承知 +の +通 +り +孔雀一羽 +につき +舌肉 +の +分量 +は +小指 +の +半 +ばにも +足 +らぬ +程故健啖 +なる +大兄 +の +胃嚢 +を +充 +たす +為 +には +うそをつけと +主人 +は +打 +ち +遣 +ったようにいう +是非共二三十羽 +の +孔雀 +を +捕獲致 +さざる +可 +らずと +存候 +然 +る +所孔雀 +は +動物園 +浅草花屋敷等 +には +ちらほら +見受 +け +候 +えども +普通 +の +鳥屋抔 +には +一向見当 +り +不申 +苦心此事 +に +御座候 +独 +りで +勝手 +に +苦心 +しているのじゃないかと +主人 +は +毫 +も +感謝 +の +意 +を +表 +しない +此孔雀 +の +舌 +の +料理 +は +往昔羅馬全盛 +の +砌 +り +一時非常 +に +流行致 +し +候 +ものにて +豪奢風流 +の +極度 +と +平生 +よりひそかに +食指 +を +動 +かし +居候次第御諒察可被下候 +何 +が +御諒察 +だ +馬鹿 +なと +主人 +はすこぶる +冷淡 +である +降 +って +十六七世紀 +の +頃迄 +は +全欧 +を +通 +じて +孔雀 +は +宴席 +に +欠 +くべからざる +好味 +と +相成居候 +レスタ +伯 +が +エリザベス +女皇 +を +ケニルウォ +ス +に +招待致 +し +候節 +も +慥 +か +孔雀 +を +使用致 +し +候様記憶致候 +有名 +なる +レンブラント +が +画 +き +候饗宴 +の +図 +にも +孔雀 +が +尾 +を +広 +げたる +儘卓上 +に +横 +わり +居 +り +候 +孔雀 +の +料理史 +をかくくらいなら +そんなに +多忙 +でもなさそうだと +不平 +をこぼす +とにかく +近頃 +の +如 +く +御馳走 +の +食 +べ +続 +けにては +さすがの +小生 +も +遠 +からぬうちに +大兄 +の +如 +く +胃弱 +と +相成 +るは +必定 +大兄 +のごとくは +余計 +だ +何 +も +僕 +を +胃弱 +の +標準 +にしなくても +済 +むと +主人 +はつぶやいた +歴史家 +の +説 +によれば +羅馬人 +は +日 +に +二度三度 +も +宴会 +を +開 +き +候由 +日 +に +二度 +も +三度 +も +方丈 +の +食饌 +に +就 +き +候 +えば +如何 +なる +健胃 +の +人 +にても +消化機能 +に +不調 +を +醸 +すべく +従 +って +自然 +は +大兄 +の +如 +く +また +大兄 +のごとくか +失敬 +な +然 +るに +贅沢 +と +衛生 +とを +両立 +せしめんと +研究 +を +尽 +したる +彼等 +は +不相当 +に +多量 +の +滋味 +を +貪 +ると +同時 +に +胃腸 +を +常態 +に +保持 +するの +必要 +を +認 +め +ここに +一 +の +秘法 +を +案出致 +し +候 +はてねと +主人 +は +急 +に +熱心 +になる +彼等 +は +食後必 +ず +入浴致候 +入浴後一種 +の +方法 +によりて +浴前 +に +嚥下 +せるものを +悉 +く +嘔吐 +し +胃内 +を +掃除致 +し +候 +胃内廓清 +の +功 +を +奏 +したる +後又食卓 +に +就 +き +飽 +く +迄珍味 +を +風好 +し +風好 +し +了 +れば +又湯 +に +入 +りて +之 +を +吐出致候 +かくの +如 +くすれば +好物 +は +貪 +ぼり +次第貪 +り +候 +も +毫 +も +内臓 +の +諸機関 +に +障害 +を +生 +ぜず +一挙両得 +とは +此等 +の +事 +を +可申 +かと +愚考致候 +なるほど +一挙両得 +に +相違 +ない +主人 +は +羨 +ましそうな +顔 +をする +廿世紀 +の +今日交通 +の +頻繁 +宴会 +の +増加 +は +申 +す +迄 +もなく +軍国多事征露 +の +第二年 +とも +相成候折柄 +吾人戦勝国 +の +国民 +は +是非共羅馬人 +に +傚 +って +此入浴嘔吐 +の +術 +を +研究 +せざるべからざる +機会 +に +到着致 +し +候事 +と +自信致候 +左 +もなくば +切角 +の +大国民 +も +近 +き +将来 +に +於 +て +悉 +く +大兄 +の +如 +く +胃病患者 +と +相成 +る +事 +と +窃 +かに +心痛罷 +りあり +候 +また +大兄 +のごとくか +癪 +に +障 +る +男 +だと +主人 +が +思 +う +此際吾人西洋 +の +事情 +に +通 +ずる +者 +が +古史伝説 +を +考究 +し +既 +に +廃絶 +せる +秘法 +を +発見 +し +之 +を +明治 +の +社会 +に +応用致 +し +候 +わば +所謂禍 +を +未萌 +に +防 +ぐの +功徳 +にも +相成 +り +平素逸楽 +を +擅 +に +致 +し +候御恩返 +も +相立 +ち +可申 +と +存候 +何 +だか +妙 +だなと +首 +を +捻 +る +依 +て +此間中 +より +ギボン +モンセン +スミス +等諸家 +の +著述 +を +渉猟致 +し +居候 +えども +未 +だに +発見 +の +端緒 +をも +見出 +し +得 +ざるは +残念 +の +至 +に +存候 +然 +し +御存 +じの +如 +く +小生 +は +一度思 +い +立 +ち +候事 +は +成功 +するまでは +決 +して +中絶仕 +らざる +性質 +に +候 +えば +嘔吐方 +を +再興致 +し +候 +も +遠 +からぬうちと +信 +じ +居 +り +候次第 +右 +は +発見次第御報道可仕候 +につき +左様御承知可被下候 +就 +てはさきに +申上候 +トチメンボ +及 +び +孔雀 +の +舌 +の +御馳走 +も +可相成 +は +右発見後 +に +致 +し +度 +左 +すれば +小生 +の +都合 +は +勿論 +既 +に +胃弱 +に +悩 +み +居 +らるる +大兄 +の +為 +にも +御便宜 +かと +存候草々不備 +何 +だとうとう +担 +がれたのか +あまり +書 +き +方 +が +真面目 +だものだからつい +仕舞 +まで +本気 +にして +読 +んでいた +新年匆々 +こんな +悪戯 +をやる +迷亭 +はよっぽどひま +人 +だなあと +主人 +は +笑 +いながら +云 +った +それから +四五日 +は +別段 +の +事 +もなく +過 +ぎ +去 +った +白磁 +の +水仙 +がだんだん +凋 +んで +青軸 +の +梅 +が +瓶 +ながらだんだん +開 +きかかるのを +眺 +め +暮 +らしてばかりいてもつまらんと +思 +って +一両度三毛子 +を +訪問 +して +見 +たが +逢 +われない +最初 +は +留守 +だと +思 +ったが +二返目 +には +病気 +で +寝 +ているという +事 +が +知 +れた +障子 +の +中 +で +例 +の +御師匠 +さんと +下女 +が +話 +しをしているのを +手水鉢 +の +葉蘭 +の +影 +に +隠 +れて +聞 +いているとこうであった +三毛 +は +御飯 +をたべるかい +いいえ +今朝 +からまだ +何 +にも +食 +べません +あったかにして +御火燵 +に +寝 +かしておきました +何 +だか +猫 +らしくない +まるで +人間 +の +取扱 +を +受 +けている +一方 +では +自分 +の +境遇 +と +比 +べて +見 +て +羨 +ましくもあるが +一方 +では +己 +が +愛 +している +猫 +がかくまで +厚遇 +を +受 +けていると +思 +えば +嬉 +しくもある +どうも +困 +るね +御飯 +をたべないと +身体 +が +疲 +れるばかりだからね +そうでございますとも +私共 +でさえ +一日御 +をいただかないと +明 +くる +日 +はとても +働 +けませんもの +下女 +は +自分 +より +猫 +の +方 +が +上等 +な +動物 +であるような +返事 +をする +実際 +この +家 +では +下女 +より +猫 +の +方 +が +大切 +かも +知 +れない +御医者様 +へ +連 +れて +行 +ったのかい +ええ +あの +御医者 +はよっぽど +妙 +でございますよ +私 +が +三毛 +をだいて +診察場 +へ +行 +くと +風邪 +でも +引 +いたのかって +私 +の +脈 +をとろうとするんでしょう +いえ +病人 +は +私 +ではございません +これですって +三毛 +を +膝 +の +上 +へ +直 +したら +にやにや +笑 +いながら +猫 +の +病気 +はわしにも +分 +らん +抛 +っておいたら +今 +に +癒 +るだろうってんですもの +あんまり +苛 +いじゃございませんか +腹 +が +立 +ったから +それじゃ +見 +ていただかなくってもようございますこれでも +大事 +の +猫 +なんですって +三毛 +を +懐 +へ +入 +れてさっさと +帰 +って +参 +りました +ほんにねえ +ほんにねえ +は +到底吾輩 +のうちなどで +聞 +かれる +言葉 +ではない +やはり +天璋院様 +の +何 +とかの +何 +とかでなくては +使 +えない +はなはだ +雅 +であると +感心 +した +何 +だかしくしく +云 +うようだが +ええきっと +風邪 +を +引 +いて +咽喉 +が +痛 +むんでございますよ +風邪 +を +引 +くと +どなたでも +御咳 +が +出 +ますからね +天璋院様 +の +何 +とかの +何 +とかの +下女 +だけに +馬鹿叮嚀 +な +言葉 +を +使 +う +それに +近頃 +は +肺病 +とか +云 +うものが +出来 +てのう +ほんとにこの +頃 +のように +肺病 +だの +ペスト +だのって +新 +しい +病気 +ばかり +殖 +えた +日 +にゃ +油断 +も +隙 +もなりゃしませんのでございますよ +旧幕時代 +に +無 +い +者 +に +碌 +な +者 +はないから +御前 +も +気 +をつけないといかんよ +そうでございましょうかねえ +下女 +は +大 +に +感動 +している +風邪 +を +引 +くといってもあまり +出 +あるきもしないようだったに +いえね +あなた +それが +近頃 +は +悪 +い +友達 +が +出来 +ましてね +下女 +は +国事 +の +秘密 +でも +語 +る +時 +のように +大得意 +である +悪 +い +友達 +ええあの +表通 +りの +教師 +の +所 +にいる +薄 +ぎたない +雄猫 +でございますよ +教師 +と +云 +うのは +あの +毎朝無作法 +な +声 +を +出 +す +人 +かえ +ええ +顔 +を +洗 +うたんびに +鵝鳥 +が +絞 +め +殺 +されるような +声 +を +出 +す +人 +でござんす +鵝鳥 +が +絞 +め +殺 +されるような +声 +はうまい +形容 +である +吾輩 +の +主人 +は +毎朝風呂場 +で +含嗽 +をやる +時 +楊枝 +で +咽喉 +をつっ +突 +いて +妙 +な +声 +を +無遠慮 +に +出 +す +癖 +がある +機嫌 +の +悪 +い +時 +はやけにがあがあやる +機嫌 +の +好 +い +時 +は +元気 +づいてなおがあがあやる +つまり +機嫌 +のいい +時 +も +悪 +い +時 +も +休 +みなく +勢 +よくがあがあやる +細君 +の +話 +しではここへ +引越 +す +前 +まではこんな +癖 +はなかったそうだが +ある +時 +ふとやり +出 +してから +今日 +まで +一日 +もやめた +事 +がないという +ちょっと +厄介 +な +癖 +であるが +なぜこんな +事 +を +根気 +よく +続 +けているのか +吾等猫 +などには +到底想像 +もつかん +それもまず +善 +いとして +薄 +ぎたない +猫 +とは +随分酷評 +をやるものだとなお +耳 +を +立 +ててあとを +聞 +く +あんな +声 +を +出 +して +何 +の +呪 +いになるか +知 +らん +御維新前 +は +中間 +でも +草履取 +りでも +相応 +の +作法 +は +心得 +たもので +屋敷町 +などで +あんな +顔 +の +洗 +い +方 +をするものは +一人 +もおらなかったよ +そうでございましょうともねえ +下女 +は +無暗 +に +感服 +しては +無暗 +にねえを +使用 +する +あんな +主人 +を +持 +っている +猫 +だから +どうせ +野良猫 +さ +今度来 +たら +少 +し +叩 +いておやり +叩 +いてやりますとも +三毛 +の +病気 +になったのも +全 +くあいつの +御蔭 +に +相違 +ございませんもの +きっと +讐 +をとってやります +飛 +んだ +冤罪 +を +蒙 +ったものだ +こいつは +滅多 +に +近 +か +寄 +れないと +三毛子 +にはとうとう +逢 +わずに +帰 +った +帰 +って +見 +ると +主人 +は +書斎 +の +中 +で +何 +か +沈吟 +の +体 +で +筆 +を +執 +っている +二絃琴 +の +御師匠 +さんの +所 +で +聞 +いた +評判 +を +話 +したら +さぞ +怒 +るだろうが +知 +らぬが +仏 +とやらで +うんうん +云 +いながら +神聖 +な +詩人 +になりすましている +ところへ +当分多忙 +で +行 +かれないと +云 +って +わざわざ +年始状 +をよこした +迷亭君 +が +飄然 +とやって +来 +る +何 +か +新体詩 +でも +作 +っているのかね +面白 +いのが +出来 +たら +見 +せたまえ +と +云 +う +うん +ちょっとうまい +文章 +だと +思 +ったから +今翻訳 +して +見 +ようと +思 +ってね +と +主人 +は +重 +たそうに +口 +を +開 +く +文章 +誰 +れの +文章 +だい +誰 +れのか +分 +らんよ +無名氏 +か +無名氏 +の +作 +にも +随分善 +いのがあるからなかなか +馬鹿 +に +出来 +ない +全体 +どこにあったのか +と +問 +う +第二読本 +と +主人 +は +落 +ちつきはらって +答 +える +第二読本 +第二読本 +がどうしたんだ +僕 +の +翻訳 +している +名文 +と +云 +うのは +第二読本 +の +中 +にあると +云 +う +事 +さ +冗談 +じゃない +孔雀 +の +舌 +の +讐 +を +際 +どいところで +討 +とうと +云 +う +寸法 +なんだろう +僕 +は +君 +のような +法螺吹 +きとは +違 +うさ +と +口髯 +を +捻 +る +泰然 +たるものだ +昔 +しある +人 +が +山陽 +に +先生近頃名文 +はござらぬかといったら +山陽 +が +馬子 +の +書 +いた +借金 +の +催促状 +を +示 +して +近来 +の +名文 +はまずこれでしょうと +云 +ったという +話 +があるから +君 +の +審美眼 +も +存外 +たしかかも +知 +れん +どれ +読 +んで +見給 +え +僕 +が +批評 +してやるから +と +迷亭先生 +は +審美眼 +の +本家 +のような +事 +を +云 +う +主人 +は +禅坊主 +が +大燈国師 +の +遺誡 +を +読 +むような +声 +を +出 +して +読 +み +始 +める +巨人 +引力 +何 +だいその +巨人引力 +と +云 +うのは +巨人引力 +と +云 +う +題 +さ +妙 +な +題 +だな +僕 +には +意味 +がわからんね +引力 +と +云 +う +名 +を +持 +っている +巨人 +というつもりさ +少 +し +無理 +なつもりだが +表題 +だからまず +負 +けておくとしよう +それから +早々本文 +を +読 +むさ +君 +は +声 +が +善 +いからなかなか +面白 +い +雑 +ぜかえしてはいかんよ +と +予 +じめ +念 +を +押 +してまた +読 +み +始 +める +ケ +ト +は +窓 +から +外面 +を +眺 +める +小児 +が +球 +を +投 +げて +遊 +んでいる +彼等 +は +高 +く +球 +を +空中 +に +擲 +つ +球 +は +上 +へ +上 +へとのぼる +しばらくすると +落 +ちて +来 +る +彼等 +はまた +球 +を +高 +く +擲 +つ +再 +び +三度 +擲 +つたびに +球 +は +落 +ちてくる +なぜ +落 +ちるのか +なぜ +上 +へ +上 +へとのみのぼらぬかと +ケ +ト +が +聞 +く +巨人 +が +地中 +に +住 +む +故 +に +と +母 +が +答 +える +彼 +は +巨人引力 +である +彼 +は +強 +い +彼 +は +万物 +を +己 +れの +方 +へと +引 +く +彼 +は +家屋 +を +地上 +に +引 +く +引 +かねば +飛 +んでしまう +小児 +も +飛 +んでしまう +葉 +が +落 +ちるのを +見 +たろう +あれは +巨人引力 +が +呼 +ぶのである +本 +を +落 +す +事 +があろう +巨人引力 +が +来 +いというからである +球 +が +空 +にあがる +巨人引力 +は +呼 +ぶ +呼 +ぶと +落 +ちてくる +それぎりかい +むむ +甘 +いじゃないか +いやこれは +恐 +れ +入 +った +飛 +んだところで +トチメンボ +の +御返礼 +に +預 +った +御返礼 +でもなんでもないさ +実際 +うまいから +訳 +して +見 +たのさ +君 +はそう +思 +わんかね +と +金縁 +の +眼鏡 +の +奥 +を +見 +る +どうも +驚 +ろいたね +君 +にしてこの +伎倆 +あらんとは +全 +く +此度 +という +今度 +は +担 +がれたよ +降参降参 +と +一人 +で +承知 +して +一人 +で +喋舌 +る +主人 +には +一向通 +じない +何 +も +君 +を +降参 +させる +考 +えはないさ +ただ +面白 +い +文章 +だと +思 +ったから +訳 +して +見 +たばかりさ +いや +実 +に +面白 +い +そう +来 +なくっちゃ +本 +ものでない +凄 +いものだ +恐縮 +だ +そんなに +恐縮 +するには +及 +ばん +僕 +も +近頃 +は +水彩画 +をやめたから +その +代 +りに +文章 +でもやろうと +思 +ってね +どうして +遠近無差別黒白平等 +の +水彩画 +の +比 +じゃない +感服 +の +至 +りだよ +そうほめてくれると +僕 +も +乗 +り +気 +になる +と +主人 +はあくまでも +疳違 +いをしている +ところへ +寒月君 +が +先日 +は +失礼 +しましたと +這入 +って +来 +る +いや +失敬 +今大変 +な +名文 +を +拝聴 +して +トチメンボ +の +亡魂 +を +退治 +られたところで +と +迷亭先生 +は +訳 +のわからぬ +事 +をほのめかす +はあ +そうですか +とこれも +訳 +の +分 +らぬ +挨拶 +をする +主人 +だけは +左 +のみ +浮 +かれた +気色 +もない +先日 +は +君 +の +紹介 +で +越智東風 +と +云 +う +人 +が +来 +たよ +ああ +上 +りましたか +あの +越智東風 +と +云 +う +男 +は +至 +って +正直 +な +男 +ですが +少 +し +変 +っているところがあるので +あるいは +御迷惑 +かと +思 +いましたが +是非紹介 +してくれというものですから +別 +に +迷惑 +の +事 +もないがね +こちらへ +上 +っても +自分 +の +姓名 +のことについて +何 +か +弁 +じて +行 +きゃしませんか +いいえ +そんな +話 +もなかったようだ +そうですか +どこへ +行 +っても +初対面 +の +人 +には +自分 +の +名前 +の +講釈 +をするのが +癖 +でしてね +どんな +講釈 +をするんだい +と +事 +あれかしと +待 +ち +構 +えた +迷亭君 +は +口 +を +入 +れる +あの +東風 +と +云 +うのを +音 +で +読 +まれると +大変気 +にするので +はてね +と +迷亭先生 +は +金唐皮 +の +煙草入 +から +煙草 +をつまみ +出 +す +私 +しの +名 +は +越智東風 +ではありません +越智 +こちですと +必 +ず +断 +りますよ +妙 +だね +と +雲井 +を +腹 +の +底 +まで +呑 +み +込 +む +それが +全 +く +文学熱 +から +来 +たので +こちと +読 +むと +遠近 +と +云 +う +成語 +になる +のみならずその +姓名 +が +韻 +を +踏 +んでいると +云 +うのが +得意 +なんです +それだから +東風 +を +音 +で +読 +むと +僕 +がせっかくの +苦心 +を +人 +が +買 +ってくれないといって +不平 +を +云 +うのです +こりゃなるほど +変 +ってる +と +迷亭先生 +は +図 +に +乗 +って +腹 +の +底 +から +雲井 +を +鼻 +の +孔 +まで +吐 +き +返 +す +途中 +で +煙 +が +戸迷 +いをして +咽喉 +の +出口 +へ +引 +きかかる +先生 +は +煙管 +を +握 +ってごほんごほんと +咽 +び +返 +る +先日来 +た +時 +は +朗読会 +で +船頭 +になって +女学生 +に +笑 +われたといっていたよ +と +主人 +は +笑 +いながら +云 +う +うむそれそれ +と +迷亭先生 +が +煙管 +で +膝頭 +を +叩 +く +吾輩 +は +険呑 +になったから +少 +し +傍 +を +離 +れる +その +朗読会 +さ +せんだって +トチメンボ +を +御馳走 +した +時 +にね +その +話 +しが +出 +たよ +何 +でも +第二回 +には +知名 +の +文士 +を +招待 +して +大会 +をやるつもりだから +先生 +にも +是非御臨席 +を +願 +いたいって +それから +僕 +が +今度 +も +近松 +の +世話物 +をやるつもりかいと +聞 +くと +いえこの +次 +はずっと +新 +しい +者 +を +撰 +んで +金色夜叉 +にしましたと +云 +うから +君 +にゃ +何 +の +役 +が +当 +ってるかと +聞 +いたら +私 +は +御宮 +ですといったのさ +東風 +の +御宮 +は +面白 +かろう +僕 +は +是非出席 +して +喝采 +しようと +思 +ってるよ +面白 +いでしょう +と +寒月君 +が +妙 +な +笑 +い +方 +をする +しかしあの +男 +はどこまでも +誠実 +で +軽薄 +なところがないから +好 +い +迷亭 +などとは +大違 +いだ +と +主人 +は +アンドレア +デル +サルト +と +孔雀 +の +舌 +と +トチメンボ +の +復讐 +を +一度 +にとる +迷亭君 +は +気 +にも +留 +めない +様子 +で +どうせ +僕 +などは +行徳 +の +俎 +と +云 +う +格 +だからなあ +と +笑 +う +まずそんなところだろう +と +主人 +が +云 +う +実 +は +行徳 +の +俎 +と +云 +う +語 +を +主人 +は +解 +さないのであるが +さすが +永年教師 +をして +胡魔化 +しつけているものだから +こんな +時 +には +教場 +の +経験 +を +社交上 +にも +応用 +するのである +行徳 +の +俎 +というのは +何 +の +事 +ですか +と +寒月 +が +真率 +に +聞 +く +主人 +は +床 +の +方 +を +見 +て +あの +水仙 +は +暮 +に +僕 +が +風呂 +の +帰 +りがけに +買 +って +来 +て +挿 +したのだが +よく +持 +つじゃないか +と +行徳 +の +俎 +を +無理 +にねじ +伏 +せる +暮 +といえば +去年 +の +暮 +に +僕 +は +実 +に +不思議 +な +経験 +をしたよ +と +迷亭 +が +煙管 +を +大神楽 +のごとく +指 +の +尖 +で +廻 +わす +どんな +経験 +か +聞 +かし +玉 +え +と +主人 +は +行徳 +の +俎 +を +遠 +く +後 +に +見捨 +てた +気 +で +ほっと +息 +をつく +迷亭先生 +の +不思議 +な +経験 +というのを +聞 +くと +左 +のごとくである +たしか +暮 +の +二十七日 +と +記憶 +しているがね +例 +の +東風 +から +参堂 +の +上是非文芸上 +の +御高話 +を +伺 +いたいから +御在宿 +を +願 +うと +云 +う +先 +き +触 +れがあったので +朝 +から +心待 +ちに +待 +っていると +先生 +なかなか +来 +ないやね +昼飯 +を +食 +って +スト +ブ +の +前 +で +バリ +ペ +ン +の +滑稽物 +を +読 +んでいるところへ +静岡 +の +母 +から +手紙 +が +来 +たから +見 +ると +年寄 +だけにいつまでも +僕 +を +小供 +のように +思 +ってね +寒中 +は +夜間外出 +をするなとか +冷水浴 +もいいが +スト +ブ +を +焚 +いて +室 +を +煖 +かにしてやらないと +風邪 +を +引 +くとかいろいろの +注意 +があるのさ +なるほど +親 +はありがたいものだ +他人 +ではとてもこうはいかないと +呑気 +な +僕 +もその +時 +だけは +大 +に +感動 +した +それにつけても +こんなにのらくらしていては +勿体 +ない +何 +か +大著述 +でもして +家名 +を +揚 +げなくてはならん +母 +の +生 +きているうちに +天下 +をして +明治 +の +文壇 +に +迷亭先生 +あるを +知 +らしめたいと +云 +う +気 +になった +それからなお +読 +んで +行 +くと +御前 +なんぞは +実 +に +仕合 +せ +者 +だ +露西亜 +と +戦争 +が +始 +まって +若 +い +人達 +は +大変 +な +辛苦 +をして +御国 +のために +働 +らいているのに +節季師走 +でもお +正月 +のように +気楽 +に +遊 +んでいると +書 +いてある +僕 +はこれでも +母 +の +思 +ってるように +遊 +んじゃいないやね +そのあとへ +以 +て +来 +て +僕 +の +小学校時代 +の +朋友 +で +今度 +の +戦争 +に +出 +て +死 +んだり +負傷 +したものの +名前 +が +列挙 +してあるのさ +その +名前 +を +一々読 +んだ +時 +には +何 +だか +世 +の +中 +が +味気 +なくなって +人間 +もつまらないと +云 +う +気 +が +起 +ったよ +一番仕舞 +にね +私 +しも +取 +る +年 +に +候 +えば +初春 +の +御雑煮 +を +祝 +い +候 +も +今度限 +りかと +何 +だか +心細 +い +事 +が +書 +いてあるんで +なおのこと +気 +がくさくさしてしまって +早 +く +東風 +が +来 +れば +好 +いと +思 +ったが +先生 +どうしても +来 +ない +そのうちとうとう +晩飯 +になったから +母 +へ +返事 +でも +書 +こうと +思 +ってちょいと +十二三行 +かいた +母 +の +手紙 +は +六尺以上 +もあるのだが +僕 +にはとてもそんな +芸 +は +出来 +んから +いつでも +十行内外 +で +御免蒙 +る +事 +に +極 +めてあるのさ +すると +一日動 +かずにおったものだから +胃 +の +具合 +が +妙 +で +苦 +しい +東風 +が +来 +たら +待 +たせておけと +云 +う +気 +になって +郵便 +を +入 +れながら +散歩 +に +出掛 +けたと +思 +い +給 +え +いつになく +富士見町 +の +方 +へは +足 +が +向 +かないで +土手三番町 +の +方 +へ +我 +れ +知 +らず +出 +てしまった +ちょうどその +晩 +は +少 +し +曇 +って +から +風 +が +御濠 +の +向 +うから +吹 +き +付 +ける +非常 +に +寒 +い +神楽坂 +の +方 +から +汽車 +が +ヒュ +と +鳴 +って +土手下 +を +通 +り +過 +ぎる +大変淋 +しい +感 +じがする +暮 +戦死 +老衰 +無常迅速 +などと +云 +う +奴 +が +頭 +の +中 +をぐるぐる +馳 +け +廻 +る +よく +人 +が +首 +を +縊 +ると +云 +うがこんな +時 +にふと +誘 +われて +死 +ぬ +気 +になるのじゃないかと +思 +い +出 +す +ちょいと +首 +を +上 +げて +土手 +の +上 +を +見 +ると +いつの +間 +にか +例 +の +松 +の +真下 +に +来 +ているのさ +例 +の +松 +た +何 +だい +と +主人 +が +断句 +を +投 +げ +入 +れる +首懸 +の +松 +さ +と +迷亭 +は +領 +を +縮 +める +首懸 +の +松 +は +鴻 +の +台 +でしょう +寒月 +が +波紋 +をひろげる +鴻 +の +台 +のは +鐘懸 +の +松 +で +土手三番町 +のは +首懸 +の +松 +さ +なぜこう +云 +う +名 +が +付 +いたかと +云 +うと +昔 +しからの +言 +い +伝 +えで +誰 +でもこの +松 +の +下 +へ +来 +ると +首 +が +縊 +りたくなる +土手 +の +上 +に +松 +は +何十本 +となくあるが +そら +首縊 +りだと +来 +て +見 +ると +必 +ずこの +松 +へぶら +下 +がっている +年 +に +二三返 +はきっとぶら +下 +がっている +どうしても +他 +の +松 +では +死 +ぬ +気 +にならん +見 +ると +うまい +具合 +に +枝 +が +往来 +の +方 +へ +横 +に +出 +ている +ああ +好 +い +枝振 +りだ +あのままにしておくのは +惜 +しいものだ +どうかしてあすこの +所 +へ +人間 +を +下 +げて +見 +たい +誰 +か +来 +ないかしらと +四辺 +を +見渡 +すと +生憎誰 +も +来 +ない +仕方 +がない +自分 +で +下 +がろうか +知 +らん +いやいや +自分 +が +下 +がっては +命 +がない +危 +ないからよそう +しかし +昔 +の +希臘人 +は +宴会 +の +席 +で +首縊 +りの +真似 +をして +余興 +を +添 +えたと +云 +う +話 +しがある +一人 +が +台 +の +上 +へ +登 +って +縄 +の +結 +び +目 +へ +首 +を +入 +れる +途端 +に +他 +のものが +台 +を +蹴返 +す +首 +を +入 +れた +当人 +は +台 +を +引 +かれると +同時 +に +縄 +をゆるめて +飛 +び +下 +りるという +趣向 +である +果 +してそれが +事実 +なら +別段恐 +るるにも +及 +ばん +僕 +も +一 +つ +試 +みようと +枝 +へ +手 +を +懸 +けて +見 +ると +好 +い +具合 +に +撓 +る +撓 +り +按排 +が +実 +に +美的 +である +首 +がかかってふわふわするところを +想像 +して +見 +ると +嬉 +しくてたまらん +是非 +やる +事 +にしようと +思 +ったが +もし +東風 +が +来 +て +待 +っていると +気 +の +毒 +だと +考 +え +出 +した +それではまず +東風 +に +逢 +って +約束通 +り +話 +しをして +それから +出直 +そうと +云 +う +気 +になってついにうちへ +帰 +ったのさ +それで +市 +が +栄 +えたのかい +と +主人 +が +聞 +く +面白 +いですな +と +寒月 +がにやにやしながら +云 +う +うちへ +帰 +って +見 +ると +東風 +は +来 +ていない +しかし +今日 +は +無拠処差支 +えがあって +出 +られぬ +いずれ +永日御面晤 +を +期 +すという +端書 +があったので +やっと +安心 +して +これなら +心置 +きなく +首 +が +縊 +れる +嬉 +しいと +思 +った +で +早速下駄 +を +引 +き +懸 +けて +急 +ぎ +足 +で +元 +の +所 +へ +引 +き +返 +して +見 +る +と +云 +って +主人 +と +寒月 +の +顔 +を +見 +てすましている +見 +るとどうしたんだい +と +主人 +は +少 +し +焦 +れる +いよいよ +佳境 +に +入 +りますね +と +寒月 +は +羽織 +の +紐 +をひねくる +見 +ると +もう +誰 +か +来 +て +先 +へぶら +下 +がっている +たった +一足違 +いでねえ +君 +残念 +な +事 +をしたよ +考 +えると +何 +でもその +時 +は +死神 +に +取 +り +着 +かれたんだね +ゼ +ムス +などに +云 +わせると +副意識下 +の +幽冥界 +と +僕 +が +存在 +している +現実界 +が +一種 +の +因果法 +によって +互 +に +感応 +したんだろう +実 +に +不思議 +な +事 +があるものじゃないか +迷亭 +はすまし +返 +っている +主人 +はまたやられたと +思 +いながら +何 +も +云 +わずに +空也餅 +を +頬張 +って +口 +をもごもご +云 +わしている +寒月 +は +火鉢 +の +灰 +を +丁寧 +に +掻 +き +馴 +らして +俯向 +いてにやにや +笑 +っていたが +やがて +口 +を +開 +く +極 +めて +静 +かな +調子 +である +なるほど +伺 +って +見 +ると +不思議 +な +事 +でちょっと +有 +りそうにも +思 +われませんが +私 +などは +自分 +でやはり +似 +たような +経験 +をつい +近頃 +したものですから +少 +しも +疑 +がう +気 +になりません +おや +君 +も +首 +を +縊 +りたくなったのかい +いえ +私 +のは +首 +じゃないんで +これもちょうど +明 +ければ +昨年 +の +暮 +の +事 +でしかも +先生 +と +同日同刻 +くらいに +起 +った +出来事 +ですからなおさら +不思議 +に +思 +われます +こりゃ +面白 +い +と +迷亭 +も +空也餅 +を +頬張 +る +その +日 +は +向島 +の +知人 +の +家 +で +忘年会兼合奏会 +がありまして +私 +もそれへ +ヴァイオリン +を +携 +えて +行 +きました +十五六人令嬢 +やら +令夫人 +が +集 +ってなかなか +盛会 +で +近来 +の +快事 +と +思 +うくらいに +万事 +が +整 +っていました +晩餐 +もすみ +合奏 +もすんで +四方 +の +話 +しが +出 +て +時刻 +も +大分遅 +くなったから +もう +暇乞 +いをして +帰 +ろうかと +思 +っていますと +某博士 +の +夫人 +が +私 +のそばへ +来 +てあなたは +子 +さんの +御病気 +を +御承知 +ですかと +小声 +で +聞 +きますので +実 +はその +両三日前 +に +逢 +った +時 +は +平常 +の +通 +りどこも +悪 +いようには +見受 +けませんでしたから +私 +も +驚 +ろいて +精 +しく +様子 +を +聞 +いて +見 +ますと +私 +しの +逢 +ったその +晩 +から +急 +に +発熱 +して +いろいろな +譫語 +を +絶間 +なく +口走 +るそうで +それだけなら +宜 +いですがその +譫語 +のうちに +私 +の +名 +が +時々出 +て +来 +るというのです +主人 +は +無論 +迷亭先生 +も +御安 +くないね +などという +月並 +は +云 +わず +静粛 +に +謹聴 +している +医者 +を +呼 +んで +見 +てもらうと +何 +だか +病名 +はわからんが +何 +しろ +熱 +が +劇 +しいので +脳 +を +犯 +しているから +もし +睡眠剤 +が +思 +うように +功 +を +奏 +しないと +危険 +であると +云 +う +診断 +だそうで +私 +はそれを +聞 +くや +否 +や +一種 +いやな +感 +じが +起 +ったのです +ちょうど +夢 +でうなされる +時 +のような +重 +くるしい +感 +じで +周囲 +の +空気 +が +急 +に +固形体 +になって +四方 +から +吾 +が +身 +をしめつけるごとく +思 +われました +帰 +り +道 +にもその +事 +ばかりが +頭 +の +中 +にあって +苦 +しくてたまらない +あの +奇麗 +な +あの +快活 +なあの +健康 +な +子 +さんが +ちょっと +失敬 +だが +待 +ってくれ +給 +え +さっきから +伺 +っていると +子 +さんと +云 +うのが +二返 +ばかり +聞 +えるようだが +もし +差支 +えがなければ +承 +わりたいね +君 +と +主人 +を +顧 +みると +主人 +も +うむ +と +生返事 +をする +いやそれだけは +当人 +の +迷惑 +になるかも +知 +れませんから +廃 +しましょう +すべて +曖々然 +として +昧々然 +たるかたで +行 +くつもりかね +冷笑 +なさってはいけません +極真面目 +な +話 +しなんですから +とにかくあの +婦人 +が +急 +にそんな +病気 +になった +事 +を +考 +えると +実 +に +飛花落葉 +の +感慨 +で +胸 +が +一杯 +になって +総身 +の +活気 +が +一度 +に +ストライキ +を +起 +したように +元気 +がにわかに +滅入 +ってしまいまして +ただ +蹌々 +として +踉々 +という +形 +ちで +吾妻橋 +へきかかったのです +欄干 +に +倚 +って +下 +を +見 +ると +満潮 +か +干潮 +か +分 +りませんが +黒 +い +水 +がかたまってただ +動 +いているように +見 +えます +花川戸 +の +方 +から +人力車 +が +一台馳 +けて +来 +て +橋 +の +上 +を +通 +りました +その +提灯 +の +火 +を +見送 +っていると +だんだん +小 +くなって +札幌 +ビ +ル +の +処 +で +消 +えました +私 +はまた +水 +を +見 +る +すると +遥 +かの +川上 +の +方 +で +私 +の +名 +を +呼 +ぶ +声 +が +聞 +えるのです +はてな +今時分人 +に +呼 +ばれる +訳 +はないが +誰 +だろうと +水 +の +面 +をすかして +見 +ましたが +暗 +くて +何 +にも +分 +りません +気 +のせいに +違 +いない +早々帰 +ろうと +思 +って +一足二足 +あるき +出 +すと +また +微 +かな +声 +で +遠 +くから +私 +の +名 +を +呼 +ぶのです +私 +はまた +立 +ち +留 +って +耳 +を +立 +てて +聞 +きました +三度目 +に +呼 +ばれた +時 +には +欄干 +に +捕 +まっていながら +膝頭 +ががくがく +悸 +え +出 +したのです +その +声 +は +遠 +くの +方 +か +川 +の +底 +から +出 +るようですが +紛 +れもない +子 +の +声 +なんでしょう +私 +は +覚 +えず +は +い +と +返事 +をしたのです +その +返事 +が +大 +きかったものですから +静 +かな +水 +に +響 +いて +自分 +で +自分 +の +声 +に +驚 +かされて +はっと +周囲 +を +見渡 +しました +人 +も +犬 +も +月 +も +何 +にも +見 +えません +その +時 +に +私 +はこの +夜 +の +中 +に +巻 +き +込 +まれて +あの +声 +の +出 +る +所 +へ +行 +きたいと +云 +う +気 +がむらむらと +起 +ったのです +子 +の +声 +がまた +苦 +しそうに +訴 +えるように +救 +を +求 +めるように +私 +の +耳 +を +刺 +し +通 +したので +今度 +は +今直 +に +行 +きます +と +答 +えて +欄干 +から +半身 +を +出 +して +黒 +い +水 +を +眺 +めました +どうも +私 +を +呼 +ぶ +声 +が +浪 +の +下 +から +無理 +に +洩 +れて +来 +るように +思 +われましてね +この +水 +の +下 +だなと +思 +いながら +私 +はとうとう +欄干 +の +上 +に +乗 +りましたよ +今度呼 +んだら +飛 +び +込 +もうと +決心 +して +流 +を +見 +つめているとまた +憐 +れな +声 +が +糸 +のように +浮 +いて +来 +る +ここだと +思 +って +力 +を +込 +めて +一反飛 +び +上 +がっておいて +そして +小石 +か +何 +ぞのように +未練 +なく +落 +ちてしまいました +とうとう +飛 +び +込 +んだのかい +と +主人 +が +眼 +をぱちつかせて +問 +う +そこまで +行 +こうとは +思 +わなかった +と +迷亭 +が +自分 +の +鼻 +の +頭 +をちょいとつまむ +飛 +び +込 +んだ +後 +は +気 +が +遠 +くなって +しばらくは +夢中 +でした +やがて +眼 +がさめて +見 +ると +寒 +くはあるが +どこも +濡 +れた +所 +も +何 +もない +水 +を +飲 +んだような +感 +じもしない +たしかに +飛 +び +込 +んだはずだが +実 +に +不思議 +だ +こりゃ +変 +だと +気 +が +付 +いてそこいらを +見渡 +すと +驚 +きましたね +水 +の +中 +へ +飛 +び +込 +んだつもりでいたところが +つい +間違 +って +橋 +の +真中 +へ +飛 +び +下 +りたので +その +時 +は +実 +に +残念 +でした +前 +と +後 +ろの +間違 +だけであの +声 +の +出 +る +所 +へ +行 +く +事 +が +出来 +なかったのです +寒月 +はにやにや +笑 +いながら +例 +のごとく +羽織 +の +紐 +を +荷厄介 +にしている +ハハハハ +これは +面白 +い +僕 +の +経験 +と +善 +く +似 +ているところが +奇 +だ +やはり +ゼ +ムス +教授 +の +材料 +になるね +人間 +の +感応 +と +云 +う +題 +で +写生文 +にしたらきっと +文壇 +を +驚 +かすよ +そしてその +子 +さんの +病気 +はどうなったかね +と +迷亭先生 +が +追窮 +する +二三日前年始 +に +行 +きましたら +門 +の +内 +で +下女 +と +羽根 +を +突 +いていましたから +病気 +は +全快 +したものと +見 +えます +主人 +は +最前 +から +沈思 +の +体 +であったが +この +時 +ようやく +口 +を +開 +いて +僕 +にもある +と +負 +けぬ +気 +を +出 +す +あるって +何 +があるんだい +迷亭 +の +眼中 +に +主人 +などは +無論 +ない +僕 +のも +去年 +の +暮 +の +事 +だ +みんな +去年 +の +暮 +は +暗合 +で +妙 +ですな +と +寒月 +が +笑 +う +欠 +けた +前歯 +のうちに +空也餅 +が +着 +いている +やはり +同日同刻 +じゃないか +と +迷亭 +がまぜ +返 +す +いや +日 +は +違 +うようだ +何 +でも +二十日頃 +だよ +細君 +が +御歳暮 +の +代 +りに +摂津大掾 +を +聞 +かしてくれろと +云 +うから +連 +れて +行 +ってやらん +事 +もないが +今日 +の +語 +り +物 +は +何 +だと +聞 +いたら +細君 +が +新聞 +を +参考 +して +鰻谷 +だと +云 +うのさ +鰻谷 +は +嫌 +いだから +今日 +はよそうとその +日 +はやめにした +翌日 +になると +細君 +がまた +新聞 +を +持 +って +来 +て +今日 +は +堀川 +だからいいでしょうと +云 +う +堀川 +は +三味線 +もので +賑 +やかなばかりで +実 +がないからよそうと +云 +うと +細君 +は +不平 +な +顔 +をして +引 +き +下 +がった +その +翌日 +になると +細君 +が +云 +うには +今日 +は +三十三間堂 +です +私 +は +是非摂津 +の +三十三間堂 +が +聞 +きたい +あなたは +三十三間堂 +も +御嫌 +いか +知 +らないが +私 +に +聞 +かせるのだからいっしょに +行 +って +下 +すっても +宜 +いでしょうと +手詰 +の +談判 +をする +御前 +がそんなに +行 +きたいなら +行 +っても +宜 +ろしい +しかし +一世一代 +と +云 +うので +大変 +な +大入 +だから +到底突懸 +けに +行 +ったって +這入 +れる +気遣 +いはない +元来 +ああ +云 +う +場所 +へ +行 +くには +茶屋 +と +云 +うものが +在 +ってそれと +交渉 +して +相当 +の +席 +を +予約 +するのが +正当 +の +手続 +きだから +それを +踏 +まないで +常規 +を +脱 +した +事 +をするのはよくない +残念 +だが +今日 +はやめようと +云 +うと +細君 +は +凄 +い +眼付 +をして +私 +は +女 +ですからそんなむずかしい +手続 +きなんか +知 +りませんが +大原 +のお +母 +あさんも +鈴木 +の +君代 +さんも +正当 +の +手続 +きを +踏 +まないで +立派 +に +聞 +いて +来 +たんですから +いくらあなたが +教師 +だからって +そう +手数 +のかかる +見物 +をしないでもすみましょう +あなたはあんまりだと +泣 +くような +声 +を +出 +す +それじゃ +駄目 +でもまあ +行 +く +事 +にしよう +晩飯 +をくって +電車 +で +行 +こうと +降参 +をすると +行 +くなら +四時 +までに +向 +うへ +着 +くようにしなくっちゃいけません +そんなぐずぐずしてはいられませんと +急 +に +勢 +がいい +なぜ +四時 +までに +行 +かなくては +駄目 +なんだと +聞 +き +返 +すと +そのくらい +早 +く +行 +って +場所 +をとらなくちゃ +這入 +れないからですと +鈴木 +の +君代 +さんから +教 +えられた +通 +りを +述 +べる +それじゃ +四時 +を +過 +ぎればもう +駄目 +なんだねと +念 +を +押 +して +見 +たら +ええ +駄目 +ですともと +答 +える +すると +君不思議 +な +事 +にはその +時 +から +急 +に +悪寒 +がし +出 +してね +奥 +さんがですか +と +寒月 +が +聞 +く +なに +細君 +はぴんぴんしていらあね +僕 +がさ +何 +だか +穴 +の +明 +いた +風船玉 +のように +一度 +に +萎縮 +する +感 +じが +起 +ると +思 +うと +もう +眼 +がぐらぐらして +動 +けなくなった +急病 +だね +と +迷亭 +が +註釈 +を +加 +える +ああ +困 +った +事 +になった +細君 +が +年 +に +一度 +の +願 +だから +是非叶 +えてやりたい +平生叱 +りつけたり +口 +を +聞 +かなかったり +身上 +の +苦労 +をさせたり +小供 +の +世話 +をさせたりするばかりで +何一 +つ +洒掃薪水 +の +労 +に +酬 +いた +事 +はない +今日 +は +幸 +い +時間 +もある +嚢中 +には +四五枚 +の +堵物 +もある +連 +れて +行 +けば +行 +かれる +細君 +も +行 +きたいだろう +僕 +も +連 +れて +行 +ってやりたい +是非連 +れて +行 +ってやりたいがこう +悪寒 +がして +眼 +がくらんでは +電車 +へ +乗 +るどころか +靴脱 +へ +降 +りる +事 +も +出来 +ない +ああ +気 +の +毒 +だ +気 +の +毒 +だと +思 +うとなお +悪寒 +がしてなお +眼 +がくらんでくる +早 +く +医者 +に +見 +てもらって +服薬 +でもしたら +四時前 +には +全快 +するだろうと +それから +細君 +と +相談 +をして +甘木医学士 +を +迎 +いにやると +生憎昨夜 +が +当番 +でまだ +大学 +から +帰 +らない +二時頃 +には +御帰 +りになりますから +帰 +り +次第 +すぐ +上 +げますと +云 +う +返事 +である +困 +ったなあ +今杏仁水 +でも +飲 +めば +四時前 +にはきっと +癒 +るに +極 +っているんだが +運 +の +悪 +い +時 +には +何事 +も +思 +うように +行 +かんもので +たまさか +妻君 +の +喜 +ぶ +笑顔 +を +見 +て +楽 +もうと +云 +う +予算 +も +がらりと +外 +れそうになって +来 +る +細君 +は +恨 +めしい +顔付 +をして +到底 +いらっしゃれませんかと +聞 +く +行 +くよ +必 +ず +行 +くよ +四時 +までにはきっと +直 +って +見 +せるから +安心 +しているがいい +早 +く +顔 +でも +洗 +って +着物 +でも +着換 +えて +待 +っているがいい +と +口 +では +云 +ったようなものの +胸中 +は +無限 +の +感慨 +である +悪寒 +はますます +劇 +しくなる +眼 +はいよいよぐらぐらする +もしや +四時 +までに +全快 +して +約束 +を +履行 +する +事 +が +出来 +なかったら +気 +の +狭 +い +女 +の +事 +だから +何 +をするかも +知 +れない +情 +けない +仕儀 +になって +来 +た +どうしたら +善 +かろう +万一 +の +事 +を +考 +えると +今 +の +内 +に +有為転変 +の +理 +生者必滅 +の +道 +を +説 +き +聞 +かして +もしもの +変 +が +起 +った +時取 +り +乱 +さないくらいの +覚悟 +をさせるのも +夫 +の +妻 +に +対 +する +義務 +ではあるまいかと +考 +え +出 +した +僕 +は +速 +かに +細君 +を +書斎 +へ +呼 +んだよ +呼 +んで +御前 +は +女 +だけれども +と +云 +う +西洋 +の +諺 +くらいは +心得 +ているだろうと +聞 +くと +そんな +横文字 +なんか +誰 +が +知 +るもんですか +あなたは +人 +が +英語 +を +知 +らないのを +御存 +じの +癖 +にわざと +英語 +を +使 +って +人 +にからかうのだから +宜 +しゅうございます +どうせ +英語 +なんかは +出来 +ないんですから +そんなに +英語 +が +御好 +きなら +なぜ +耶蘇学校 +の +卒業生 +かなんかをお +貰 +いなさらなかったんです +あなたくらい +冷酷 +な +人 +はありはしないと +非常 +な +権幕 +なんで +僕 +もせっかくの +計画 +の +腰 +を +折 +られてしまった +君等 +にも +弁解 +するが +僕 +の +英語 +は +決 +して +悪意 +で +使 +った +訳 +じゃない +全 +く +妻 +を +愛 +する +至情 +から +出 +たので +それを +妻 +のように +解釈 +されては +僕 +も +立 +つ +瀬 +がない +それにさっきからの +悪寒 +と +眩暈 +で +少 +し +脳 +が +乱 +れていたところへもって +来 +て +早 +く +有為転変 +生者必滅 +の +理 +を +呑 +み +込 +ませようと +少 +し +急 +き +込 +んだものだから +つい +細君 +の +英語 +を +知 +らないと +云 +う +事 +を +忘 +れて +何 +の +気 +も +付 +かずに +使 +ってしまった +訳 +さ +考 +えるとこれは +僕 +が +悪 +るい +全 +く +手落 +ちであった +この +失敗 +で +悪寒 +はますます +強 +くなる +眼 +はいよいよぐらぐらする +妻君 +は +命 +ぜられた +通 +り +風呂場 +へ +行 +って +両肌 +を +脱 +いで +御化粧 +をして +箪笥 +から +着物 +を +出 +して +着換 +える +もういつでも +出掛 +けられますと +云 +う +風情 +で +待 +ち +構 +えている +僕 +は +気 +が +気 +でない +早 +く +甘木君 +が +来 +てくれれば +善 +いがと +思 +って +時計 +を +見 +るともう +三時 +だ +四時 +にはもう +一時間 +しかない +そろそろ +出掛 +けましょうか +と +妻君 +が +書斎 +の +開 +き +戸 +を +明 +けて +顔 +を +出 +す +自分 +の +妻 +を +褒 +めるのはおかしいようであるが +僕 +はこの +時 +ほど +細君 +を +美 +しいと +思 +った +事 +はなかった +もろ +肌 +を +脱 +いで +石鹸 +で +磨 +き +上 +げた +皮膚 +がぴかついて +黒縮緬 +の +羽織 +と +反映 +している +その +顔 +が +石鹸 +と +摂津大掾 +を +聞 +こうと +云 +う +希望 +との +二 +つで +有形無形 +の +両方面 +から +輝 +やいて +見 +える +どうしてもその +希望 +を +満足 +させて +出掛 +けてやろうと +云 +う +気 +になる +それじゃ +奮発 +して +行 +こうかな +と +一 +ぷくふかしているとようやく +甘木先生 +が +来 +た +うまい +注文通 +りに +行 +った +が +容体 +をはなすと +甘木先生 +は +僕 +の +舌 +を +眺 +めて +手 +を +握 +って +胸 +を +敲 +いて +背 +を +撫 +でて +目縁 +を +引 +っ +繰 +り +返 +して +頭蓋骨 +をさすって +しばらく +考 +え +込 +んでいる +どうも +少 +し +険呑 +のような +気 +がしまして +と +僕 +が +云 +うと +先生 +は +落 +ちついて +いえ +格別 +の +事 +もございますまい +と +云 +う +あのちょっとくらい +外出致 +しても +差支 +えはございますまいね +と +細君 +が +聞 +く +さよう +と +先生 +はまた +考 +え +込 +む +御気分 +さえ +御悪 +くなければ +気分 +は +悪 +いですよ +と +僕 +がいう +じゃともかくも +頓服 +と +水薬 +を +上 +げますから +へえどうか +何 +だかちと +危 +ないようになりそうですな +いや +決 +して +御心配 +になるほどの +事 +じゃございません +神経 +を +御起 +しになるといけませんよ +と +先生 +が +帰 +る +三時 +は +三十分過 +ぎた +下女 +を +薬取 +りにやる +細君 +の +厳命 +で +馳 +け +出 +して +行 +って +馳 +け +出 +して +返 +ってくる +四時十五分前 +である +四時 +にはまだ +十五分 +ある +すると +四時十五分前頃 +から +今 +まで +何 +とも +無 +かったのに +急 +に +嘔気 +を +催 +おして +来 +た +細君 +は +水薬 +を +茶碗 +へ +注 +いで +僕 +の +前 +へ +置 +いてくれたから +茶碗 +を +取 +り +上 +げて +飲 +もうとすると +胃 +の +中 +からげ +と +云 +う +者 +が +吶喊 +して +出 +てくる +やむをえず +茶碗 +を +下 +へ +置 +く +細君 +は +早 +く +御飲 +みになったら +宜 +いでしょう +と +逼 +る +早 +く +飲 +んで +早 +く +出掛 +けなくては +義理 +が +悪 +い +思 +い +切 +って +飲 +んでしまおうとまた +茶碗 +を +唇 +へつけるとまた +ゲ +が +執念深 +く +妨害 +をする +飲 +もうとしては +茶碗 +を +置 +き +飲 +もうとしては +茶碗 +を +置 +いていると +茶 +の +間 +の +柱時計 +が +チンチンチンチン +と +四時 +を +打 +った +さあ +四時 +だ +愚図愚図 +してはおられんと +茶碗 +をまた +取 +り +上 +げると +不思議 +だねえ +君 +実 +に +不思議 +とはこの +事 +だろう +四時 +の +音 +と +共 +に +吐 +き +気 +がすっかり +留 +まって +水薬 +が +何 +の +苦 +なしに +飲 +めたよ +それから +四時十分頃 +になると +甘木先生 +の +名医 +という +事 +も +始 +めて +理解 +する +事 +が +出来 +たんだが +背中 +がぞくぞくするのも +眼 +がぐらぐらするのも +夢 +のように +消 +えて +当分立 +つ +事 +も +出来 +まいと +思 +った +病気 +がたちまち +全快 +したのは +嬉 +しかった +それから +歌舞伎座 +へいっしょに +行 +ったのかい +と +迷亭 +が +要領 +を +得 +んと +云 +う +顔付 +をして +聞 +く +行 +きたかったが +四時 +を +過 +ぎちゃ +這入 +れないと +云 +う +細君 +の +意見 +なんだから +仕方 +がない +やめにしたさ +もう +十五分 +ばかり +早 +く +甘木先生 +が +来 +てくれたら +僕 +の +義理 +も +立 +つし +妻 +も +満足 +したろうに +わずか +十五分 +の +差 +でね +実 +に +残念 +な +事 +をした +考 +え +出 +すとあぶないところだったと +今 +でも +思 +うのさ +語 +り +了 +った +主人 +はようやく +自分 +の +義務 +をすましたような +風 +をする +これで +両人 +に +対 +して +顔 +が +立 +つと +云 +う +気 +かも +知 +れん +寒月 +は +例 +のごとく +欠 +けた +歯 +を +出 +して +笑 +いながら +それは +残念 +でしたな +と +云 +う +迷亭 +はとぼけた +顔 +をして +君 +のような +親切 +な +夫 +を +持 +った +妻君 +は +実 +に +仕合 +せだな +と +独 +り +言 +のようにいう +障子 +の +蔭 +で +エヘン +と +云 +う +細君 +の +咳払 +いが +聞 +える +吾輩 +はおとなしく +三人 +の +話 +しを +順番 +に +聞 +いていたがおかしくも +悲 +しくもなかった +人間 +というものは +時間 +を +潰 +すために +強 +いて +口 +を +運動 +させて +おかしくもない +事 +を +笑 +ったり +面白 +くもない +事 +を +嬉 +しがったりするほかに +能 +もない +者 +だと +思 +った +吾輩 +の +主人 +の +我儘 +で +偏狭 +な +事 +は +前 +から +承知 +していたが +平常 +は +言葉数 +を +使 +わないので +何 +だか +了解 +しかねる +点 +があるように +思 +われていた +その +了解 +しかねる +点 +に +少 +しは +恐 +しいと +云 +う +感 +じもあったが +今 +の +話 +を +聞 +いてから +急 +に +軽蔑 +したくなった +かれはなぜ +両人 +の +話 +しを +沈黙 +して +聞 +いていられないのだろう +負 +けぬ +気 +になって +愚 +にもつかぬ +駄弁 +を +弄 +すれば +何 +の +所得 +があるだろう +エピクテタス +にそんな +事 +をしろと +書 +いてあるのか +知 +らん +要 +するに +主人 +も +寒月 +も +迷亭 +も +太平 +の +逸民 +で +彼等 +は +糸瓜 +のごとく +風 +に +吹 +かれて +超然 +と +澄 +し +切 +っているようなものの +その +実 +はやはり +娑婆気 +もあり +慾気 +もある +競争 +の +念 +勝 +とう +勝 +とうの +心 +は +彼等 +が +日常 +の +談笑中 +にもちらちらとほのめいて +一歩進 +めば +彼等 +が +平常罵倒 +している +俗骨共 +と +一 +つ +穴 +の +動物 +になるのは +猫 +より +見 +て +気 +の +毒 +の +至 +りである +ただその +言語動作 +が +普通 +の +半可通 +のごとく +文切 +り +形 +の +厭味 +を +帯 +びてないのはいささかの +取 +り +得 +でもあろう +こう +考 +えると +急 +に +三人 +の +談話 +が +面白 +くなくなったので +三毛子 +の +様子 +でも +見 +て +来 +ようかと +二絃琴 +の +御師匠 +さんの +庭口 +へ +廻 +る +門松注目飾 +りはすでに +取 +り +払 +われて +正月 +も +早 +や +十日 +となったが +うららかな +春日 +は +一流 +れの +雲 +も +見 +えぬ +深 +き +空 +より +四海天下 +を +一度 +に +照 +らして +十坪 +に +足 +らぬ +庭 +の +面 +も +元日 +の +曙光 +を +受 +けた +時 +より +鮮 +かな +活気 +を +呈 +している +椽側 +に +座蒲団 +が +一 +つあって +人影 +も +見 +えず +障子 +も +立 +て +切 +ってあるのは +御師匠 +さんは +湯 +にでも +行 +ったのか +知 +らん +御師匠 +さんは +留守 +でも +構 +わんが +三毛子 +は +少 +しは +宜 +い +方 +か +それが +気掛 +りである +ひっそりして +人 +の +気合 +もしないから +泥足 +のまま +椽側 +へ +上 +って +座蒲団 +の +真中 +へ +寝転 +ろんで +見 +るといい +心持 +ちだ +ついうとうととして +三毛子 +の +事 +も +忘 +れてうたた +寝 +をしていると +急 +に +障子 +のうちで +人声 +がする +御苦労 +だった +出来 +たかえ +御師匠 +さんはやはり +留守 +ではなかったのだ +はい +遅 +くなりまして +仏師屋 +へ +参 +りましたらちょうど +出来上 +ったところだと +申 +しまして +どれお +見 +せなさい +ああ +奇麗 +に +出来 +た +これで +三毛 +も +浮 +かばれましょう +金 +は +剥 +げる +事 +はあるまいね +ええ +念 +を +押 +しましたら +上等 +を +使 +ったからこれなら +人間 +の +位牌 +よりも +持 +つと +申 +しておりました +それから +猫誉信女 +の +誉 +の +字 +は +崩 +した +方 +が +恰好 +がいいから +少 +し +劃 +を +易 +えたと +申 +しました +どれどれ +早速御仏壇 +へ +上 +げて +御線香 +でもあげましょう +三毛子 +は +どうかしたのかな +何 +だか +様子 +が +変 +だと +蒲団 +の +上 +へ +立 +ち +上 +る +チ +ン +南無猫誉信女 +南無阿弥陀仏南無阿弥陀仏 +と +御師匠 +さんの +声 +がする +御前 +も +回向 +をしておやりなさい +チ +ン +南無猫誉信女南無阿弥陀仏南無阿弥陀仏 +と +今度 +は +下女 +の +声 +がする +吾輩 +は +急 +に +動悸 +がして +来 +た +座蒲団 +の +上 +に +立 +ったまま +木彫 +の +猫 +のように +眼 +も +動 +かさない +ほんとに +残念 +な +事 +を +致 +しましたね +始 +めはちょいと +風邪 +を +引 +いたんでございましょうがねえ +甘木 +さんが +薬 +でも +下 +さると +よかったかも +知 +れないよ +一体 +あの +甘木 +さんが +悪 +うございますよ +あんまり +三毛 +を +馬鹿 +にし +過 +ぎまさあね +そう +人様 +の +事 +を +悪 +く +云 +うものではない +これも +寿命 +だから +三毛子 +も +甘木先生 +に +診察 +して +貰 +ったものと +見 +える +つまるところ +表通 +りの +教師 +のうちの +野良猫 +が +無暗 +に +誘 +い +出 +したからだと +わたしは +思 +うよ +ええあの +畜生 +が +三毛 +のかたきでございますよ +少 +し +弁解 +したかったが +ここが +我慢 +のしどころと +唾 +を +呑 +んで +聞 +いている +話 +しはしばし +途切 +れる +世 +の +中 +は +自由 +にならん +者 +でのう +三毛 +のような +器量 +よしは +早死 +をするし +不器量 +な +野良猫 +は +達者 +でいたずらをしているし +その +通 +りでございますよ +三毛 +のような +可愛 +らしい +猫 +は +鐘 +と +太鼓 +で +探 +してあるいたって +二人 +とはおりませんからね +二匹 +と +云 +う +代 +りに +二 +たりといった +下女 +の +考 +えでは +猫 +と +人間 +とは +同種族 +ものと +思 +っているらしい +そう +云 +えばこの +下女 +の +顔 +は +吾等猫属 +とはなはだ +類似 +している +出来 +るものなら +三毛 +の +代 +りに +あの +教師 +の +所 +の +野良 +が +死 +ぬと +御誂 +え +通 +りに +参 +ったんでございますがねえ +御誂 +え +通 +りになっては +ちと +困 +る +死 +ぬと +云 +う +事 +はどんなものか +まだ +経験 +した +事 +がないから +好 +きとも +嫌 +いとも +云 +えないが +先日 +あまり +寒 +いので +火消壺 +の +中 +へもぐり +込 +んでいたら +下女 +が +吾輩 +がいるのも +知 +らんで +上 +から +蓋 +をした +事 +があった +その +時 +の +苦 +しさは +考 +えても +恐 +しくなるほどであった +白君 +の +説明 +によるとあの +苦 +しみが +今少 +し +続 +くと +死 +ぬのであるそうだ +三毛子 +の +身代 +りになるのなら +苦情 +もないが +あの +苦 +しみを +受 +けなくては +死 +ぬ +事 +が +出来 +ないのなら +誰 +のためでも +死 +にたくはない +しかし +猫 +でも +坊 +さんの +御経 +を +読 +んでもらったり +戒名 +をこしらえてもらったのだから +心残 +りはあるまい +そうでございますとも +全 +く +果報者 +でございますよ +ただ +慾 +を +云 +うとあの +坊 +さんの +御経 +があまり +軽少 +だったようでございますね +少 +し +短 +か +過 +ぎたようだったから +大変御早 +うございますねと +御尋 +ねをしたら +月桂寺 +さんは +ええ +利目 +のあるところをちょいとやっておきました +なに +猫 +だからあのくらいで +充分浄土 +へ +行 +かれますとおっしゃったよ +あらまあ +しかしあの +野良 +なんかは +吾輩 +は +名前 +はないとしばしば +断 +っておくのに +この +下女 +は +野良野良 +と +吾輩 +を +呼 +ぶ +失敬 +な +奴 +だ +罪 +が +深 +いんですから +いくらありがたい +御経 +だって +浮 +かばれる +事 +はございませんよ +吾輩 +はその +後野良 +が +何百遍繰 +り +返 +されたかを +知 +らぬ +吾輩 +はこの +際限 +なき +談話 +を +中途 +で +聞 +き +棄 +てて +布団 +をすべり +落 +ちて +椽側 +から +飛 +び +下 +りた +時 +八万八千八百八十本 +の +毛髪 +を +一度 +にたてて +身震 +いをした +その +後二絃琴 +の +御師匠 +さんの +近所 +へは +寄 +りついた +事 +がない +今頃 +は +御師匠 +さん +自身 +が +月桂寺 +さんから +軽少 +な +御回向 +を +受 +けているだろう +近頃 +は +外出 +する +勇気 +もない +何 +だか +世間 +が +慵 +うく +感 +ぜらるる +主人 +に +劣 +らぬほどの +無性猫 +となった +主人 +が +書斎 +にのみ +閉 +じ +籠 +っているのを +人 +が +失恋 +だ +失恋 +だと +評 +するのも +無理 +はないと +思 +うようになった +鼠 +はまだ +取 +った +事 +がないので +一時 +は +御三 +から +放逐論 +さえ +呈出 +された +事 +もあったが +主人 +は +吾輩 +の +普通一般 +の +猫 +でないと +云 +う +事 +を +知 +っているものだから +吾輩 +はやはりのらくらしてこの +家 +に +起臥 +している +この +点 +については +深 +く +主人 +の +恩 +を +感謝 +すると +同時 +にその +活眼 +に +対 +して +敬服 +の +意 +を +表 +するに +躊躇 +しないつもりである +御三 +が +吾輩 +を +知 +らずして +虐待 +をするのは +別 +に +腹 +も +立 +たない +今 +に +左甚五郎 +が +出 +て +来 +て +吾輩 +の +肖像 +を +楼門 +の +柱 +に +刻 +み +日本 +の +スタンラン +が +好 +んで +吾輩 +の +似顔 +を +カンヴァス +の +上 +に +描 +くようになったら +彼等鈍瞎漢 +は +始 +めて +自己 +の +不明 +を +恥 +ずるであろう +三 +三毛子 +は +死 +ぬ +黒 +は +相手 +にならず +いささか +寂寞 +の +感 +はあるが +幸 +い +人間 +に +知己 +が +出来 +たのでさほど +退屈 +とも +思 +わぬ +せんだっては +主人 +の +許 +へ +吾輩 +の +写真 +を +送 +ってくれと +手紙 +で +依頼 +した +男 +がある +この +間 +は +岡山 +の +名産吉備団子 +をわざわざ +吾輩 +の +名宛 +で +届 +けてくれた +人 +がある +だんだん +人間 +から +同情 +を +寄 +せらるるに +従 +って +己 +が +猫 +である +事 +はようやく +忘却 +してくる +猫 +よりはいつの +間 +にか +人間 +の +方 +へ +接近 +して +来 +たような +心持 +になって +同族 +を +糾合 +して +二本足 +の +先生 +と +雌雄 +を +決 +しようなどと +云 +う +量見 +は +昨今 +のところ +毛頭 +ない +それのみか +折々 +は +吾輩 +もまた +人間世界 +の +一人 +だと +思 +う +折 +さえあるくらいに +進化 +したのはたのもしい +あえて +同族 +を +軽蔑 +する +次第 +ではない +ただ +性情 +の +近 +きところに +向 +って +一身 +の +安 +きを +置 +くは +勢 +のしからしむるところで +これを +変心 +とか +軽薄 +とか +裏切 +りとか +評 +せられてはちと +迷惑 +する +かような +言語 +を +弄 +して +人 +を +罵詈 +するものに +限 +って +融通 +の +利 +かぬ +貧乏性 +の +男 +が +多 +いようだ +こう +猫 +の +習癖 +を +脱化 +して +見 +ると +三毛子 +や +黒 +の +事 +ばかり +荷厄介 +にしている +訳 +には +行 +かん +やはり +人間同等 +の +気位 +で +彼等 +の +思想 +言行 +を +評隲 +したくなる +これも +無理 +はあるまい +ただそのくらいな +見識 +を +有 +している +吾輩 +をやはり +一般猫児 +の +毛 +の +生 +えたものくらいに +思 +って +主人 +が +吾輩 +に +一言 +の +挨拶 +もなく +吉備団子 +をわが +物顔 +に +喰 +い +尽 +したのは +残念 +の +次第 +である +写真 +もまだ +撮 +って +送 +らぬ +容子 +だ +これも +不平 +と +云 +えば +不平 +だが +主人 +は +主人 +吾輩 +は +吾輩 +で +相互 +の +見解 +が +自然異 +なるのは +致 +し +方 +もあるまい +吾輩 +はどこまでも +人間 +になりすましているのだから +交際 +をせぬ +猫 +の +動作 +は +どうしてもちょいと +筆 +に +上 +りにくい +迷亭 +寒月諸先生 +の +評判 +だけで +御免蒙 +る +事 +に +致 +そう +今日 +は +上天気 +の +日曜 +なので +主人 +はのそのそ +書斎 +から +出 +て +来 +て +吾輩 +の +傍 +へ +筆硯 +と +原稿用紙 +を +並 +べて +腹這 +になって +しきりに +何 +か +唸 +っている +大方草稿 +を +書 +き +卸 +す +序開 +きとして +妙 +な +声 +を +発 +するのだろうと +注目 +していると +ややしばらくして +筆太 +に +香一 +とかいた +はてな +詩 +になるか +俳句 +になるか +香一 +とは +主人 +にしては +少 +し +洒落過 +ぎているがと +思 +う +間 +もなく +彼 +は +香一 +を +書 +き +放 +しにして +新 +たに +行 +を +改 +めて +さっきから +天然居士 +の +事 +をかこうと +考 +えている +と +筆 +を +走 +らせた +筆 +はそれだけではたと +留 +ったぎり +動 +かない +主人 +は +筆 +を +持 +って +首 +を +捻 +ったが +別段名案 +もないものと +見 +えて +筆 +の +穂 +を +甞 +めだした +唇 +が +真黒 +になったと +見 +ていると +今度 +はその +下 +へちょいと +丸 +をかいた +丸 +の +中 +へ +点 +を +二 +つうって +眼 +をつける +真中 +へ +小鼻 +の +開 +いた +鼻 +をかいて +真一文字 +に +口 +を +横 +へ +引張 +った +これでは +文章 +でも +俳句 +でもない +主人 +も +自分 +で +愛想 +が +尽 +きたと +見 +えて +そこそこに +顔 +を +塗 +り +消 +してしまった +主人 +はまた +行 +を +改 +める +彼 +の +考 +によると +行 +さえ +改 +めれば +詩 +か +賛 +か +語 +か +録 +か +何 +かになるだろうとただ +宛 +もなく +考 +えているらしい +やがて +天然居士 +は +空間 +を +研究 +し +論語 +を +読 +み +焼芋 +を +食 +い +鼻汁 +を +垂 +らす +人 +である +と +言文一致体 +で +一気呵成 +に +書 +き +流 +した +何 +となくごたごたした +文章 +である +それから +主人 +はこれを +遠慮 +なく +朗読 +して +いつになく +ハハハハ +面白 +い +と +笑 +ったが +鼻汁 +を +垂 +らすのは +ちと +酷 +だから +消 +そう +とその +句 +だけへ +棒 +を +引 +く +一本 +ですむところを +二本引 +き +三本引 +き +奇麗 +な +併行線 +を +描 +く +線 +がほかの +行 +まで +食 +み +出 +しても +構 +わず +引 +いている +線 +が +八本並 +んでもあとの +句 +が +出来 +ないと +見 +えて +今度 +は +筆 +を +捨 +てて +髭 +を +捻 +って +見 +る +文章 +を +髭 +から +捻 +り +出 +して +御覧 +に +入 +れますと +云 +う +見幕 +で +猛烈 +に +捻 +ってはねじ +上 +げ +ねじ +下 +ろしているところへ +茶 +の +間 +から +妻君 +が +出 +て +来 +てぴたりと +主人 +の +鼻 +の +先 +へ +坐 +わる +あなたちょっと +と +呼 +ぶ +なんだ +と +主人 +は +水中 +で +銅鑼 +を +叩 +くような +声 +を +出 +す +返事 +が +気 +に +入 +らないと +見 +えて +妻君 +はまた +あなたちょっと +と +出直 +す +なんだよ +と +今度 +は +鼻 +の +穴 +へ +親指 +と +人 +さし +指 +を +入 +れて +鼻毛 +をぐっと +抜 +く +今月 +はちっと +足 +りませんが +足 +りんはずはない +医者 +へも +薬礼 +はすましたし +本屋 +へも +先月払 +ったじゃないか +今月 +は +余 +らなければならん +とすまして +抜 +き +取 +った +鼻毛 +を +天下 +の +奇観 +のごとく +眺 +めている +それでもあなたが +御飯 +を +召 +し +上 +らんで +麺麭 +を +御食 +べになったり +ジャム +を +御舐 +めになるものですから +元来 +ジャム +は +幾缶舐 +めたのかい +今月 +は +八 +つ +入 +りましたよ +八 +つ +そんなに +舐 +めた +覚 +えはない +あなたばかりじゃありません +子供 +も +舐 +めます +いくら +舐 +めたって +五六円 +くらいなものだ +と +主人 +は +平気 +な +顔 +で +鼻毛 +を +一本一本丁寧 +に +原稿紙 +の +上 +へ +植付 +ける +肉 +が +付 +いているのでぴんと +針 +を +立 +てたごとくに +立 +つ +主人 +は +思 +わぬ +発見 +をして +感 +じ +入 +った +体 +で +ふっと +吹 +いて +見 +る +粘着力 +が +強 +いので +決 +して +飛 +ばない +いやに +頑固 +だな +と +主人 +は +一生懸命 +に +吹 +く +ジャム +ばかりじゃないんです +ほかに +買 +わなけりゃ +ならない +物 +もあります +と +妻君 +は +大 +に +不平 +な +気色 +を +両頬 +に +漲 +らす +あるかも +知 +れないさ +と +主人 +はまた +指 +を +突 +っ +込 +んでぐいと +鼻毛 +を +抜 +く +赤 +いのや +黒 +いのや +種々 +の +色 +が +交 +る +中 +に +一本真白 +なのがある +大 +に +驚 +いた +様子 +で +穴 +の +開 +くほど +眺 +めていた +主人 +は +指 +の +股 +へ +挟 +んだまま +その +鼻毛 +を +妻君 +の +顔 +の +前 +へ +出 +す +あら +いやだ +と +妻君 +は +顔 +をしかめて +主人 +の +手 +を +突 +き +戻 +す +ちょっと +見 +ろ +鼻毛 +の +白髪 +だ +と +主人 +は +大 +に +感動 +した +様子 +である +さすがの +妻君 +も +笑 +いながら +茶 +の +間 +へ +這入 +る +経済問題 +は +断念 +したらしい +主人 +はまた +天然居士 +に +取 +り +懸 +る +鼻毛 +で +妻君 +を +追払 +った +主人 +は +まずこれで +安心 +と +云 +わぬばかりに +鼻毛 +を +抜 +いては +原稿 +をかこうと +焦 +る +体 +であるがなかなか +筆 +は +動 +かない +焼芋 +を +食 +うも +蛇足 +だ +割愛 +しよう +とついにこの +句 +も +抹殺 +する +香一 +もあまり +唐突 +だから +已 +めろ +と +惜気 +もなく +筆誅 +する +余 +す +所 +は +天然居士 +は +空間 +を +研究 +し +論語 +を +読 +む +人 +である +と +云 +う +一句 +になってしまった +主人 +はこれでは +何 +だか +簡単過 +ぎるようだなと +考 +えていたが +ええ +面倒臭 +い +文章 +は +御廃 +しにして +銘 +だけにしろと +筆 +を +十文字 +に +揮 +って +原稿紙 +の +上 +へ +下手 +な +文人画 +の +蘭 +を +勢 +よくかく +せっかくの +苦心 +も +一字残 +らず +落第 +となった +それから +裏 +を +返 +して +空間 +に +生 +れ +空間 +を +究 +め +空間 +に +死 +す +空 +たり +間 +たり +天然居士噫 +と +意味不明 +な +語 +を +連 +ねているところへ +例 +のごとく +迷亭 +が +這入 +って +来 +る +迷亭 +は +人 +の +家 +も +自分 +の +家 +も +同 +じものと +心得 +ているのか +案内 +も +乞 +わず +ずかずか +上 +ってくる +のみならず +時 +には +勝手口 +から +飄然 +と +舞 +い +込 +む +事 +もある +心配 +遠慮 +気兼 +苦労 +を +生 +れる +時 +どこかへ +振 +り +落 +した +男 +である +また +巨人引力 +かね +と +立 +ったまま +主人 +に +聞 +く +そう +いつでも +巨人引力 +ばかり +書 +いてはおらんさ +天然居士 +の +墓銘 +を +撰 +しているところなんだ +と +大袈裟 +な +事 +を +云 +う +天然居士 +と +云 +うなあやはり +偶然童子 +のような +戒名 +かね +と +迷亭 +は +不相変出鱈目 +を +云 +う +偶然童子 +と +云 +うのもあるのかい +なに +有 +りゃしないがまずその +見当 +だろうと +思 +っていらあね +偶然童子 +と +云 +うのは +僕 +の +知 +ったものじゃないようだが +天然居士 +と +云 +うのは +君 +の +知 +ってる +男 +だぜ +一体 +だれが +天然居士 +なんて +名 +を +付 +けてすましているんだい +例 +の +曾呂崎 +の +事 +だ +卒業 +して +大学院 +へ +這入 +って +空間論 +と +云 +う +題目 +で +研究 +していたが +あまり +勉強 +し +過 +ぎて +腹膜炎 +で +死 +んでしまった +曾呂崎 +はあれでも +僕 +の +親友 +なんだからな +親友 +でもいいさ +決 +して +悪 +いと +云 +やしない +しかしその +曾呂崎 +を +天然居士 +に +変化 +させたのは +一体誰 +の +所作 +だい +僕 +さ +僕 +がつけてやったんだ +元来坊主 +のつける +戒名 +ほど +俗 +なものは +無 +いからな +と +天然居士 +はよほど +雅 +な +名 +のように +自慢 +する +迷亭 +は +笑 +いながら +まあその +墓碑銘 +と +云 +う +奴 +を +見 +せ +給 +え +と +原稿 +を +取 +り +上 +げて +何 +だ +空間 +に +生 +れ +空間 +を +究 +め +空間 +に +死 +す +空 +たり +間 +たり +天然居士噫 +と +大 +きな +声 +で +読 +み +上 +る +なるほどこりゃあ +善 +い +天然居士相当 +のところだ +主人 +は +嬉 +しそうに +善 +いだろう +と +云 +う +この +墓銘 +を +沢庵石 +へ +彫 +り +付 +けて +本堂 +の +裏手 +へ +力石 +のように +抛 +り +出 +して +置 +くんだね +雅 +でいいや +天然居士 +も +浮 +かばれる +訳 +だ +僕 +もそうしようと +思 +っているのさ +と +主人 +は +至極真面目 +に +答 +えたが +僕 +あちょっと +失敬 +するよ +じき +帰 +るから +猫 +にでもからかっていてくれ +給 +え +と +迷亭 +の +返事 +も +待 +たず +風然 +と +出 +て +行 +く +計 +らずも +迷亭先生 +の +接待掛 +りを +命 +ぜられて +無愛想 +な +顔 +もしていられないから +ニャ +ニャ +と +愛嬌 +を +振 +り +蒔 +いて +膝 +の +上 +へ +這 +い +上 +って +見 +た +すると +迷亭 +は +イヨ +大分肥 +ったな +どれ +と +無作法 +にも +吾輩 +の +襟髪 +を +攫 +んで +宙 +へ +釣 +るす +あと +足 +をこうぶら +下 +げては +鼠 +は +取 +れそうもない +どうです +奥 +さんこの +猫 +は +鼠 +を +捕 +りますかね +と +吾輩 +ばかりでは +不足 +だと +見 +えて +隣 +りの +室 +の +妻君 +に +話 +しかける +鼠 +どころじゃございません +御雑煮 +を +食 +べて +踊 +りをおどるんですもの +と +妻君 +は +飛 +んだところで +旧悪 +を +暴 +く +吾輩 +は +宙乗 +りをしながらも +少々極 +りが +悪 +かった +迷亭 +はまだ +吾輩 +を +卸 +してくれない +なるほど +踊 +りでもおどりそうな +顔 +だ +奥 +さんこの +猫 +は +油断 +のならない +相好 +ですぜ +昔 +しの +草双紙 +にある +猫又 +に +似 +ていますよ +と +勝手 +な +事 +を +言 +いながら +しきりに +細君 +に +話 +しかける +細君 +は +迷惑 +そうに +針仕事 +の +手 +をやめて +座敷 +へ +出 +てくる +どうも +御退屈様 +もう +帰 +りましょう +と +茶 +を +注 +ぎ +易 +えて +迷亭 +の +前 +へ +出 +す +どこへ +行 +ったんですかね +どこへ +参 +るにも +断 +わって +行 +った +事 +の +無 +い +男 +ですから +分 +りかねますが +大方御医者 +へでも +行 +ったんでしょう +甘木 +さんですか +甘木 +さんもあんな +病人 +に +捕 +まっちゃ +災難 +ですな +へえ +と +細君 +は +挨拶 +のしようもないと +見 +えて +簡単 +な +答 +えをする +迷亭 +は +一向頓着 +しない +近頃 +はどうです +少 +しは +胃 +の +加減 +が +能 +いんですか +能 +いか +悪 +いか +頓 +と +分 +りません +いくら +甘木 +さんにかかったって +あんなに +ジャム +ばかり +甞 +めては +胃病 +の +直 +る +訳 +がないと +思 +います +と +細君 +は +先刻 +の +不平 +を +暗 +に +迷亭 +に +洩 +らす +そんなに +ジャム +を +甞 +めるんですかまるで +小供 +のようですね +ジャム +ばかりじゃないんで +この +頃 +は +胃病 +の +薬 +だとか +云 +って +大根卸 +しを +無暗 +に +甞 +めますので +驚 +ろいたな +と +迷亭 +は +感嘆 +する +何 +でも +大根卸 +の +中 +には +ジヤスタ +ゼ +が +有 +るとか +云 +う +話 +しを +新聞 +で +読 +んでからです +なるほどそれで +ジャム +の +損害 +を +償 +おうと +云 +う +趣向 +ですな +なかなか +考 +えていらあ +ハハハハ +と +迷亭 +は +細君 +の +訴 +を +聞 +いて +大 +に +愉快 +な +気色 +である +この +間 +などは +赤 +ん +坊 +にまで +甞 +めさせまして +ジャム +をですか +いいえ +大根卸 +を +あなた +坊 +や +御父様 +がうまいものをやるからおいでてって +たまに +小供 +を +可愛 +がってくれるかと +思 +うとそんな +馬鹿 +な +事 +ばかりするんです +二三日前 +には +中 +の +娘 +を +抱 +いて +箪笥 +の +上 +へあげましてね +どう +云 +う +趣向 +がありました +と +迷亭 +は +何 +を +聞 +いても +趣向 +ずくめに +解釈 +する +なに +趣向 +も +何 +も +有 +りゃしません +ただその +上 +から +飛 +び +下 +りて +見 +ろと +云 +うんですわ +三 +つや +四 +つの +女 +の +子 +ですもの +そんな +御転婆 +な +事 +が +出来 +るはずがないです +なるほどこりゃ +趣向 +が +無 +さ +過 +ぎましたね +しかしあれで +腹 +の +中 +は +毒 +のない +善人 +ですよ +あの +上腹 +の +中 +に +毒 +があっちゃ +辛防 +は +出来 +ませんわ +と +細君 +は +大 +に +気焔 +を +揚 +げる +まあそんなに +不平 +を +云 +わんでも +善 +いでさあ +こうやって +不足 +なくその +日 +その +日 +が +暮 +らして +行 +かれれば +上 +の +分 +ですよ +苦沙弥君 +などは +道楽 +はせず +服装 +にも +構 +わず +地味 +に +世帯向 +きに +出来上 +った +人 +でさあ +と +迷亭 +は +柄 +にない +説教 +を +陽気 +な +調子 +でやっている +ところがあなた +大違 +いで +何 +か +内々 +でやりますかね +油断 +のならない +世 +の +中 +だからね +と +飄然 +とふわふわした +返事 +をする +ほかの +道楽 +はないですが +無暗 +に +読 +みもしない +本 +ばかり +買 +いましてね +それも +善 +い +加減 +に +見計 +らって +買 +ってくれると +善 +いんですけれど +勝手 +に +丸善 +へ +行 +っちゃ +何冊 +でも +取 +って +来 +て +月末 +になると +知 +らん +顔 +をしているんですもの +去年 +の +暮 +なんか +月々 +のが +溜 +って +大変困 +りました +なあに +書物 +なんか +取 +って +来 +るだけ +取 +って +来 +て +構 +わんですよ +払 +いをとりに +来 +たら +今 +にやる +今 +にやると +云 +っていりゃ +帰 +ってしまいまさあ +それでも +そういつまでも +引張 +る +訳 +にも +参 +りませんから +と +妻君 +は +憮然 +としている +それじゃ +訳 +を +話 +して +書籍費 +を +削減 +させるさ +どうして +そんな +言 +を +云 +ったって +なかなか +聞 +くものですか +この +間 +などは +貴様 +は +学者 +の +妻 +にも +似合 +わん +毫 +も +書籍 +の +価値 +を +解 +しておらん +昔 +し +羅馬 +にこう +云 +う +話 +しがある +後学 +のため +聞 +いておけと +云 +うんです +そりゃ +面白 +い +どんな +話 +しですか +迷亭 +は +乗気 +になる +細君 +に +同情 +を +表 +しているというよりむしろ +好奇心 +に +駆 +られている +何 +んでも +昔 +し +羅馬 +に +樽金 +とか +云 +う +王様 +があって +樽金 +樽金 +はちと +妙 +ですぜ +私 +は +唐人 +の +名 +なんかむずかしくて +覚 +えられませんわ +何 +でも +七代目 +なんだそうです +なるほど +七代目樽金 +は +妙 +ですな +ふんその +七代目樽金 +がどうかしましたかい +あら +あなたまで +冷 +かしては +立 +つ +瀬 +がありませんわ +知 +っていらっしゃるなら +教 +えて +下 +さればいいじゃありませんか +人 +の +悪 +い +と +細君 +は +迷亭 +へ +食 +って +掛 +る +何冷 +かすなんて +そんな +人 +の +悪 +い +事 +をする +僕 +じゃない +ただ +七代目樽金 +は +振 +ってると +思 +ってね +ええお +待 +ちなさいよ +羅馬 +の +七代目 +の +王様 +ですね +こうっとたしかには +覚 +えていないが +タ +クイン +ゼ +プラウド +の +事 +でしょう +まあ +誰 +でもいい +その +王様 +がどうしました +その +王様 +の +所 +へ +一人 +の +女 +が +本 +を +九冊持 +って +来 +て +買 +ってくれないかと +云 +ったんだそうです +なるほど +王様 +がいくらなら +売 +るといって +聞 +いたら +大変 +な +高 +い +事 +を +云 +うんですって +あまり +高 +いもんだから +少 +し +負 +けないかと +云 +うとその +女 +がいきなり +九冊 +の +内 +の +三冊 +を +火 +にくべて +焚 +いてしまったそうです +惜 +しい +事 +をしましたな +その +本 +の +内 +には +予言 +か +何 +かほかで +見 +られない +事 +が +書 +いてあるんですって +へえ +王様 +は +九冊 +が +六冊 +になったから +少 +しは +価 +も +減 +ったろうと +思 +って +六冊 +でいくらだと +聞 +くと +やはり +元 +の +通 +り +一文 +も +引 +かないそうです +それは +乱暴 +だと +云 +うと +その +女 +はまた +三冊 +をとって +火 +にくべたそうです +王様 +はまだ +未練 +があったと +見 +えて +余 +った +三冊 +をいくらで +売 +ると +聞 +くと +やはり +九冊分 +のねだんをくれと +云 +うそうです +九冊 +が +六冊 +になり +六冊 +が +三冊 +になっても +代価 +は +元 +の +通 +り +一厘 +も +引 +かない +それを +引 +かせようとすると +残 +ってる +三冊 +も +火 +にくべるかも +知 +れないので +王様 +はとうとう +高 +い +御金 +を +出 +して +焚 +け +余 +りの +三冊 +を +買 +ったんですって +どうだこの +話 +しで +少 +しは +書物 +のありがた +味 +が +分 +ったろう +どうだと +力味 +むのですけれど +私 +にゃ +何 +がありがたいんだか +まあ +分 +りませんね +と +細君 +は +一家 +の +見識 +を +立 +てて +迷亭 +の +返答 +を +促 +がす +さすがの +迷亭 +も +少々窮 +したと +見 +えて +袂 +から +ハンケチ +を +出 +して +吾輩 +をじゃらしていたが +しかし +奥 +さん +と +急 +に +何 +か +考 +えついたように +大 +きな +声 +を +出 +す +あんなに +本 +を +買 +って +矢鱈 +に +詰 +め +込 +むものだから +人 +から +少 +しは +学者 +だとか +何 +とか +云 +われるんですよ +この +間 +ある +文学雑誌 +を +見 +たら +苦沙弥君 +の +評 +が +出 +ていましたよ +ほんとに +と +細君 +は +向 +き +直 +る +主人 +の +評判 +が +気 +にかかるのは +やはり +夫婦 +と +見 +える +何 +とかいてあったんです +なあに +二三行 +ばかりですがね +苦沙弥君 +の +文 +は +行雲流水 +のごとしとありましたよ +細君 +は +少 +しにこにこして +それぎりですか +その +次 +にね +出 +ずるかと +思 +えば +忽 +ち +消 +え +逝 +いては +長 +えに +帰 +るを +忘 +るとありましたよ +細君 +は +妙 +な +顔 +をして +賞 +めたんでしょうか +と +心元 +ない +調子 +である +まあ +賞 +めた +方 +でしょうな +と +迷亭 +は +済 +まして +ハンケチ +を +吾輩 +の +眼 +の +前 +にぶら +下 +げる +書物 +は +商買道具 +で +仕方 +もござんすまいが +よっぽど +偏屈 +でしてねえ +迷亭 +はまた +別途 +の +方面 +から +来 +たなと +思 +って +偏屈 +は +少々偏屈 +ですね +学問 +をするものはどうせあんなですよ +と +調子 +を +合 +わせるような +弁護 +をするような +不即不離 +の +妙答 +をする +せんだってなどは +学校 +から +帰 +ってすぐわきへ +出 +るのに +着物 +を +着換 +えるのが +面倒 +だものですから +あなた +外套 +も +脱 +がないで +机 +へ +腰 +を +掛 +けて +御飯 +を +食 +べるのです +御膳 +を +火燵櫓 +の +上 +へ +乗 +せまして +私 +は +御櫃 +を +抱 +えて +坐 +っておりましたがおかしくって +何 +だか +ハイカラ +の +首実検 +のようですな +しかしそんなところが +苦沙弥君 +の +苦沙弥君 +たるところで +とにかく +月並 +でない +と +切 +ない +褒 +め +方 +をする +月並 +か +月並 +でないか +女 +には +分 +りませんが +なんぼ +何 +でも +あまり +乱暴 +ですわ +しかし +月並 +より +好 +いですよ +と +無暗 +に +加勢 +すると +細君 +は +不満 +な +様子 +で +一体 +月並月並 +と +皆 +さんが +よくおっしゃいますが +どんなのが +月並 +なんです +と +開 +き +直 +って +月並 +の +定義 +を +質問 +する +月並 +ですか +月並 +と +云 +うと +さようちと +説明 +しにくいのですが +そんな +曖昧 +なものなら +月並 +だって +好 +さそうなものじゃありませんか +と +細君 +は +女人一流 +の +論理法 +で +詰 +め +寄 +せる +曖昧 +じゃありませんよ +ちゃんと +分 +っています +ただ +説明 +しにくいだけの +事 +でさあ +何 +でも +自分 +の +嫌 +いな +事 +を +月並 +と +云 +うんでしょう +と +細君 +は +我知 +らず +穿 +った +事 +を +云 +う +迷亭 +もこうなると +何 +とか +月並 +の +処置 +を +付 +けなければならぬ +仕儀 +となる +奥 +さん +月並 +と +云 +うのはね +まず +年 +は +二八 +か +二九 +からぬと +言 +わず +語 +らず +物思 +いの +間 +に +寝転 +んでいて +この +日 +や +天気晴朗 +とくると +必 +ず +一瓢 +を +携 +えて +墨堤 +に +遊 +ぶ +連中 +を +云 +うんです +そんな +連中 +があるでしょうか +と +細君 +は +分 +らんものだから +好加減 +な +挨拶 +をする +何 +だかごたごたして +私 +には +分 +りませんわ +とついに +我 +を +折 +る +それじゃ +馬琴 +の +胴 +へ +メジョオ +ペンデニス +の +首 +をつけて +一二年欧州 +の +空気 +で +包 +んでおくんですね +そうすると +月並 +が +出来 +るでしょうか +迷亭 +は +返事 +をしないで +笑 +っている +何 +そんな +手数 +のかかる +事 +をしないでも +出来 +ます +中学校 +の +生徒 +に +白木屋 +の +番頭 +を +加 +えて +二 +で +割 +ると +立派 +な +月並 +が +出来上 +ります +そうでしょうか +と +細君 +は +首 +を +捻 +ったまま +納得 +し +兼 +ねたと +云 +う +風情 +に +見 +える +君 +まだいるのか +と +主人 +はいつの +間 +にやら +帰 +って +来 +て +迷亭 +の +傍 +へ +坐 +わる +まだいるのかはちと +酷 +だな +すぐ +帰 +るから +待 +ってい +給 +えと +言 +ったじゃないか +万事 +あれなんですもの +と +細君 +は +迷亭 +を +顧 +みる +今君 +の +留守中 +に +君 +の +逸話 +を +残 +らず +聞 +いてしまったぜ +女 +はとかく +多弁 +でいかん +人間 +もこの +猫 +くらい +沈黙 +を +守 +るといいがな +と +主人 +は +吾輩 +の +頭 +を +撫 +でてくれる +君 +は +赤 +ん +坊 +に +大根卸 +しを +甞 +めさしたそうだな +ふむ +と +主人 +は +笑 +ったが +赤 +ん +坊 +でも +近頃 +の +赤 +ん +坊 +はなかなか +利口 +だぜ +それ +以来 +坊 +や +辛 +いのはどこと +聞 +くときっと +舌 +を +出 +すから +妙 +だ +まるで +犬 +に +芸 +を +仕込 +む +気 +でいるから +残酷 +だ +時 +に +寒月 +はもう +来 +そうなものだな +寒月 +が +来 +るのかい +と +主人 +は +不審 +な +顔 +をする +来 +るんだ +午後一時 +までに +苦沙弥 +の +家 +へ +来 +いと +端書 +を +出 +しておいたから +人 +の +都合 +も +聞 +かんで +勝手 +な +事 +をする +男 +だ +寒月 +を +呼 +んで +何 +をするんだい +なあに +今日 +のはこっちの +趣向 +じゃない +寒月先生自身 +の +要求 +さ +先生何 +でも +理学協会 +で +演説 +をするとか +云 +うのでね +その +稽古 +をやるから +僕 +に +聴 +いてくれと +云 +うから +そりゃちょうどいい +苦沙弥 +にも +聞 +かしてやろうと +云 +うのでね +そこで +君 +の +家 +へ +呼 +ぶ +事 +にしておいたのさ +なあに +君 +はひま +人 +だからちょうどいいやね +差支 +えなんぞある +男 +じゃない +聞 +くがいいさ +と +迷亭 +は +独 +りで +呑 +み +込 +んでいる +物理学 +の +演説 +なんか +僕 +にゃ +分 +らん +と +主人 +は +少々迷亭 +の +専断 +を +憤 +ったもののごとくに +云 +う +ところがその +問題 +が +マグネ +付 +けられた +ノッズル +についてなどと +云 +う +乾燥無味 +なものじゃないんだ +首縊 +りの +力学 +と +云 +う +脱俗超凡 +な +演題 +なのだから +傾聴 +する +価値 +があるさ +君 +は +首 +を +縊 +り +損 +くなった +男 +だから +傾聴 +するが +好 +いが +僕 +なんざあ +歌舞伎座 +で +悪寒 +がするくらいの +人間 +だから +聞 +かれないと +云 +う +結論 +は +出 +そうもないぜ +と +例 +のごとく +軽口 +を +叩 +く +妻君 +は +ホホ +と +笑 +って +主人 +を +顧 +みながら +次 +の +間 +へ +退 +く +主人 +は +無言 +のまま +吾輩 +の +頭 +を +撫 +でる +この +時 +のみは +非常 +に +丁寧 +な +撫 +で +方 +であった +それから +約七分 +くらいすると +注文通 +り +寒月君 +が +来 +る +今日 +は +晩 +に +演舌 +をするというので +例 +になく +立派 +な +フロック +を +着 +て +洗濯 +し +立 +ての +白襟 +を +聳 +やかして +男振 +りを +二割方上 +げて +少 +し +後 +れまして +と +落 +ちつき +払 +って +挨拶 +をする +さっきから +二人 +で +大待 +ちに +待 +ったところなんだ +早速願 +おう +なあ +君 +と +主人 +を +見 +る +主人 +もやむを +得 +ず +うむ +と +生返事 +をする +寒月君 +はいそがない +コップ +へ +水 +を +一杯頂戴 +しましょう +と +云 +う +いよ +本式 +にやるのか +次 +には +拍手 +の +請求 +とおいでなさるだろう +と +迷亭 +は +独 +りで +騒 +ぎ +立 +てる +寒月君 +は +内隠 +しから +草稿 +を +取 +り +出 +して +徐 +ろに +稽古 +ですから +御遠慮 +なく +御批評 +を +願 +います +と +前置 +をして +いよいよ +演舌 +の +御浚 +いを +始 +める +罪人 +を +絞罪 +の +刑 +に +処 +すると +云 +う +事 +は +重 +に +アングロサクソン +民族間 +に +行 +われた +方法 +でありまして +それより +古代 +に +溯 +って +考 +えますと +首縊 +りは +重 +に +自殺 +の +方法 +として +行 +われた +者 +であります +猶太人中 +に +在 +っては +罪人 +を +石 +を +抛 +げつけて +殺 +す +習慣 +であったそうでございます +旧約全書 +を +研究 +して +見 +ますといわゆる +ハンギング +なる +語 +は +罪人 +の +死体 +を +釣 +るして +野獣 +または +肉食鳥 +の +餌食 +とする +意義 +と +認 +められます +ヘロドタス +の +説 +に +従 +って +見 +ますと +猶太人 +は +エジプト +を +去 +る +以前 +から +夜中死骸 +を +曝 +されることを +痛 +く +忌 +み +嫌 +ったように +思 +われます +エジプト +人 +は +罪人 +の +首 +を +斬 +って +胴 +だけを +十字架 +に +釘付 +けにして +夜中曝 +し +物 +にしたそうで +御座 +います +波斯人 +は +寒月君首縊 +りと +縁 +がだんだん +遠 +くなるようだが +大丈夫 +かい +と +迷亭 +が +口 +を +入 +れる +これから +本論 +に +這入 +るところですから +少々御辛防 +を +願 +います +さて +波斯人 +はどうかと +申 +しますとこれもやはり +処刑 +には +磔 +を +用 +いたようでございます +但 +し +生 +きているうちに +張付 +けに +致 +したものか +死 +んでから +釘 +を +打 +ったものかその +辺 +はちと +分 +りかねます +そんな +事 +は +分 +らんでもいいさ +と +主人 +は +退屈 +そうに +欠伸 +をする +まだいろいろ +御話 +し +致 +したい +事 +もございますが +御迷惑 +であらっしゃいましょうから +あらっしゃいましょうより +いらっしゃいましょうの +方 +が +聞 +きいいよ +ねえ +苦沙弥君 +とまた +迷亭 +が +咎 +め +立 +をすると +主人 +は +どっちでも +同 +じ +事 +だ +と +気 +のない +返事 +をする +さていよいよ +本題 +に +入 +りまして +弁 +じます +弁 +じますなんか +講釈師 +の +云 +い +草 +だ +演舌家 +はもっと +上品 +な +詞 +を +使 +って +貰 +いたいね +と +迷亭先生 +また +交 +ぜ +返 +す +弁 +じますが +下品 +なら +何 +と +云 +ったらいいでしょう +と +寒月君 +は +少々 +むっとした +調子 +で +問 +いかける +迷亭 +のは +聴 +いているのか +交 +ぜ +返 +しているのか +判然 +しない +寒月君 +そんな +弥次馬 +に +構 +わず +さっさとやるが +好 +い +と +主人 +はなるべく +早 +く +難関 +を +切 +り +抜 +けようとする +むっとして +弁 +じましたる +柳 +かな +かね +と +迷亭 +はあいかわらず +飄然 +たる +事 +を +云 +う +寒月 +は +思 +わず +吹 +き +出 +す +真 +に +処刑 +として +絞殺 +を +用 +いましたのは +私 +の +調 +べました +結果 +によりますると +オディセ +の +二十二巻目 +に +出 +ております +即 +ち +彼 +の +テレマカス +が +ペネロピ +の +十二人 +の +侍女 +を +絞殺 +するという +条 +りでございます +希臘語 +で +本文 +を +朗読 +しても +宜 +しゅうございますが +ちと +衒 +うような +気味 +にもなりますからやめに +致 +します +四百六十五行 +から +四百七十三行 +を +御覧 +になると +分 +ります +希臘語云々 +はよした +方 +がいい +さも +希臘語 +が +出来 +ますと +云 +わんばかりだ +ねえ +苦沙弥君 +それは +僕 +も +賛成 +だ +そんな +物欲 +しそうな +事 +は +言 +わん +方 +が +奥床 +しくて +好 +い +と +主人 +はいつになく +直 +ちに +迷亭 +に +加担 +する +両人 +は +毫 +も +希臘語 +が +読 +めないのである +それではこの +両三句 +は +今晩抜 +く +事 +に +致 +しまして +次 +を +弁 +じ +ええ +申 +し +上 +げます +この +絞殺 +を +今 +から +想像 +して +見 +ますと +これを +執行 +するに +二 +つの +方法 +があります +第一 +は +彼 +の +テレマカス +が +ユ +ミアス +及 +び +フ +リ +シャス +の +援 +を +藉 +りて +縄 +の +一端 +を +柱 +へ +括 +りつけます +そしてその +縄 +の +所々 +へ +結 +び +目 +を +穴 +に +開 +けてこの +穴 +へ +女 +の +頭 +を +一 +つずつ +入 +れておいて +片方 +の +端 +をぐいと +引張 +って +釣 +し +上 +げたものと +見 +るのです +つまり +西洋洗濯屋 +の +シャツ +のように +女 +がぶら +下 +ったと +見 +れば +好 +いんだろう +その +通 +りで +それから +第二 +は +縄 +の +一端 +を +前 +のごとく +柱 +へ +括 +り +付 +けて +他 +の +一端 +も +始 +めから +天井 +へ +高 +く +釣 +るのです +そしてその +高 +い +縄 +から +何本 +か +別 +の +縄 +を +下 +げて +それに +結 +び +目 +の +輪 +になったのを +付 +けて +女 +の +頸 +を +入 +れておいて +いざと +云 +う +時 +に +女 +の +足台 +を +取 +りはずすと +云 +う +趣向 +なのです +たとえて +云 +うと +縄暖簾 +の +先 +へ +提灯玉 +を +釣 +したような +景色 +と +思 +えば +間違 +はあるまい +提灯玉 +と +云 +う +玉 +は +見 +た +事 +がないから +何 +とも +申 +されませんが +もしあるとすればその +辺 +のところかと +思 +います +それでこれから +力学的 +に +第一 +の +場合 +は +到底成立 +すべきものでないと +云 +う +事 +を +証拠立 +てて +御覧 +に +入 +れます +面白 +いな +と +迷亭 +が +云 +うと +うん +面白 +い +と +主人 +も +一致 +する +まず +女 +が +同距離 +に +釣 +られると +仮定 +します +また +一番地面 +に +近 +い +二人 +の +女 +の +首 +と +首 +を +繋 +いでいる +縄 +は +ホリゾンタル +と +仮定 +します +そこで +を +縄 +が +地平線 +と +形 +づくる +角度 +とし +を +縄 +の +各部 +が +受 +ける +力 +と +見做 +し +は +縄 +のもっとも +低 +い +部分 +の +受 +ける +力 +とします +は +勿論女 +の +体重 +と +御承知下 +さい +どうです +御分 +りになりましたか +迷亭 +と +主人 +は +顔 +を +見合 +せて +大抵分 +った +と +云 +う +但 +しこの +大抵 +と +云 +う +度合 +は +両人 +が +勝手 +に +作 +ったのだから +他人 +の +場合 +には +応用 +が +出来 +ないかも +知 +れない +さて +多角形 +に +関 +する +御存 +じの +平均性理論 +によりますと +下 +のごとく +十二 +の +方程式 +が +立 +ちます +方程式 +はそのくらいで +沢山 +だろう +と +主人 +は +乱暴 +な +事 +を +云 +う +実 +はこの +式 +が +演説 +の +首脳 +なんですが +と +寒月君 +ははなはだ +残 +り +惜 +し +気 +に +見 +える +それじゃ +首脳 +だけは +逐 +って +伺 +う +事 +にしようじゃないか +と +迷亭 +も +少々恐縮 +の +体 +に +見受 +けられる +この +式 +を +略 +してしまうとせっかくの +力学的研究 +がまるで +駄目 +になるのですが +何 +そんな +遠慮 +はいらんから +ずんずん +略 +すさ +と +主人 +は +平気 +で +云 +う +それでは +仰 +せに +従 +って +無理 +ですが +略 +しましょう +それがよかろう +と +迷亭 +が +妙 +なところで +手 +をぱちぱちと +叩 +く +それから +英国 +へ +移 +って +論 +じますと +ベオウルフ +の +中 +に +絞首架即 +ち +ガルガ +と +申 +す +字 +が +見 +えますから +絞罪 +の +刑 +はこの +時代 +から +行 +われたものに +違 +ないと +思 +われます +ブラクスト +ン +の +説 +によるともし +絞罪 +に +処 +せられる +罪人 +が +万一縄 +の +具合 +で +死 +に +切 +れぬ +時 +は +再度同様 +の +刑罰 +を +受 +くべきものだとしてありますが +妙 +な +事 +には +ピヤ +ス +プロ +マン +の +中 +には +仮令兇漢 +でも +二度絞 +める +法 +はないと +云 +う +句 +があるのです +まあどっちが +本当 +か +知 +りませんが +悪 +くすると +一度 +で +死 +ねない +事 +が +往々実例 +にあるので +千七百八十六年 +に +有名 +な +フ +ツ +ゼラルド +と +云 +う +悪漢 +を +絞 +めた +事 +がありました +ところが +妙 +なはずみで +一度目 +には +台 +から +飛 +び +降 +りるときに +縄 +が +切 +れてしまったのです +またやり +直 +すと +今度 +は +縄 +が +長過 +ぎて +足 +が +地面 +へ +着 +いたのでやはり +死 +ねなかったのです +とうとう +三返目 +に +見物人 +が +手伝 +って +往生 +さしたと +云 +う +話 +しです +やれやれ +と +迷亭 +はこんなところへくると +急 +に +元気 +が +出 +る +本当 +に +死 +に +損 +いだな +と +主人 +まで +浮 +かれ +出 +す +まだ +面白 +い +事 +があります +首 +を +縊 +ると +背 +が +一寸 +ばかり +延 +びるそうです +これはたしかに +医者 +が +計 +って +見 +たのだから +間違 +はありません +それは +新工夫 +だね +どうだい +苦沙弥 +などはちと +釣 +って +貰 +っちゃあ +一寸延 +びたら +人間並 +になるかも +知 +れないぜ +と +迷亭 +が +主人 +の +方 +を +向 +くと +主人 +は +案外真面目 +で +寒月君 +一寸 +くらい +背 +が +延 +びて +生 +き +返 +る +事 +があるだろうか +と +聞 +く +それは +駄目 +に +極 +っています +釣 +られて +脊髄 +が +延 +びるからなんで +早 +く +云 +うと +背 +が +延 +びると +云 +うより +壊 +れるんですからね +それじゃ +まあ +止 +めよう +と +主人 +は +断念 +する +演説 +の +続 +きは +まだなかなか +長 +くあって +寒月君 +は +首縊 +りの +生理作用 +にまで +論及 +するはずでいたが +迷亭 +が +無暗 +に +風来坊 +のような +珍語 +を +挟 +むのと +主人 +が +時々遠慮 +なく +欠伸 +をするので +ついに +中途 +でやめて +帰 +ってしまった +その +晩 +は +寒月君 +がいかなる +態度 +で +いかなる +雄弁 +を +振 +ったか +遠方 +で +起 +った +出来事 +の +事 +だから +吾輩 +には +知 +れよう +訳 +がない +二三日 +は +事 +もなく +過 +ぎたが +或 +る +日 +の +午後二時頃 +また +迷亭先生 +は +例 +のごとく +空々 +として +偶然童子 +のごとく +舞 +い +込 +んで +来 +た +座 +に +着 +くと +いきなり +君 +越智東風 +の +高輪事件 +を +聞 +いたかい +と +旅順陥落 +の +号外 +を +知 +らせに +来 +たほどの +勢 +を +示 +す +知 +らん +近頃 +は +合 +わんから +と +主人 +は +平生 +の +通 +り +陰気 +である +きょうはその +東風子 +の +失策物語 +を +御報道 +に +及 +ぼうと +思 +って +忙 +しいところをわざわざ +来 +たんだよ +またそんな +仰山 +な +事 +を +云 +う +君 +は +全体不埒 +な +男 +だ +ハハハハハ +不埒 +と +云 +わんよりむしろ +無埒 +の +方 +だろう +それだけはちょっと +区別 +しておいて +貰 +わんと +名誉 +に +関係 +するからな +おんなし +事 +だ +と +主人 +は +嘯 +いている +純然 +たる +天然居士 +の +再来 +だ +この +前 +の +日曜 +に +東風子 +が +高輪泉岳寺 +に +行 +ったんだそうだ +この +寒 +いのによせばいいのに +第一今時泉岳寺 +などへ +参 +るのはさも +東京 +を +知 +らない +田舎者 +のようじゃないか +それは +東風 +の +勝手 +さ +君 +がそれを +留 +める +権利 +はない +なるほど +権利 +は +正 +にない +権利 +はどうでもいいが +あの +寺内 +に +義士遺物保存会 +と +云 +う +見世物 +があるだろう +君知 +ってるか +うんにゃ +知 +らない +だって +泉岳寺 +へ +行 +った +事 +はあるだろう +いいや +ない +こりゃ +驚 +ろいた +道理 +で +大変東風 +を +弁護 +すると +思 +った +江戸 +っ +子 +が +泉岳寺 +を +知 +らないのは +情 +けない +知 +らなくても +教師 +は +務 +まるからな +と +主人 +はいよいよ +天然居士 +になる +そりゃ +好 +いが +その +展覧場 +へ +東風 +が +這入 +って +見物 +していると +そこへ +独逸人 +が +夫婦連 +で +来 +たんだって +それが +最初 +は +日本語 +で +東風 +に +何 +か +質問 +したそうだ +ところが +先生例 +の +通 +り +独逸語 +が +使 +って +見 +たくてたまらん +男 +だろう +そら +二口三口 +べらべらやって +見 +たとさ +すると +存外 +うまく +出来 +たんだ +あとで +考 +えるとそれが +災 +の +本 +さね +それからどうした +と +主人 +はついに +釣 +り +込 +まれる +独逸人 +が +大鷹源吾 +の +蒔絵 +の +印籠 +を +見 +て +これを +買 +いたいが +売 +ってくれるだろうかと +聞 +くんだそうだ +その +時東風 +の +返事 +が +面白 +いじゃないか +日本人 +は +清廉 +の +君子 +ばかりだから +到底駄目 +だと +云 +ったんだとさ +その +辺 +は +大分景気 +がよかったが +それから +独逸人 +の +方 +では +恰好 +な +通弁 +を +得 +たつもりでしきりに +聞 +くそうだ +何 +を +それがさ +何 +だか +分 +るくらいなら +心配 +はないんだが +早口 +で +無暗 +に +問 +い +掛 +けるものだから +少 +しも +要領 +を +得 +ないのさ +たまに +分 +るかと +思 +うと +鳶口 +や +掛矢 +の +事 +を +聞 +かれる +西洋 +の +鳶口 +や +掛矢 +は +先生何 +と +翻訳 +して +善 +いのか +習 +った +事 +が +無 +いんだから +弱 +わらあね +もっともだ +と +主人 +は +教師 +の +身 +の +上 +に +引 +き +較 +べて +同情 +を +表 +する +ところへ +閑人 +が +物珍 +しそうにぽつぽつ +集 +ってくる +仕舞 +には +東風 +と +独逸人 +を +四方 +から +取 +り +巻 +いて +見物 +する +東風 +は +顔 +を +赤 +くしてへどもどする +初 +めの +勢 +に +引 +き +易 +えて +先生大弱 +りの +体 +さ +結局 +どうなったんだい +仕舞 +に +東風 +が +我慢出来 +なくなったと +見 +えてさいならと +日本語 +で +云 +ってぐんぐん +帰 +って +来 +たそうだ +さいならは +少 +し +変 +だ +君 +の +国 +ではさよならをさいならと +云 +うかって +聞 +いて +見 +たら +何 +やっぱりさよならですが +相手 +が +西洋人 +だから +調和 +を +計 +るために +さいならにしたんだって +東風子 +は +苦 +しい +時 +でも +調和 +を +忘 +れない +男 +だと +感心 +した +さいならはいいが +西洋人 +はどうした +西洋人 +はあっけに +取 +られて +茫然 +と +見 +ていたそうだ +ハハハハ +面白 +いじゃないか +別段面白 +い +事 +もないようだ +それをわざわざ +報知 +に +来 +る +君 +の +方 +がよっぽど +面白 +いぜ +と +主人 +は +巻煙草 +の +灰 +を +火桶 +の +中 +へはたき +落 +す +折柄格子戸 +の +ベル +が +飛 +び +上 +るほど +鳴 +って +御免 +なさい +と +鋭 +どい +女 +の +声 +がする +迷亭 +と +主人 +は +思 +わず +顔 +を +見合 +わせて +沈黙 +する +主人 +のうちへ +女客 +は +稀有 +だなと +見 +ていると +かの +鋭 +どい +声 +の +所有主 +は +縮緬 +の +二枚重 +ねを +畳 +へ +擦 +り +付 +けながら +這入 +って +来 +る +年 +は +四十 +の +上 +を +少 +し +超 +したくらいだろう +抜 +け +上 +った +生 +え +際 +から +前髪 +が +堤防工事 +のように +高 +く +聳 +えて +少 +なくとも +顔 +の +長 +さの +二分 +の +一 +だけ +天 +に +向 +ってせり +出 +している +眼 +が +切 +り +通 +しの +坂 +くらいな +勾配 +で +直線 +に +釣 +るし +上 +げられて +左右 +に +対立 +する +直線 +とは +鯨 +より +細 +いという +形容 +である +鼻 +だけは +無暗 +に +大 +きい +人 +の +鼻 +を +盗 +んで +来 +て +顔 +の +真中 +へ +据 +え +付 +けたように +見 +える +三坪 +ほどの +小庭 +へ +招魂社 +の +石灯籠 +を +移 +した +時 +のごとく +独 +りで +幅 +を +利 +かしているが +何 +となく +落 +ちつかない +その +鼻 +はいわゆる +鍵鼻 +で +ひと +度 +は +精一杯高 +くなって +見 +たが +これではあんまりだと +中途 +から +謙遜 +して +先 +の +方 +へ +行 +くと +初 +めの +勢 +に +似 +ず +垂 +れかかって +下 +にある +唇 +を +覗 +き +込 +んでいる +かく +著 +るしい +鼻 +だから +この +女 +が +物 +を +言 +うときは +口 +が +物 +を +言 +うと +云 +わんより +鼻 +が +口 +をきいているとしか +思 +われない +吾輩 +はこの +偉大 +なる +鼻 +に +敬意 +を +表 +するため +以来 +はこの +女 +を +称 +して +鼻子鼻子 +と +呼 +ぶつもりである +鼻子 +は +先 +ず +初対面 +の +挨拶 +を +終 +って +どうも +結構 +な +御住居 +ですこと +と +座敷中 +を +睨 +め +廻 +わす +主人 +は +嘘 +をつけ +と +腹 +の +中 +で +言 +ったまま +ぷかぷか +煙草 +をふかす +迷亭 +は +天井 +を +見 +ながら +君 +ありゃ +雨洩 +りか +板 +の +木目 +か +妙 +な +模様 +が +出 +ているぜ +と +暗 +に +主人 +を +促 +がす +無論雨 +の +洩 +りさ +と +主人 +が +答 +えると +結構 +だなあ +と +迷亭 +がすまして +云 +う +鼻子 +は +社交 +を +知 +らぬ +人達 +だと +腹 +の +中 +で +憤 +る +しばらくは +三人鼎坐 +のまま +無言 +である +ちと +伺 +いたい +事 +があって +参 +ったんですが +と +鼻子 +は +再 +び +話 +の +口 +を +切 +る +はあ +と +主人 +が +極 +めて +冷淡 +に +受 +ける +これではならぬと +鼻子 +は +実 +は +私 +はつい +御近所 +で +あの +向 +う +横丁 +の +角屋敷 +なんですが +あの +大 +きな +西洋館 +の +倉 +のあるうちですか +道理 +であすこには +金田 +と +云 +う +標札 +が +出 +ていますな +と +主人 +はようやく +金田 +の +西洋館 +と +金田 +の +倉 +を +認識 +したようだが +金田夫人 +に +対 +する +尊敬 +の +度合 +は +前 +と +同様 +である +実 +は +宿 +が +出 +まして +御話 +を +伺 +うんですが +会社 +の +方 +が +大変忙 +がしいもんですから +と +今度 +は +少 +し +利 +いたろうという +眼付 +をする +主人 +は +一向動 +じない +鼻子 +の +先刻 +からの +言葉遣 +いが +初対面 +の +女 +としてはあまり +存在過 +ぎるのですでに +不平 +なのである +会社 +でも +一 +つじゃ +無 +いんです +二 +つも +三 +つも +兼 +ねているんです +それにどの +会社 +でも +重役 +なんで +多分御存知 +でしょうが +これでも +恐 +れ +入 +らぬかと +云 +う +顔付 +をする +元来 +ここの +主人 +は +博士 +とか +大学教授 +とかいうと +非常 +に +恐縮 +する +男 +であるが +妙 +な +事 +には +実業家 +に +対 +する +尊敬 +の +度 +は +極 +めて +低 +い +実業家 +よりも +中学校 +の +先生 +の +方 +がえらいと +信 +じている +よし +信 +じておらんでも +融通 +の +利 +かぬ +性質 +として +到底実業家 +金満家 +の +恩顧 +を +蒙 +る +事 +は +覚束 +ないと +諦 +らめている +いくら +先方 +が +勢力家 +でも +財産家 +でも +自分 +が +世話 +になる +見込 +のないと +思 +い +切 +った +人 +の +利害 +には +極 +めて +無頓着 +である +それだから +学者社会 +を +除 +いて +他 +の +方面 +の +事 +には +極 +めて +迂濶 +で +ことに +実業界 +などでは +どこに +だれが +何 +をしているか +一向知 +らん +知 +っても +尊敬畏服 +の +念 +は +毫 +も +起 +らんのである +鼻子 +の +方 +では +天 +が +下 +の +一隅 +にこんな +変人 +がやはり +日光 +に +照 +らされて +生活 +していようとは +夢 +にも +知 +らない +今 +まで +世 +の +中 +の +人間 +にも +大分接 +して +見 +たが +金田 +の +妻 +ですと +名乗 +って +急 +に +取扱 +いの +変 +らない +場合 +はない +どこの +会 +へ +出 +ても +どんな +身分 +の +高 +い +人 +の +前 +でも +立派 +に +金田夫人 +で +通 +して +行 +かれる +いわんやこんな +燻 +り +返 +った +老書生 +においてをやで +私 +の +家 +は +向 +う +横丁 +の +角屋敷 +ですとさえ +云 +えば +職業 +などは +聞 +かぬ +先 +から +驚 +くだろうと +予期 +していたのである +金田 +って +人 +を +知 +ってるか +と +主人 +は +無雑作 +に +迷亭 +に +聞 +く +知 +ってるとも +金田 +さんは +僕 +の +伯父 +の +友達 +だ +この +間 +なんざ +園遊会 +へおいでになった +と +迷亭 +は +真面目 +な +返事 +をする +へえ +君 +の +伯父 +さんてえな +誰 +だい +牧山男爵 +さ +と +迷亭 +はいよいよ +真面目 +である +主人 +が +何 +か +云 +おうとして +云 +わぬ +先 +に +鼻子 +は +急 +に +向 +き +直 +って +迷亭 +の +方 +を +見 +る +迷亭 +は +大島紬 +に +古渡更紗 +か +何 +か +重 +ねてすましている +おや +あなたが +牧山様 +の +何 +でいらっしゃいますか +ちっとも +存 +じませんで +はなはだ +失礼 +を +致 +しました +牧山様 +には +始終御世話 +になると +宿 +で +毎々御噂 +を +致 +しております +と +急 +に +叮嚀 +な +言葉使 +をして +おまけに +御辞儀 +までする +迷亭 +は +へええ +何 +ハハハハ +と +笑 +っている +主人 +はあっ +気 +に +取 +られて +無言 +で +二人 +を +見 +ている +たしか +娘 +の +縁辺 +の +事 +につきましてもいろいろ +牧山 +さまへ +御心配 +を +願 +いましたそうで +へえ +そうですか +とこればかりは +迷亭 +にもちと +唐突過 +ぎたと +見 +えてちょっと +魂消 +たような +声 +を +出 +す +実 +は +方々 +からくれくれと +申 +し +込 +はございますが +こちらの +身分 +もあるものでございますから +滅多 +な +所 +へも +片付 +けられませんので +ごもっともで +と +迷亭 +はようやく +安心 +する +それについて +あなたに +伺 +おうと +思 +って +上 +がったんですがね +と +鼻子 +は +主人 +の +方 +を +見 +て +急 +に +存在 +な +言葉 +に +返 +る +あなたの +所 +へ +水島寒月 +という +男 +が +度々上 +がるそうですが +あの +人 +は +全体 +どんな +風 +な +人 +でしょう +寒月 +の +事 +を +聞 +いて +何 +にするんです +と +主人 +は +苦々 +しく +云 +う +やはり +御令嬢 +の +御婚儀上 +の +関係 +で +寒月君 +の +性行 +の +一斑 +を +御承知 +になりたいという +訳 +でしょう +と +迷亭 +が +気転 +を +利 +かす +それが +伺 +えれば +大変都合 +が +宜 +しいのでございますが +それじゃ +御令嬢 +を +寒月 +におやりになりたいとおっしゃるんで +やりたいなんてえんじゃ +無 +いんです +と +鼻子 +は +急 +に +主人 +を +参 +らせる +ほかにもだんだん +口 +が +有 +るんですから +無理 +に +貰 +っていただかないだって +困 +りゃしません +それじゃ +寒月 +の +事 +なんか +聞 +かんでも +好 +いでしょう +と +主人 +も +躍起 +となる +しかし +御隠 +しなさる +訳 +もないでしょう +と +鼻子 +も +少々喧嘩腰 +になる +迷亭 +は +双方 +の +間 +に +坐 +って +銀煙管 +を +軍配団扇 +のように +持 +って +心 +の +裡 +で +八卦 +よいやよいやと +怒鳴 +っている +じゃあ +寒月 +の +方 +で +是非貰 +いたいとでも +云 +ったのですか +と +主人 +が +正面 +から +鉄砲 +を +喰 +わせる +貰 +いたいと +云 +ったんじゃないんですけれども +貰 +いたいだろうと +思 +っていらっしゃるんですか +と +主人 +はこの +婦人鉄砲 +に +限 +ると +覚 +ったらしい +話 +しはそんなに +運 +んでるんじゃありませんが +寒月 +さんだって +満更嬉 +しくない +事 +もないでしょう +と +土俵際 +で +持 +ち +直 +す +寒月 +が +何 +かその +御令嬢 +に +恋着 +したというような +事 +でもありますか +あるなら +云 +って +見 +ろと +云 +う +権幕 +で +主人 +は +反 +り +返 +る +まあ +そんな +見当 +でしょうね +今度 +は +主人 +の +鉄砲 +が +少 +しも +功 +を +奏 +しない +今 +まで +面白気 +に +行司気取 +りで +見物 +していた +迷亭 +も +鼻子 +の +一言 +に +好奇心 +を +挑撥 +されたものと +見 +えて +煙管 +を +置 +いて +前 +へ +乗 +り +出 +す +寒月 +が +御嬢 +さんに +付 +け +文 +でもしたんですか +こりゃ +愉快 +だ +新年 +になって +逸話 +がまた +一 +つ +殖 +えて +話 +しの +好材料 +になる +と +一人 +で +喜 +んでいる +付 +け +文 +じゃないんです +もっと +烈 +しいんでさあ +御二人 +とも +御承知 +じゃありませんか +と +鼻子 +は +乙 +にからまって +来 +る +君知 +ってるか +と +主人 +は +狐付 +きのような +顔 +をして +迷亭 +に +聞 +く +迷亭 +も +馬鹿気 +た +調子 +で +僕 +は +知 +らん +知 +っていりゃ +君 +だ +とつまらんところで +謙遜 +する +いえ +御両人共御存 +じの +事 +ですよ +と +鼻子 +だけ +大得意 +である +へえ +と +御両人 +は +一度 +に +感 +じ +入 +る +御忘 +れになったら +私 +しから +御話 +をしましょう +去年 +の +暮向島 +の +阿部 +さんの +御屋敷 +で +演奏会 +があって +寒月 +さんも +出掛 +けたじゃありませんか +その +晩帰 +りに +吾妻橋 +で +何 +かあったでしょう +詳 +しい +事 +は +言 +いますまい +当人 +の +御迷惑 +になるかも +知 +れませんから +あれだけの +証拠 +がありゃ +充分 +だと +思 +いますが +どんなものでしょう +と +金剛石入 +りの +指環 +の +嵌 +った +指 +を +膝 +の +上 +へ +併 +べて +つんと +居 +ずまいを +直 +す +偉大 +なる +鼻 +がますます +異彩 +を +放 +って +迷亭 +も +主人 +も +有 +れども +無 +きがごとき +有様 +である +主人 +は +無論 +さすがの +迷亭 +もこの +不意撃 +には +胆 +を +抜 +かれたものと +見 +えて +しばらくは +呆然 +として +瘧 +の +落 +ちた +病人 +のように +坐 +っていたが +驚愕 +の +箍 +がゆるんでだんだん +持前 +の +本態 +に +復 +すると +共 +に +滑稽 +と +云 +う +感 +じが +一度 +に +吶喊 +してくる +両人 +は +申 +し +合 +せたごとく +ハハハハハ +と +笑 +い +崩 +れる +鼻子 +ばかりは +少 +し +当 +てがはずれて +この +際笑 +うのははなはだ +失礼 +だと +両人 +を +睨 +みつける +あれが +御嬢 +さんですか +なるほどこりゃいい +おっしゃる +通 +りだ +ねえ +苦沙弥君 +全 +く +寒月 +はお +嬢 +さんを +恋 +ってるに +相違 +ないね +もう +隠 +したってしようがないから +白状 +しようじゃないか +ウフン +と +主人 +は +云 +ったままである +本当 +に +御隠 +しなさってもいけませんよ +ちゃんと +種 +は +上 +ってるんですからね +と +鼻子 +はまた +得意 +になる +こうなりゃ +仕方 +がない +何 +でも +寒月君 +に +関 +する +事実 +は +御参考 +のために +陳述 +するさ +おい +苦沙弥君 +君 +が +主人 +だのに +そう +にやにや +笑 +っていては +埒 +があかんじゃないか +実 +に +秘密 +というものは +恐 +ろしいものだねえ +いくら +隠 +しても +どこからか +露見 +するからな +しかし +不思議 +と +云 +えば +不思議 +ですねえ +金田 +の +奥 +さん +どうしてこの +秘密 +を +御探知 +になったんです +実 +に +驚 +ろきますな +と +迷亭 +は +一人 +で +喋舌 +る +私 +しの +方 +だって +ぬかりはありませんやね +と +鼻子 +はしたり +顔 +をする +あんまり +ぬかりが +無 +さ +過 +ぎるようですぜ +一体誰 +に +御聞 +きになったんです +じきこの +裏 +にいる +車屋 +の +神 +さんからです +あの +黒猫 +のいる +車屋 +ですか +と +主人 +は +眼 +を +丸 +くする +ええ +寒月 +さんの +事 +じゃ +よっぽど +使 +いましたよ +寒月 +さんが +ここへ +来 +る +度 +に +どんな +話 +しをするかと +思 +って +車屋 +の +神 +さんを +頼 +んで +一々知 +らせて +貰 +うんです +そりゃ +苛 +い +と +主人 +は +大 +きな +声 +を +出 +す +なあに +あなたが +何 +をなさろうとおっしゃろうと +それに +構 +ってるんじゃないんです +寒月 +さんの +事 +だけですよ +寒月 +の +事 +だって +誰 +の +事 +だって +全体 +あの +車屋 +の +神 +さんは +気 +に +食 +わん +奴 +だ +と +主人 +は +一人怒 +り +出 +す +しかしあなたの +垣根 +のそとへ +来 +て +立 +っているのは +向 +うの +勝手 +じゃありませんか +話 +しが +聞 +えてわるけりゃもっと +小 +さい +声 +でなさるか +もっと +大 +きなうちへ +御這入 +んなさるがいいでしょう +と +鼻子 +は +少 +しも +赤面 +した +様子 +がない +車屋 +ばかりじゃありません +新道 +の +二絃琴 +の +師匠 +からも +大分 +いろいろな +事 +を +聞 +いています +寒月 +の +事 +をですか +寒月 +さんばかりの +事 +じゃありません +と +少 +し +凄 +い +事 +を +云 +う +主人 +は +恐 +れ +入 +るかと +思 +うと +あの +師匠 +はいやに +上品 +ぶって +自分 +だけ +人間 +らしい +顔 +をしている +馬鹿野郎 +です +憚 +り +様 +女 +ですよ +野郎 +は +御門違 +いです +と +鼻子 +の +言葉使 +いはますます +御里 +をあらわして +来 +る +これではまるで +喧嘩 +をしに +来 +たようなものであるが +そこへ +行 +くと +迷亭 +はやはり +迷亭 +でこの +談判 +を +面白 +そうに +聞 +いている +鉄枴仙人 +が +軍鶏 +の +蹴合 +いを +見 +るような +顔 +をして +平気 +で +聞 +いている +悪口 +の +交換 +では +到底鼻子 +の +敵 +でないと +自覚 +した +主人 +は +しばらく +沈黙 +を +守 +るのやむを +得 +ざるに +至 +らしめられていたが +ようやく +思 +い +付 +いたか +あなたは +寒月 +の +方 +から +御嬢 +さんに +恋着 +したようにばかりおっしゃるが +私 +の +聞 +いたんじゃ +少 +し +違 +いますぜ +ねえ +迷亭君 +と +迷亭 +の +救 +いを +求 +める +うん +あの +時 +の +話 +しじゃ +御嬢 +さんの +方 +が +始 +め +病気 +になって +何 +だか +譫語 +をいったように +聞 +いたね +なにそんな +事 +はありません +と +金田夫人 +は +判然 +たる +直線流 +の +言葉使 +いをする +それでも +寒月 +はたしかに +博士 +の +夫人 +から +聞 +いたと +云 +っていましたぜ +それがこっちの +手 +なんでさあ +博士 +の +奥 +さんを +頼 +んで +寒月 +さんの +気 +を +引 +いて +見 +たんでさあね +の +奥 +さんは +それを +承知 +で +引 +き +受 +けたんですか +ええ +引 +き +受 +けて +貰 +うたって +ただじゃ +出来 +ませんやね +それやこれやでいろいろ +物 +を +使 +っているんですから +是非寒月君 +の +事 +を +根堀 +り +葉堀 +り +御聞 +きにならなくっちゃ +御帰 +りにならないと +云 +う +決心 +ですかね +と +迷亭 +も +少 +し +気持 +を +悪 +くしたと +見 +えて +いつになく +手障 +りのあらい +言葉 +を +使 +う +いいや +君 +話 +したって +損 +の +行 +く +事 +じゃなし +話 +そうじゃないか +苦沙弥君 +奥 +さん +私 +でも +苦沙弥 +でも +寒月君 +に +関 +する +事実 +で +差支 +えのない +事 +は +みんな +話 +しますからね +そう +順 +を +立 +ててだんだん +聞 +いて +下 +さると +都合 +がいいですね +鼻子 +はようやく +納得 +してそろそろ +質問 +を +呈出 +する +一時荒立 +てた +言葉使 +いも +迷亭 +に +対 +してはまたもとのごとく +叮嚀 +になる +寒月 +さんも +理学士 +だそうですが +全体 +どんな +事 +を +専門 +にしているのでございます +大学院 +では +地球 +の +磁気 +の +研究 +をやっています +と +主人 +が +真面目 +に +答 +える +不幸 +にしてその +意味 +が +鼻子 +には +分 +らんものだから +へえ +とは +云 +ったが +怪訝 +な +顔 +をしている +それを +勉強 +すると +博士 +になれましょうか +と +聞 +く +博士 +にならなければやれないとおっしゃるんですか +と +主人 +は +不愉快 +そうに +尋 +ねる +ええ +ただの +学士 +じゃね +いくらでもありますからね +と +鼻子 +は +平気 +で +答 +える +主人 +は +迷亭 +を +見 +ていよいよいやな +顔 +をする +博士 +になるかならんかは +僕等 +も +保証 +する +事 +が +出来 +んから +ほかの +事 +を +聞 +いていただく +事 +にしよう +と +迷亭 +もあまり +好 +い +機嫌 +ではない +近頃 +でもその +地球 +の +何 +かを +勉強 +しているんでございましょうか +二三日前 +は +首縊 +りの +力学 +と +云 +う +研究 +の +結果 +を +理学協会 +で +演説 +しました +と +主人 +は +何 +の +気 +も +付 +かずに +云 +う +おやいやだ +首縊 +りだなんて +よっぽど +変人 +ですねえ +そんな +首縊 +りや +何 +かやってたんじゃ +とても +博士 +にはなれますまいね +本人 +が +首 +を +縊 +っちゃあむずかしいですが +首縊 +りの +力学 +なら +成 +れないとも +限 +らんです +そうでしょうか +と +今度 +は +主人 +の +方 +を +見 +て +顔色 +を +窺 +う +悲 +しい +事 +に +力学 +と +云 +う +意味 +がわからんので +落 +ちつきかねている +しかしこれしきの +事 +を +尋 +ねては +金田夫人 +の +面目 +に +関 +すると +思 +ってか +ただ +相手 +の +顔色 +で +八卦 +を +立 +てて +見 +る +主人 +の +顔 +は +渋 +い +そのほかになにか +分 +り +易 +いものを +勉強 +しておりますまいか +そうですな +せんだって +団栗 +の +スタビリチ +を +論 +じて +併 +せて +天体 +の +運行 +に +及 +ぶと +云 +う +論文 +を +書 +いた +事 +があります +団栗 +なんぞでも +大学校 +で +勉強 +するものでしょうか +さあ +僕 +も +素人 +だからよく +分 +らんが +何 +しろ +寒月君 +がやるくらいなんだから +研究 +する +価値 +があると +見 +えますな +と +迷亭 +はすまして +冷 +かす +鼻子 +は +学問上 +の +質問 +は +手 +に +合 +わんと +断念 +したものと +見 +えて +今度 +は +話題 +を +転 +ずる +御話 +は +違 +いますが +この +御正月 +に +椎茸 +を +食 +べて +前歯 +を +二枚折 +ったそうじゃございませんか +ええその +欠 +けたところに +空也餅 +がくっ +付 +いていましてね +と +迷亭 +はこの +質問 +こそ +吾縄張内 +だと +急 +に +浮 +かれ +出 +す +色気 +のない +人 +じゃございませんか +何 +だって +楊子 +を +使 +わないんでしょう +今度逢 +ったら +注意 +しておきましょう +と +主人 +がくすくす +笑 +う +椎茸 +で +歯 +がかけるくらいじゃ +よほど +歯 +の +性 +が +悪 +いと +思 +われますが +如何 +なものでしょう +善 +いとは +言 +われますまいな +ねえ +迷亭 +善 +い +事 +はないがちょっと +愛嬌 +があるよ +あれぎり +まだ +填 +めないところが +妙 +だ +今 +だに +空也餅引掛所 +になってるなあ +奇観 +だぜ +歯 +を +填 +める +小遣 +がないので +欠 +けなりにしておくんですか +または +物好 +きで +欠 +けなりにしておくんでしょうか +何 +も +永 +く +前歯欠成 +を +名乗 +る +訳 +でもないでしょうから +御安心 +なさいよ +と +迷亭 +の +機嫌 +はだんだん +回復 +してくる +鼻子 +はまた +問題 +を +改 +める +何 +か +御宅 +に +手紙 +かなんぞ +当人 +の +書 +いたものでもございますならちょっと +拝見 +したいもんでございますが +端書 +なら +沢山 +あります +御覧 +なさい +と +主人 +は +書斎 +から +三四十枚持 +って +来 +る +そんなに +沢山拝見 +しないでも +その +内 +の +二三枚 +だけ +どれどれ +僕 +が +好 +いのを +撰 +ってやろう +と +迷亭先生 +は +これなざあ +面白 +いでしょう +と +一枚 +の +絵葉書 +を +出 +す +おや +絵 +もかくんでございますか +なかなか +器用 +ですね +どれ +拝見 +しましょう +と +眺 +めていたが +あらいやだ +狸 +だよ +何 +だって +撰 +りに +撰 +って +狸 +なんぞかくんでしょうね +それでも +狸 +と +見 +えるから +不思議 +だよ +と +少 +し +感心 +する +その +文句 +を +読 +んで +御覧 +なさい +と +主人 +が +笑 +いながら +云 +う +鼻子 +は +下女 +が +新聞 +を +読 +むように +読 +み +出 +す +旧暦 +の +歳 +の +夜 +山 +の +狸 +が +園遊会 +をやって +盛 +に +舞踏 +します +その +歌 +に +曰 +く +来 +いさ +としの +夜 +で +御山婦美 +も +来 +まいぞ +スッポコポンノポン +何 +ですこりゃ +人 +を +馬鹿 +にしているじゃございませんか +と +鼻子 +は +不平 +の +体 +である +この +天女 +は +御気 +に +入 +りませんか +と +迷亭 +がまた +一枚出 +す +見 +ると +天女 +が +羽衣 +を +着 +て +琵琶 +を +弾 +いている +この +天女 +の +鼻 +が +少 +し +小 +さ +過 +ぎるようですが +何 +それが +人並 +ですよ +鼻 +より +文句 +を +読 +んで +御覧 +なさい +文句 +にはこうある +昔 +しある +所 +に +一人 +の +天文学者 +がありました +ある +夜 +いつものように +高 +い +台 +に +登 +って +一心 +に +星 +を +見 +ていますと +空 +に +美 +しい +天女 +が +現 +われ +この +世 +では +聞 +かれぬほどの +微妙 +な +音楽 +を +奏 +し +出 +したので +天文学者 +は +身 +に +沁 +む +寒 +さも +忘 +れて +聞 +き +惚 +れてしまいました +朝見 +るとその +天文学者 +の +死骸 +に +霜 +が +真白 +に +降 +っていました +これは +本当 +の +噺 +だと +あのうそつきの +爺 +やが +申 +しました +何 +の +事 +ですこりゃ +意味 +も +何 +もないじゃありませんか +これでも +理学士 +で +通 +るんですかね +ちっと +文芸倶楽部 +でも +読 +んだらよさそうなものですがねえ +と +寒月君 +さんざんにやられる +迷亭 +は +面白半分 +に +こりゃどうです +と +三枚目 +を +出 +す +今度 +は +活版 +で +帆懸舟 +が +印刷 +してあって +例 +のごとくその +下 +に +何 +か +書 +き +散 +らしてある +よべの +泊 +りの +十六小女郎 +親 +がないとて +荒磯 +の +千鳥 +さよの +寝覚 +の +千鳥 +に +泣 +いた +親 +は +船乗 +り +波 +の +底 +うまいのねえ +感心 +だ +事 +話 +せるじゃありませんか +話 +せますかな +ええこれなら +三味線 +に +乗 +りますよ +三味線 +に +乗 +りゃ +本物 +だ +こりゃ +如何 +です +と +迷亭 +は +無暗 +に +出 +す +いえ +もうこれだけ +拝見 +すれば +ほかのは +沢山 +で +そんなに +野暮 +でないんだと +云 +う +事 +は +分 +りましたから +と +一人 +で +合点 +している +鼻子 +はこれで +寒月 +に +関 +する +大抵 +の +質問 +を +卒 +えたものと +見 +えて +これははなはだ +失礼 +を +致 +しました +どうか +私 +の +参 +った +事 +は +寒月 +さんへは +内々 +に +願 +います +と +得手勝手 +な +要求 +をする +寒月 +の +事 +は +何 +でも +聞 +かなければならないが +自分 +の +方 +の +事 +は +一切寒月 +へ +知 +らしてはならないと +云 +う +方針 +と +見 +える +迷亭 +も +主人 +も +はあ +と +気 +のない +返事 +をすると +いずれその +内御礼 +は +致 +しますから +と +念 +を +入 +れて +言 +いながら +立 +つ +見送 +りに +出 +た +両人 +が +席 +へ +返 +るや +否 +や +迷亭 +が +ありゃ +何 +だい +と +云 +うと +主人 +も +ありゃ +何 +だい +と +双方 +から +同 +じ +問 +をかける +奥 +の +部屋 +で +細君 +が +怺 +え +切 +れなかったと +見 +えて +クツクツ +笑 +う +声 +が +聞 +える +迷亭 +は +大 +きな +声 +を +出 +して +奥 +さん +奥 +さん +月並 +の +標本 +が +来 +ましたぜ +月並 +もあのくらいになるとなかなか +振 +っていますなあ +さあ +遠慮 +はいらんから +存分御笑 +いなさい +主人 +は +不満 +な +口気 +で +第一気 +に +喰 +わん +顔 +だ +と +悪 +らしそうに +云 +うと +迷亭 +はすぐ +引 +きうけて +鼻 +が +顔 +の +中央 +に +陣取 +って +乙 +に +構 +えているなあ +とあとを +付 +ける +しかも +曲 +っていらあ +少 +し +猫背 +だね +猫背 +の +鼻 +は +ちと +奇抜過 +ぎる +と +面白 +そうに +笑 +う +夫 +を +剋 +する +顔 +だ +と +主人 +はなお +口惜 +しそうである +十九世紀 +で +売 +れ +残 +って +二十世紀 +で +店曝 +しに +逢 +うと +云 +う +相 +だ +と +迷亭 +は +妙 +な +事 +ばかり +云 +う +ところへ +妻君 +が +奥 +の +間 +から +出 +て +来 +て +女 +だけに +あんまり +悪口 +をおっしゃると +また +車屋 +の +神 +さんにいつけられますよ +と +注意 +する +少 +しいつける +方 +が +薬 +ですよ +奥 +さん +しかし +顔 +の +讒訴 +などをなさるのは +あまり +下等 +ですわ +誰 +だって +好 +んであんな +鼻 +を +持 +ってる +訳 +でもありませんから +それに +相手 +が +婦人 +ですからね +あんまり +苛 +いわ +と +鼻子 +の +鼻 +を +弁護 +すると +同時 +に +自分 +の +容貌 +も +間接 +に +弁護 +しておく +何 +ひどいものか +あんなのは +婦人 +じゃない +愚人 +だ +ねえ +迷亭君 +愚人 +かも +知 +れんが +なかなかえら +者 +だ +大分引 +き +掻 +かれたじゃないか +全体教師 +を +何 +と +心得 +ているんだろう +裏 +の +車屋 +くらいに +心得 +ているのさ +ああ +云 +う +人物 +に +尊敬 +されるには +博士 +になるに +限 +るよ +一体博士 +になっておかんのが +君 +の +不了見 +さ +ねえ +奥 +さん +そうでしょう +と +迷亭 +は +笑 +いながら +細君 +を +顧 +みる +博士 +なんて +到底駄目 +ですよ +と +主人 +は +細君 +にまで +見離 +される +これでも +今 +になるかも +知 +れん +軽蔑 +するな +貴様 +なぞは +知 +るまいが +昔 +し +アイソクラチス +と +云 +う +人 +は +九十四歳 +で +大著述 +をした +ソフォクリス +が +傑作 +を +出 +して +天下 +を +驚 +かしたのは +ほとんど +百歳 +の +高齢 +だった +シモニジス +は +八十 +で +妙詩 +を +作 +った +おれだって +馬鹿馬鹿 +しいわ +あなたのような +胃病 +でそんなに +永 +く +生 +きられるものですか +と +細君 +はちゃんと +主人 +の +寿命 +を +予算 +している +失敬 +な +甘木 +さんへ +行 +って +聞 +いて +見 +ろ +元来御前 +がこんな +皺苦茶 +な +黒木綿 +の +羽織 +や +つぎだらけの +着物 +を +着 +せておくから +あんな +女 +に +馬鹿 +にされるんだ +あしたから +迷亭 +の +着 +ているような +奴 +を +着 +るから +出 +しておけ +出 +しておけって +あんな +立派 +な +御召 +はござんせんわ +金田 +の +奥 +さんが +迷亭 +さんに +叮嚀 +になったのは +伯父 +さんの +名前 +を +聞 +いてからですよ +着物 +の +咎 +じゃございません +と +細君 +うまく +責任 +を +逃 +がれる +主人 +は +伯父 +さんと +云 +う +言葉 +を +聞 +いて +急 +に +思 +い +出 +したように +君 +に +伯父 +があると +云 +う +事 +は +今日始 +めて +聞 +いた +今 +までついに +噂 +をした +事 +がないじゃないか +本当 +にあるのかい +と +迷亭 +に +聞 +く +迷亭 +は +待 +ってたと +云 +わぬばかりに +うんその +伯父 +さ +その +伯父 +が +馬鹿 +に +頑物 +でねえ +やはりその +十九世紀 +から +連綿 +と +今日 +まで +生 +き +延 +びているんだがね +と +主人夫婦 +を +半々 +に +見 +る +オホホホホホ +面白 +い +事 +ばかりおっしゃって +どこに +生 +きていらっしゃるんです +静岡 +に +生 +きてますがね +それがただ +生 +きてるんじゃ +無 +いです +頭 +にちょん +髷 +を +頂 +いて +生 +きてるんだから +恐縮 +しまさあ +帽子 +を +被 +れってえと +おれはこの +年 +になるが +まだ +帽子 +を +被 +るほど +寒 +さを +感 +じた +事 +はないと +威張 +ってるんです +寒 +いから +もっと +寝 +ていらっしゃいと +云 +うと +人間 +は +四時間寝 +れば +充分 +だ +四時間以上寝 +るのは +贅沢 +の +沙汰 +だって +朝暗 +いうちから +起 +きてくるんです +それでね +おれも +睡眠時間 +を +四時間 +に +縮 +めるには +永年修業 +をしたもんだ +若 +いうちはどうしても +眠 +たくていかなんだが +近頃 +に +至 +って +始 +めて +随処任意 +の +庶境 +に +入 +ってはなはだ +嬉 +しいと +自慢 +するんです +六十七 +になって +寝 +られなくなるなあ +当 +り +前 +でさあ +修業 +も +糸瓜 +も +入 +ったものじゃないのに +当人 +は +全 +く +克己 +の +力 +で +成功 +したと +思 +ってるんですからね +それで +外出 +する +時 +には +きっと +鉄扇 +をもって +出 +るんですがね +なににするんだい +何 +にするんだか +分 +らない +ただ +持 +って +出 +るんだね +まあ +ステッキ +の +代 +りくらいに +考 +えてるかも +知 +れんよ +ところがせんだって +妙 +な +事 +がありましてね +と +今度 +は +細君 +の +方 +へ +話 +しかける +へえ +と +細君 +が +差 +し +合 +のない +返事 +をする +此年 +の +春突然手紙 +を +寄 +こして +山高帽子 +と +フロックコ +ト +を +至急送 +れと +云 +うんです +ちょっと +驚 +ろいたから +郵便 +で +問 +い +返 +したところが +老人自身 +が +着 +ると +云 +う +返事 +が +来 +ました +二十三日 +に +静岡 +で +祝捷会 +があるからそれまでに +間 +に +合 +うように +至急調達 +しろと +云 +う +命令 +なんです +ところがおかしいのは +命令中 +にこうあるんです +帽子 +は +好 +い +加減 +な +大 +きさのを +買 +ってくれ +洋服 +も +寸法 +を +見計 +らって +大丸 +へ +注文 +してくれ +近頃 +は +大丸 +でも +洋服 +を +仕立 +てるのかい +なあに +先生 +白木屋 +と +間違 +えたんだあね +寸法 +を +見計 +ってくれたって +無理 +じゃないか +そこが +伯父 +の +伯父 +たるところさ +どうした +仕方 +がないから +見計 +らって +送 +ってやった +君 +も +乱暴 +だな +それで +間 +に +合 +ったのかい +まあ +どうにか +こうにかおっついたんだろう +国 +の +新聞 +を +見 +たら +当日牧山翁 +は +珍 +らしく +フロックコ +ト +にて +例 +の +鉄扇 +を +持 +ち +鉄扇 +だけは +離 +さなかったと +見 +えるね +うん +死 +んだら +棺 +の +中 +へ +鉄扇 +だけは +入 +れてやろうと +思 +っているよ +それでも +帽子 +も +洋服 +も +うまい +具合 +に +着 +られて +善 +かった +ところが +大間違 +さ +僕 +も +無事 +に +行 +ってありがたいと +思 +ってると +しばらくして +国 +から +小包 +が +届 +いたから +何 +か +礼 +でもくれた +事 +と +思 +って +開 +けて +見 +たら +例 +の +山高帽子 +さ +手紙 +が +添 +えてあってね +せっかく +御求 +め +被下候 +えども +少々大 +きく +候間 +帽子屋 +へ +御遣 +わしの +上 +御縮 +め +被下度候 +縮 +め +賃 +は +小為替 +にて +此方 +より +御送可申上候 +とあるのさ +なるほど +迂濶 +だな +と +主人 +は +己 +れより +迂濶 +なものの +天下 +にある +事 +を +発見 +して +大 +に +満足 +の +体 +に +見 +える +やがて +それから +どうした +と +聞 +く +どうするったって +仕方 +がないから +僕 +が +頂戴 +して +被 +っていらあ +あの +帽子 +かあ +と +主人 +がにやにや +笑 +う +その +方 +が +男爵 +でいらっしゃるんですか +と +細君 +が +不思議 +そうに +尋 +ねる +誰 +がです +その +鉄扇 +の +伯父 +さまが +なあに +漢学者 +でさあ +若 +い +時聖堂 +で +朱子学 +か +何 +かにこり +固 +まったものだから +電気灯 +の +下 +で +恭 +しくちょん +髷 +を +頂 +いているんです +仕方 +がありません +とやたらに +顋 +を +撫 +で +廻 +す +それでも +君 +は +さっきの +女 +に +牧山男爵 +と +云 +ったようだぜ +そうおっしゃいましたよ +私 +も +茶 +の +間 +で +聞 +いておりました +と +細君 +もこれだけは +主人 +の +意見 +に +同意 +する +そうでしたかな +アハハハハハ +と +迷亭 +は +訳 +もなく +笑 +う +そりゃ +嘘 +ですよ +僕 +に +男爵 +の +伯父 +がありゃ +今頃 +は +局長 +くらいになっていまさあ +と +平気 +なものである +何 +だか +変 +だと +思 +った +と +主人 +は +嬉 +しそうな +心配 +そうな +顔付 +をする +あらまあ +よく +真面目 +であんな +嘘 +が +付 +けますねえ +あなたもよっぽど +法螺 +が +御上手 +でいらっしゃる +事 +と +細君 +は +非常 +に +感心 +する +僕 +より +あの +女 +の +方 +が +上 +わ +手 +でさあ +あなただって +御負 +けなさる +気遣 +いはありません +しかし +奥 +さん +僕 +の +法螺 +は +単 +なる +法螺 +ですよ +あの +女 +のは +みんな +魂胆 +があって +曰 +く +付 +きの +嘘 +ですぜ +たちが +悪 +いです +猿智慧 +から +割 +り +出 +した +術数 +と +天来 +の +滑稽趣味 +と +混同 +されちゃ +コメディ +の +神様 +も +活眼 +の +士 +なきを +嘆 +ぜざるを +得 +ざる +訳 +に +立 +ち +至 +りますからな +主人 +は +俯目 +になって +どうだか +と +云 +う +妻君 +は +笑 +いながら +同 +じ +事 +ですわ +と +云 +う +吾輩 +は +今 +まで +向 +う +横丁 +へ +足 +を +踏 +み +込 +んだ +事 +はない +角屋敷 +の +金田 +とは +どんな +構 +えか +見 +た +事 +は +無論 +ない +聞 +いた +事 +さえ +今 +が +始 +めてである +主人 +の +家 +で +実業家 +が +話頭 +に +上 +った +事 +は +一返 +もないので +主人 +の +飯 +を +食 +う +吾輩 +までがこの +方面 +には +単 +に +無関係 +なるのみならず +はなはだ +冷淡 +であった +しかるに +先刻図 +らずも +鼻子 +の +訪問 +を +受 +けて +余所 +ながらその +談話 +を +拝聴 +し +その +令嬢 +の +艶美 +を +想像 +し +またその +富貴 +権勢 +を +思 +い +浮 +べて +見 +ると +猫 +ながら +安閑 +として +椽側 +に +寝転 +んでいられなくなった +しかのみならず +吾輩 +は +寒月君 +に +対 +してはなはだ +同情 +の +至 +りに +堪 +えん +先方 +では +博士 +の +奥 +さんやら +車屋 +の +神 +さんやら +二絃琴 +の +天璋院 +まで +買収 +して +知 +らぬ +間 +に +前歯 +の +欠 +けたのさえ +探偵 +しているのに +寒月君 +の +方 +ではただ +ニヤニヤ +して +羽織 +の +紐 +ばかり +気 +にしているのは +いかに +卒業 +したての +理学士 +にせよ +あまり +能 +がなさ +過 +ぎる +と +言 +って +ああ +云 +う +偉大 +な +鼻 +を +顔 +の +中 +に +安置 +している +女 +の +事 +だから +滅多 +な +者 +では +寄 +り +付 +ける +訳 +の +者 +ではない +こう +云 +う +事件 +に +関 +しては +主人 +はむしろ +無頓着 +でかつあまりに +銭 +がなさ +過 +ぎる +迷亭 +は +銭 +に +不自由 +はしないが +あんな +偶然童子 +だから +寒月 +に +援 +けを +与 +える +便宜 +は +尠 +かろう +して +見 +ると +可哀相 +なのは +首縊 +りの +力学 +を +演説 +する +先生 +ばかりとなる +吾輩 +でも +奮発 +して +敵城 +へ +乗 +り +込 +んでその +動静 +を +偵察 +してやらなくては +あまり +不公平 +である +吾輩 +は +猫 +だけれど +エピクテタス +を +読 +んで +机 +の +上 +へ +叩 +きつけるくらいな +学者 +の +家 +に +寄寓 +する +猫 +で +世間一般 +の +痴猫 +愚猫 +とは +少 +しく +撰 +を +殊 +にしている +この +冒険 +をあえてするくらいの +義侠心 +は +固 +より +尻尾 +の +先 +に +畳 +み +込 +んである +何 +も +寒月君 +に +恩 +になったと +云 +う +訳 +もないが +これはただに +個人 +のためにする +血気躁狂 +の +沙汰 +ではない +大 +きく +云 +えば +公平 +を +好 +み +中庸 +を +愛 +する +天意 +を +現実 +にする +天晴 +な +美挙 +だ +人 +の +許諾 +を +経 +ずして +吾妻橋事件 +などを +至 +る +処 +に +振 +り +廻 +わす +以上 +は +人 +の +軒下 +に +犬 +を +忍 +ばして +その +報道 +を +得々 +として +逢 +う +人 +に +吹聴 +する +以上 +は +車夫 +馬丁 +無頼漢 +ごろつき +書生 +日雇婆 +産婆 +妖婆 +按摩 +頓馬 +に +至 +るまでを +使用 +して +国家有用 +の +材 +に +煩 +を +及 +ぼして +顧 +みざる +以上 +は +猫 +にも +覚悟 +がある +幸 +い +天気 +も +好 +い +霜解 +は +少々閉口 +するが +道 +のためには +一命 +もすてる +足 +の +裏 +へ +泥 +が +着 +いて +椽側 +へ +梅 +の +花 +の +印 +を +押 +すくらいな +事 +は +ただ +御三 +の +迷惑 +にはなるか +知 +れんが +吾輩 +の +苦痛 +とは +申 +されない +翌日 +とも +云 +わずこれから +出掛 +けようと +勇猛精進 +の +大決心 +を +起 +して +台所 +まで +飛 +んで +出 +たが +待 +てよ +と +考 +えた +吾輩 +は +猫 +として +進化 +の +極度 +に +達 +しているのみならず +脳力 +の +発達 +においてはあえて +中学 +の +三年生 +に +劣 +らざるつもりであるが +悲 +しいかな +咽喉 +の +構造 +だけはどこまでも +猫 +なので +人間 +の +言語 +が +饒舌 +れない +よし +首尾 +よく +金田邸 +へ +忍 +び +込 +んで +充分敵 +の +情勢 +を +見届 +けたところで +肝心 +の +寒月君 +に +教 +えてやる +訳 +に +行 +かない +主人 +にも +迷亭先生 +にも +話 +せない +話 +せないとすれば +土中 +にある +金剛石 +の +日 +を +受 +けて +光 +らぬと +同 +じ +事 +で +せっかくの +智識 +も +無用 +の +長物 +となる +これは +愚 +だ +やめようかしらんと +上 +り +口 +で +佇 +んで +見 +た +しかし +一度思 +い +立 +った +事 +を +中途 +でやめるのは +白雨 +が +来 +るかと +待 +っている +時黒雲共隣国 +へ +通 +り +過 +ぎたように +何 +となく +残 +り +惜 +しい +それも +非 +がこっちにあれば +格別 +だが +いわゆる +正義 +のため +人道 +のためなら +たとい +無駄死 +をやるまでも +進 +むのが +義務 +を +知 +る +男児 +の +本懐 +であろう +無駄骨 +を +折 +り +無駄足 +を +汚 +すくらいは +猫 +として +適当 +のところである +猫 +と +生 +れた +因果 +で +寒月 +迷亭 +苦沙弥諸先生 +と +三寸 +の +舌頭 +に +相互 +の +思想 +を +交換 +する +技倆 +はないが +猫 +だけに +忍 +びの +術 +は +諸先生 +より +達者 +である +他人 +の +出来 +ぬ +事 +を +成就 +するのはそれ +自身 +において +愉快 +である +吾一箇 +でも +金田 +の +内幕 +を +知 +るのは +誰 +も +知 +らぬより +愉快 +である +人 +に +告 +げられんでも +人 +に +知 +られているなと +云 +う +自覚 +を +彼等 +に +与 +うるだけが +愉快 +である +こんなに +愉快 +が +続々出 +て +来 +ては +行 +かずにはいられない +やはり +行 +く +事 +に +致 +そう +向 +う +横町 +へ +来 +て +見 +ると +聞 +いた +通 +りの +西洋館 +が +角地面 +を +吾物顔 +に +占領 +している +この +主人 +もこの +西洋館 +のごとく +傲慢 +に +構 +えているんだろうと +門 +を +這入 +ってその +建築 +を +眺 +めて +見 +たがただ +人 +を +威圧 +しようと +二階作 +りが +無意味 +に +突 +っ +立 +っているほかに +何等 +の +能 +もない +構造 +であった +迷亭 +のいわゆる +月並 +とはこれであろうか +玄関 +を +右 +に +見 +て +植込 +の +中 +を +通 +り +抜 +けて +勝手口 +へ +廻 +る +さすがに +勝手 +は +広 +い +苦沙弥先生 +の +台所 +の +十倍 +はたしかにある +せんだって +日本新聞 +に +詳 +しく +書 +いてあった +大隈伯 +の +勝手 +にも +劣 +るまいと +思 +うくらい +整然 +とぴかぴかしている +模範勝手 +だな +と +這入 +り +込 +む +見 +ると +漆喰 +で +叩 +き +上 +げた +二坪 +ほどの +土間 +に +例 +の +車屋 +の +神 +さんが +立 +ちながら +御飯焚 +きと +車夫 +を +相手 +にしきりに +何 +か +弁 +じている +こいつは +剣呑 +だと +水桶 +の +裏 +へかくれる +あの +教師 +あ +うちの +旦那 +の +名 +を +知 +らないのかね +と +飯焚 +が +云 +う +知 +らねえ +事 +があるもんか +この +界隈 +で +金田 +さんの +御屋敷 +を +知 +らなけりゃ +眼 +も +耳 +もねえ +片輪 +だあな +これは +抱 +え +車夫 +の +声 +である +なんとも +云 +えないよ +あの +教師 +と +来 +たら +本 +よりほかに +何 +にも +知 +らない +変人 +なんだからねえ +旦那 +の +事 +を +少 +しでも +知 +ってりゃ +恐 +れるかも +知 +れないが +駄目 +だよ +自分 +の +小供 +の +歳 +さえ +知 +らないんだもの +と +神 +さんが +云 +う +金田 +さんでも +恐 +れねえかな +厄介 +な +唐変木 +だ +構 +あ +事 +あねえ +みんなで +威嚇 +かしてやろうじゃねえか +それが +好 +いよ +奥様 +の +鼻 +が +大 +き +過 +ぎるの +顔 +が +気 +に +喰 +わないのって +そりゃあ +酷 +い +事 +を +云 +うんだよ +自分 +の +面 +あ +今戸焼 +の +狸見 +たような +癖 +に +あれで +一人前 +だと +思 +っているんだからやれ +切 +れないじゃないか +顔 +ばかりじゃない +手拭 +を +提 +げて +湯 +に +行 +くところからして +いやに +高慢 +ちきじゃないか +自分 +くらいえらい +者 +は +無 +いつもりでいるんだよ +と +苦沙弥先生 +は +飯焚 +にも +大 +に +不人望 +である +何 +でも +大勢 +であいつの +垣根 +の +傍 +へ +行 +って +悪口 +をさんざんいってやるんだね +そうしたらきっと +恐 +れ +入 +るよ +しかしこっちの +姿 +を +見 +せちゃあ +面白 +くねえから +声 +だけ +聞 +かして +勉強 +の +邪魔 +をした +上 +に +出来 +るだけじらしてやれって +さっき +奥様 +が +言 +い +付 +けておいでなすったぜ +そりゃ +分 +っているよ +と +神 +さんは +悪口 +の +三分 +の +一 +を +引 +き +受 +けると +云 +う +意味 +を +示 +す +なるほどこの +手合 +が +苦沙弥先生 +を +冷 +やかしに +来 +るなと +三人 +の +横 +を +そっと +通 +り +抜 +けて +奥 +へ +這入 +る +猫 +の +足 +はあれども +無 +きがごとし +どこを +歩 +いても +不器用 +な +音 +のした +試 +しがない +空 +を +踏 +むがごとく +雲 +を +行 +くがごとく +水中 +に +磬 +を +打 +つがごとく +洞裏 +に +瑟 +を +鼓 +するがごとく +醍醐 +の +妙味 +を +甞 +めて +言詮 +のほかに +冷暖 +を +自知 +するがごとし +月並 +な +西洋館 +もなく +模範勝手 +もなく +車屋 +の +神 +さんも +権助 +も +飯焚 +も +御嬢 +さまも +仲働 +きも +鼻子夫人 +も +夫人 +の +旦那様 +もない +行 +きたいところへ +行 +って +聞 +きたい +話 +を +聞 +いて +舌 +を +出 +し +尻尾 +を +掉 +って +髭 +をぴんと +立 +てて +悠々 +と +帰 +るのみである +ことに +吾輩 +はこの +道 +に +掛 +けては +日本一 +の +堪能 +である +草双紙 +にある +猫又 +の +血脈 +を +受 +けておりはせぬかと +自 +ら +疑 +うくらいである +蟇 +の +額 +には +夜光 +の +明珠 +があると +云 +うが +吾輩 +の +尻尾 +には +神祇釈教恋無常 +は +無論 +の +事 +満天下 +の +人間 +を +馬鹿 +にする +一家相伝 +の +妙薬 +が +詰 +め +込 +んである +金田家 +の +廊下 +を +人 +の +知 +らぬ +間 +に +横行 +するくらいは +仁王様 +が +心太 +を +踏 +み +潰 +すよりも +容易 +である +この +時吾輩 +は +我 +ながら +わが +力量 +に +感服 +して +これも +普段大事 +にする +尻尾 +の +御蔭 +だなと +気 +が +付 +いて +見 +るとただ +置 +かれない +吾輩 +の +尊敬 +する +尻尾大明神 +を +礼拝 +して +ニャン +運長久 +を +祈 +らばやと +ちょっと +低頭 +して +見 +たが +どうも +少 +し +見当 +が +違 +うようである +なるべく +尻尾 +の +方 +を +見 +て +三拝 +しなければならん +尻尾 +の +方 +を +見 +ようと +身体 +を +廻 +すと +尻尾 +も +自然 +と +廻 +る +追付 +こうと +思 +って +首 +をねじると +尻尾 +も +同 +じ +間隔 +をとって +先 +へ +馳 +け +出 +す +なるほど +天地玄黄 +を +三寸裏 +に +収 +めるほどの +霊物 +だけあって +到底吾輩 +の +手 +に +合 +わない +尻尾 +を +環 +る +事七度 +び +半 +にして +草臥 +れたからやめにした +少々眼 +がくらむ +どこにいるのだかちょっと +方角 +が +分 +らなくなる +構 +うものかと +滅茶苦茶 +にあるき +廻 +る +障子 +の +裏 +で +鼻子 +の +声 +がする +ここだと +立 +ち +留 +まって +左右 +の +耳 +をはすに +切 +って +息 +を +凝 +らす +貧乏教師 +の +癖 +に +生意気 +じゃありませんか +と +例 +の +金切 +り +声 +を +振 +り +立 +てる +うん +生意気 +な +奴 +だ +ちと +懲 +らしめのためにいじめてやろう +あの +学校 +にゃ +国 +のものもいるからな +誰 +がいるの +津木 +ピン +助 +や +福地 +キシャゴ +がいるから +頼 +んでからかわしてやろう +吾輩 +は +金田君 +の +生国 +は +分 +らんが +妙 +な +名前 +の +人間 +ばかり +揃 +った +所 +だと +少々驚 +いた +金田君 +はなお +語 +をついで +あいつは +英語 +の +教師 +かい +と +聞 +く +はあ +車屋 +の +神 +さんの +話 +では +英語 +の +リ +ドル +か +何 +か +専門 +に +教 +えるんだって +云 +います +どうせ +碌 +な +教師 +じゃあるめえ +あるめえにも +尠 +なからず +感心 +した +この +間 +ピン +助 +に +遇 +ったら +私 +の +学校 +にゃ +妙 +な +奴 +がおります +生徒 +から +先生番茶 +は +英語 +で +何 +と +云 +いますと +聞 +かれて +番茶 +は +であると +真面目 +に +答 +えたんで +教員間 +の +物笑 +いとなっています +どうもあんな +教員 +があるから +ほかのものの +迷惑 +になって +困 +りますと +云 +ったが +大方 +あいつの +事 +だぜ +あいつに +極 +っていまさあ +そんな +事 +を +云 +いそうな +面構 +えですよ +いやに +髭 +なんか +生 +やして +怪 +しからん +奴 +だ +髭 +を +生 +やして +怪 +しからなければ +猫 +などは +一疋 +だって +怪 +しかりようがない +それにあの +迷亭 +とか +へべれけとか +云 +う +奴 +は +まあ +何 +てえ +頓狂 +な +跳返 +りなんでしょう +伯父 +の +牧山男爵 +だなんて +あんな +顔 +に +男爵 +の +伯父 +なんざ +有 +るはずがないと +思 +ったんですもの +御前 +がどこの +馬 +の +骨 +だか +分 +らんものの +言 +う +事 +を +真 +に +受 +けるのも +悪 +い +悪 +いって +あんまり +人 +を +馬鹿 +にし +過 +ぎるじゃありませんか +と +大変残念 +そうである +不思議 +な +事 +には +寒月君 +の +事 +は +一言半句 +も +出 +ない +吾輩 +の +忍 +んで +来 +る +前 +に +評判記 +はすんだものか +またはすでに +落第 +と +事 +が +極 +って +念頭 +にないものか +その +辺 +は +懸念 +もあるが +仕方 +がない +しばらく +佇 +んでいると +廊下 +を +隔 +てて +向 +うの +座敷 +で +ベル +の +音 +がする +そらあすこにも +何 +か +事 +がある +後 +れぬ +先 +に +とその +方角 +へ +歩 +を +向 +ける +来 +て +見 +ると +女 +が +独 +りで +何 +か +大声 +で +話 +している +その +声 +が +鼻子 +とよく +似 +ているところをもって +推 +すと +これが +即 +ち +当家 +の +令嬢寒月君 +をして +未遂入水 +をあえてせしめたる +代物 +だろう +惜哉障子越 +しで +玉 +の +御姿 +を +拝 +する +事 +が +出来 +ない +従 +って +顔 +の +真中 +に +大 +きな +鼻 +を +祭 +り +込 +んでいるか +どうだか +受合 +えない +しかし +談話 +の +模様 +から +鼻息 +の +荒 +いところなどを +綜合 +して +考 +えて +見 +ると +満更人 +の +注意 +を +惹 +かぬ +獅鼻 +とも +思 +われない +女 +はしきりに +喋舌 +っているが +相手 +の +声 +が +少 +しも +聞 +えないのは +噂 +にきく +電話 +というものであろう +御前 +は +大和 +かい +明日 +ね +行 +くんだからね +鶉 +の +三 +を +取 +っておいておくれ +いいかえ +分 +ったかい +なに +分 +らない +おやいやだ +鶉 +の +三 +を +取 +るんだよ +なんだって +取 +れない +取 +れないはずはない +とるんだよ +へへへへへ +御冗談 +をだって +何 +が +御冗談 +なんだよ +いやに +人 +をおひゃらかすよ +全体御前 +は +誰 +だい +長吉 +だ +長吉 +なんぞじゃ +訳 +が +分 +らない +お +神 +さんに +電話口 +へ +出 +ろって +御云 +いな +なに +私 +しで +何 +でも +弁 +じます +お +前 +は +失敬 +だよ +妾 +しを +誰 +だか +知 +ってるのかい +金田 +だよ +へへへへへ +善 +く +存 +じておりますだって +ほんとに +馬鹿 +だよこの +人 +あ +金田 +だってえばさ +なに +毎度御贔屓 +にあずかりましてありがとうございます +何 +がありがたいんだね +御礼 +なんか +聞 +きたかあないやね +おやまた +笑 +ってるよ +お +前 +はよっぽど +愚物 +だね +仰 +せの +通 +りだって +あんまり +人 +を +馬鹿 +にすると +電話 +を +切 +ってしまうよ +いいのかい +困 +らないのかよ +黙 +ってちゃ +分 +らないじゃないか +何 +とか +御云 +いなさいな +電話 +は +長吉 +の +方 +から +切 +ったものか +何 +の +返事 +もないらしい +令嬢 +は +癇癪 +を +起 +してやけに +ベル +を +ジャラジャラ +と +廻 +す +足元 +で +狆 +が +驚 +ろいて +急 +に +吠 +え +出 +す +これは +迂濶 +に +出来 +ないと +急 +に +飛 +び +下 +りて +椽 +の +下 +へもぐり +込 +む +折柄廊下 +を +近 +く +足音 +がして +障子 +を +開 +ける +音 +がする +誰 +か +来 +たなと +一生懸命 +に +聞 +いていると +御嬢様 +旦那様 +と +奥様 +が +呼 +んでいらっしゃいます +と +小間使 +らしい +声 +がする +知 +らないよ +と +令嬢 +は +剣突 +を +食 +わせる +ちょっと +用 +があるから +嬢 +を +呼 +んで +来 +いとおっしゃいました +うるさいね +知 +らないてば +と +令嬢 +は +第二 +の +剣突 +を +食 +わせる +水島寒月 +さんの +事 +で +御用 +があるんだそうでございます +と +小間使 +は +気 +を +利 +かして +機嫌 +を +直 +そうとする +寒月 +でも +水月 +でも +知 +らないんだよ +大嫌 +いだわ +糸瓜 +が +戸迷 +いをしたような +顔 +をして +第三 +の +剣突 +は +憐 +れなる +寒月君 +が +留守中 +に +頂戴 +する +おや +御前 +いつ +束髪 +に +結 +ったの +小間使 +はほっと +一息 +ついて +今日 +となるべく +単簡 +な +挨拶 +をする +生意気 +だねえ +小間使 +の +癖 +に +と +第四 +の +剣突 +を +別方面 +から +食 +わす +そうして +新 +しい +半襟 +を +掛 +けたじゃないか +へえ +せんだって +御嬢様 +からいただきましたので +結構過 +ぎて +勿体 +ないと +思 +って +行李 +の +中 +へしまっておきましたが +今 +までのがあまり +汚 +れましたからかけ +易 +えました +いつ +そんなものを +上 +げた +事 +があるの +この +御正月 +白木屋 +へいらっしゃいまして +御求 +め +遊 +ばしたので +鶯茶 +へ +相撲 +の +番附 +を +染 +め +出 +したのでございます +妾 +しには +地味過 +ぎていやだから +御前 +に +上 +げようとおっしゃった +あれでございます +あらいやだ +善 +く +似合 +うのね +にくらしいわ +恐 +れ +入 +ります +褒 +めたんじゃない +にくらしいんだよ +へえ +そんなによく +似合 +うものをなぜだまって +貰 +ったんだい +へえ +御前 +にさえ +そのくらい +似合 +うなら +妾 +しにだっておかしい +事 +あないだろうじゃないか +きっとよく +御似合 +い +遊 +ばします +似 +あうのが +分 +ってる +癖 +になぜ +黙 +っているんだい +そうしてすまして +掛 +けているんだよ +人 +の +悪 +い +剣突 +は +留 +めどもなく +連発 +される +このさき +事局 +はどう +発展 +するかと +謹聴 +している +時 +向 +うの +座敷 +で +富子 +や +富子 +や +と +大 +きな +声 +で +金田君 +が +令嬢 +を +呼 +ぶ +令嬢 +はやむを +得 +ず +はい +と +電話室 +を +出 +て +行 +く +吾輩 +より +少 +し +大 +きな +狆 +が +顔 +の +中心 +に +眼 +と +口 +を +引 +き +集 +めたような +面 +をして +付 +いて +行 +く +吾輩 +は +例 +の +忍 +び +足 +で +再 +び +勝手 +から +往来 +へ +出 +て +急 +いで +主人 +の +家 +に +帰 +る +探険 +はまず +十二分 +の +成績 +である +帰 +って +見 +ると +奇麗 +な +家 +から +急 +に +汚 +ない +所 +へ +移 +ったので +何 +だか +日当 +りの +善 +い +山 +の +上 +から +薄黒 +い +洞窟 +の +中 +へ +入 +り +込 +んだような +心持 +ちがする +探険中 +は +ほかの +事 +に +気 +を +奪 +われて +部屋 +の +装飾 +襖 +障子 +の +具合 +などには +眼 +も +留 +らなかったが +わが +住居 +の +下等 +なるを +感 +ずると +同時 +に +彼 +のいわゆる +月並 +が +恋 +しくなる +教師 +よりもやはり +実業家 +がえらいように +思 +われる +吾輩 +も +少 +し +変 +だと +思 +って +例 +の +尻尾 +に +伺 +いを +立 +てて +見 +たら +その +通 +りその +通 +りと +尻尾 +の +先 +から +御託宣 +があった +座敷 +へ +這入 +って +見 +ると +驚 +いたのは +迷亭先生 +まだ +帰 +らない +巻煙草 +の +吸 +い +殻 +を +蜂 +の +巣 +のごとく +火鉢 +の +中 +へ +突 +き +立 +てて +大胡坐 +で +何 +か +話 +し +立 +てている +いつの +間 +にか +寒月君 +さえ +来 +ている +主人 +は +手枕 +をして +天井 +の +雨洩 +を +余念 +もなく +眺 +めている +あいかわらず +太平 +の +逸民 +の +会合 +である +寒月君 +君 +の +事 +を +譫語 +にまで +言 +った +婦人 +の +名 +は +当時秘密 +であったようだが +もう +話 +しても +善 +かろう +と +迷亭 +がからかい +出 +す +御話 +しをしても +私 +だけに +関 +する +事 +なら +差支 +えないんですが +先方 +の +迷惑 +になる +事 +ですから +まだ +駄目 +かなあ +それに +博士夫人 +に +約束 +をしてしまったもんですから +他言 +をしないと +云 +う +約束 +かね +ええ +と +寒月君 +は +例 +のごとく +羽織 +の +紐 +をひねくる +その +紐 +は +売品 +にあるまじき +紫色 +である +その +紐 +の +色 +は +ちと +天保調 +だな +と +主人 +が +寝 +ながら +云 +う +主人 +は +金田事件 +などには +無頓着 +である +そうさ +到底日露戦争時代 +のものではないな +陣笠 +に +立葵 +の +紋 +の +付 +いたぶっ +割 +き +羽織 +でも +着 +なくっちゃ +納 +まりの +付 +かない +紐 +だ +織田信長 +が +聟入 +をするとき +頭 +の +髪 +を +茶筌 +に +結 +ったと +云 +うがその +節用 +いたのは +たしかそんな +紐 +だよ +と +迷亭 +の +文句 +はあいかわらず +長 +い +実際 +これは +爺 +が +長州征伐 +の +時 +に +用 +いたのです +と +寒月君 +は +真面目 +である +もういい +加減 +に +博物館 +へでも +献納 +してはどうだ +首縊 +りの +力学 +の +演者 +理学士水島寒月君 +ともあろうものが +売 +れ +残 +りの +旗本 +のような +出 +で +立 +をするのはちと +体面 +に +関 +する +訳 +だから +御忠告 +の +通 +りに +致 +してもいいのですが +この +紐 +が +大変 +よく +似合 +うと +云 +ってくれる +人 +もありますので +誰 +だい +そんな +趣味 +のない +事 +を +云 +うのは +と +主人 +は +寝返 +りを +打 +ちながら +大 +きな +声 +を +出 +す +それは +御存 +じの +方 +なんじゃないんで +御存 +じでなくてもいいや +一体誰 +だい +去 +る +女性 +なんです +ハハハハハ +よほど +茶人 +だなあ +当 +てて +見 +ようか +やはり +隅田川 +の +底 +から +君 +の +名 +を +呼 +んだ +女 +なんだろう +その +羽織 +を +着 +てもう +一返御駄仏 +を +極 +め +込 +んじゃどうだい +と +迷亭 +が +横合 +から +飛 +び +出 +す +へへへへへもう +水底 +から +呼 +んではおりません +ここから +乾 +の +方角 +にあたる +清浄 +な +世界 +で +あんまり +清浄 +でもなさそうだ +毒々 +しい +鼻 +だぜ +へえ +と +寒月 +は +不審 +な +顔 +をする +向 +う +横丁 +の +鼻 +がさっき +押 +しかけて +来 +たんだよ +ここへ +実 +に +僕等二人 +は +驚 +いたよ +ねえ +苦沙弥君 +うむ +と +主人 +は +寝 +ながら +茶 +を +飲 +む +鼻 +って +誰 +の +事 +です +君 +の +親愛 +なる +久遠 +の +女性 +の +御母堂様 +だ +へえ +金田 +の +妻 +という +女 +が +君 +の +事 +を +聞 +きに +来 +たよ +と +主人 +が +真面目 +に +説明 +してやる +驚 +くか +嬉 +しがるか +恥 +ずかしがるかと +寒月君 +の +様子 +を +窺 +って +見 +ると +別段 +の +事 +もない +例 +の +通 +り +静 +かな +調子 +で +どうか +私 +に +あの +娘 +を +貰 +ってくれと +云 +う +依頼 +なんでしょう +と +また +紫 +の +紐 +をひねくる +ところが +大違 +さ +その +御母堂 +なるものが +偉大 +なる +鼻 +の +所有主 +でね +迷亭 +が +半 +ば +言 +い +懸 +けると +主人 +が +おい +君 +僕 +はさっきから +あの +鼻 +について +俳体詩 +を +考 +えているんだがね +と +木 +に +竹 +を +接 +いだような +事 +を +云 +う +隣 +の +室 +で +妻君 +がくすくす +笑 +い +出 +す +随分君 +も +呑気 +だなあ +出来 +たのかい +少 +し +出来 +た +第一句 +がこの +顔 +に +鼻祭 +りと +云 +うのだ +それから +次 +がこの +鼻 +に +神酒供 +えというのさ +次 +の +句 +は +まだそれぎりしか +出来 +ておらん +面白 +いですな +と +寒月君 +がにやにや +笑 +う +次 +へ +穴二 +つ +幽 +かなりと +付 +けちゃどうだ +と +迷亭 +はすぐ +出来 +る +すると +寒月 +が +奥深 +く +毛 +も +見 +えずはいけますまいか +と +各々出鱈目 +を +並 +べていると +垣根 +に +近 +く +往来 +で +今戸焼 +の +狸今戸焼 +の +狸 +と +四五人 +わいわい +云 +う +声 +がする +主人 +も +迷亭 +もちょっと +驚 +ろいて +表 +の +方 +を +垣 +の +隙 +からすかして +見 +ると +ワハハハハハ +と +笑 +う +声 +がして +遠 +くへ +散 +る +足 +の +音 +がする +今戸焼 +の +狸 +というな +何 +だい +と +迷亭 +が +不思議 +そうに +主人 +に +聞 +く +何 +だか +分 +らん +と +主人 +が +答 +える +なかなか +振 +っていますな +と +寒月君 +が +批評 +を +加 +える +迷亭 +は +何 +を +思 +い +出 +したか +急 +に +立 +ち +上 +って +吾輩 +は +年来美学上 +の +見地 +からこの +鼻 +について +研究 +した +事 +がございますから +その +一斑 +を +披瀝 +して +御両君 +の +清聴 +を +煩 +わしたいと +思 +います +と +演舌 +の +真似 +をやる +主人 +はあまりの +突然 +にぼんやりして +無言 +のまま +迷亭 +を +見 +ている +寒月 +は +是非承 +りたいものです +と +小声 +で +云 +う +いろいろ +調 +べて +見 +ましたが +鼻 +の +起源 +はどうも +確 +と +分 +りません +第一 +の +不審 +は +もしこれを +実用上 +の +道具 +と +仮定 +すれば +穴 +が +二 +つでたくさんである +何 +もこんなに +横風 +に +真中 +から +突 +き +出 +して +見 +る +必用 +がないのである +ところがどうしてだんだん +御覧 +のごとく +斯様 +にせり +出 +して +参 +ったか +と +自分 +の +鼻 +を +抓 +んで +見 +せる +あんまりせり +出 +してもおらんじゃないか +と +主人 +は +御世辞 +のないところを +云 +う +とにかく +引 +っ +込 +んではおりませんからな +ただ +二個 +の +孔 +が +併 +んでいる +状体 +と +混同 +なすっては +誤解 +を +生 +ずるに +至 +るかも +計 +られませんから +予 +め +御注意 +をしておきます +で +愚見 +によりますと +鼻 +の +発達 +は +吾々人間 +が +鼻汁 +をかむと +申 +す +微細 +なる +行為 +の +結果 +が +自然 +と +蓄積 +してかく +著明 +なる +現象 +を +呈出 +したものでございます +佯 +りのない +愚見 +だ +とまた +主人 +が +寸評 +を +挿入 +する +御承知 +の +通 +り +鼻汁 +をかむ +時 +は +是非鼻 +を +抓 +みます +鼻 +を +抓 +んで +ことにこの +局部 +だけに +刺激 +を +与 +えますと +進化論 +の +大原則 +によって +この +局部 +はこの +刺激 +に +応 +ずるがため +他 +に +比例 +して +不相当 +な +発達 +を +致 +します +皮 +も +自然堅 +くなります +肉 +も +次第 +に +硬 +くなります +ついに +凝 +って +骨 +となります +それは +少 +し +そう +自由 +に +肉 +が +骨 +に +一足飛 +に +変化 +は +出来 +ますまい +と +理学士 +だけあって +寒月君 +が +抗議 +を +申 +し +込 +む +迷亭 +は +何喰 +わぬ +顔 +で +陳 +べ +続 +ける +いや +御不審 +はごもっともですが +論 +より +証拠 +この +通 +り +骨 +があるから +仕方 +がありません +すでに +骨 +が +出来 +る +骨 +は +出来 +ても +鼻汁 +は +出 +ますな +出 +ればかまずにはいられません +この +作用 +で +骨 +の +左右 +が +削 +り +取 +られて +細 +い +高 +い +隆起 +と +変化 +して +参 +ります +実 +に +恐 +ろしい +作用 +です +点滴 +の +石 +を +穿 +つがごとく +賓頭顱 +の +頭 +が +自 +から +光明 +を +放 +つがごとく +不思議薫不思議臭 +の +喩 +のごとく +斯様 +に +鼻筋 +が +通 +って +堅 +くなります +それでも +君 +のなんぞ +ぶくぶくだぜ +演者自身 +の +局部 +は +回護 +の +恐 +れがありますから +わざと +論 +じません +かの +金田 +の +御母堂 +の +持 +たせらるる +鼻 +のごときは +もっとも +発達 +せるもっとも +偉大 +なる +天下 +の +珍品 +として +御両君 +に +紹介 +しておきたいと +思 +います +寒月君 +は +思 +わず +ヒヤヤヤ +と +云 +う +しかし +物 +も +極度 +に +達 +しますと +偉観 +には +相違 +ございませんが +何 +となく +怖 +しくて +近 +づき +難 +いものであります +あの +鼻梁 +などは +素晴 +しいには +違 +いございませんが +少々峻嶮過 +ぎるかと +思 +われます +古人 +のうちにても +ソクラチス +ゴ +ルドスミス +もしくは +サッカレ +の +鼻 +などは +構造 +の +上 +から +云 +うと +随分申 +し +分 +はございましょうがその +申 +し +分 +のあるところに +愛嬌 +がございます +鼻高 +きが +故 +に +貴 +からず +奇 +なるがために +貴 +しとはこの +故 +でもございましょうか +下世話 +にも +鼻 +より +団子 +と +申 +しますれば +美的価値 +から +申 +しますとまず +迷亭 +くらいのところが +適当 +かと +存 +じます +寒月 +と +主人 +は +フフフフ +と +笑 +い +出 +す +迷亭自身 +も +愉快 +そうに +笑 +う +さてただ +今 +まで +弁 +じましたのは +先生弁 +じましたは +少 +し +講釈師 +のようで +下品 +ですから +よしていただきましょう +と +寒月君 +は +先日 +の +復讐 +をやる +さようしからば +顔 +を +洗 +って +出直 +しましょうかな +ええ +これから +鼻 +と +顔 +の +権衡 +に +一言論及 +したいと +思 +います +他 +に +関係 +なく +単独 +に +鼻論 +をやりますと +かの +御母堂 +などはどこへ +出 +しても +恥 +ずかしからぬ +鼻 +鞍馬山 +で +展覧会 +があっても +恐 +らく +一等賞 +だろうと +思 +われるくらいな +鼻 +を +所有 +していらせられますが +悲 +しいかなあれは +眼 +口 +その +他 +の +諸先生 +と +何等 +の +相談 +もなく +出来上 +った +鼻 +であります +ジュリアス +シ +ザ +の +鼻 +は +大 +したものに +相違 +ございません +しかし +シ +ザ +の +鼻 +を +鋏 +でちょん +切 +って +当家 +の +猫 +の +顔 +へ +安置 +したらどんな +者 +でございましょうか +喩 +えにも +猫 +の +額 +と +云 +うくらいな +地面 +へ +英雄 +の +鼻柱 +が +突兀 +として +聳 +えたら +碁盤 +の +上 +へ +奈良 +の +大仏 +を +据 +え +付 +けたようなもので +少 +しく +比例 +を +失 +するの +極 +その +美的価値 +を +落 +す +事 +だろうと +思 +います +御母堂 +の +鼻 +は +シ +ザ +のそれのごとく +正 +しく +英姿颯爽 +たる +隆起 +に +相違 +ございません +しかしその +周囲 +を +囲繞 +する +顔面的条件 +は +如何 +な +者 +でありましょう +無論当家 +の +猫 +のごとく +劣等 +ではない +しかし +癲癇病 +みの +御 +かめのごとく +眉 +の +根 +に +八字 +を +刻 +んで +細 +い +眼 +を +釣 +るし +上 +げらるるのは +事実 +であります +諸君 +この +顔 +にしてこの +鼻 +ありと +嘆 +ぜざるを +得 +んではありませんか +迷亭 +の +言葉 +が +少 +し +途切 +れる +途端 +裏 +の +方 +で +まだ +鼻 +の +話 +しをしているんだよ +何 +てえ +剛突 +く +張 +だろう +と +云 +う +声 +が +聞 +える +車屋 +の +神 +さんだ +と +主人 +が +迷亭 +に +教 +えてやる +迷亭 +はまたやり +初 +める +計 +らざる +裏手 +にあたって +新 +たに +異性 +の +傍聴者 +のある +事 +を +発見 +したのは +演者 +の +深 +く +名誉 +と +思 +うところであります +ことに +宛転 +たる +嬌音 +をもって +乾燥 +なる +講筵 +に +一点 +の +艶味 +を +添 +えられたのは +実 +に +望外 +の +幸福 +であります +なるべく +通俗的 +に +引 +き +直 +して +佳人淑女 +の +眷顧 +に +背 +かざらん +事 +を +期 +する +訳 +でありますが +これからは +少々力学上 +の +問題 +に +立 +ち +入 +りますので +勢御婦人方 +には +御分 +りにくいかも +知 +れません +どうか +御辛防 +を +願 +います +寒月君 +は +力学 +と +云 +う +語 +を +聞 +いてまたにやにやする +私 +の +証拠立 +てようとするのは +この +鼻 +とこの +顔 +は +到底調和 +しない +ツァイシング +の +黄金律 +を +失 +していると +云 +う +事 +なんで +それを +厳格 +に +力学上 +の +公式 +から +演繹 +して +御覧 +に +入 +れようと +云 +うのであります +まず +を +鼻 +の +高 +さとします +は +鼻 +と +顔 +の +平面 +の +交叉 +より +生 +ずる +角度 +であります +は +無論鼻 +の +重量 +と +御承知下 +さい +どうです +大抵 +お +分 +りになりましたか +分 +るものか +と +主人 +が +云 +う +寒月君 +はどうだい +私 +にもちと +分 +りかねますな +そりゃ +困 +ったな +苦沙弥 +はとにかく +君 +は +理学士 +だから +分 +るだろうと +思 +ったのに +この +式 +が +演説 +の +首脳 +なんだからこれを +略 +しては +今 +までやった +甲斐 +がないのだが +まあ +仕方 +がない +公式 +は +略 +して +結論 +だけ +話 +そう +結論 +があるか +と +主人 +が +不思議 +そうに +聞 +く +当 +り +前 +さ +結論 +のない +演舌 +は +デザ +ト +のない +西洋料理 +のようなものだ +いいか +両君能 +く +聞 +き +給 +え +これからが +結論 +だぜ +さて +以上 +の +公式 +に +ウィルヒョウ +ワイスマン +諸家 +の +説 +を +参酌 +して +考 +えて +見 +ますと +先天的形体 +の +遺伝 +は +無論 +の +事許 +さねばなりません +またこの +形体 +に +追陪 +して +起 +る +心意的状況 +は +たとい +後天性 +は +遺伝 +するものにあらずとの +有力 +なる +説 +あるにも +関 +せず +ある +程度 +までは +必然 +の +結果 +と +認 +めねばなりません +従 +ってかくのごとく +身分 +に +不似合 +なる +鼻 +の +持主 +の +生 +んだ +子 +には +その +鼻 +にも +何 +か +異状 +がある +事 +と +察 +せられます +寒月君 +などは +まだ +年 +が +御若 +いから +金田令嬢 +の +鼻 +の +構造 +において +特別 +の +異状 +を +認 +められんかも +知 +れませんが +かかる +遺伝 +は +潜伏期 +の +長 +いものでありますから +いつ +何時気候 +の +劇変 +と +共 +に +急 +に +発達 +して +御母堂 +のそれのごとく +咄嗟 +の +間 +に +膨脹 +するかも +知 +れません +それ +故 +にこの +御婚儀 +は +迷亭 +の +学理的論証 +によりますと +今 +の +中御断念 +になった +方 +が +安全 +かと +思 +われます +これには +当家 +の +御主人 +は +無論 +の +事 +そこに +寝 +ておらるる +猫又殿 +にも +御異存 +は +無 +かろうと +存 +じます +主人 +はようよう +起 +き +返 +って +そりゃ +無論 +さ +あんなものの +娘 +を +誰 +が +貰 +うものか +寒月君 +もらっちゃいかんよ +と +大変熱心 +に +主張 +する +吾輩 +もいささか +賛成 +の +意 +を +表 +するためににゃ +にゃ +と +二声 +ばかり +鳴 +いて +見 +せる +寒月君 +は +別段騒 +いだ +様子 +もなく +先生方 +の +御意向 +がそうなら +私 +は +断念 +してもいいんですが +もし +当人 +がそれを +気 +にして +病気 +にでもなったら +罪 +ですから +ハハハハハ +艶罪 +と +云 +う +訳 +だ +主人 +だけは +大 +にむきになって +そんな +馬鹿 +があるものか +あいつの +娘 +なら +碌 +な +者 +でないに +極 +ってらあ +初 +めて +人 +のうちへ +来 +ておれをやり +込 +めに +掛 +った +奴 +だ +傲慢 +な +奴 +だ +と +独 +りでぷんぷんする +するとまた +垣根 +のそばで +三四人 +が +ワハハハハハ +と +云 +う +声 +がする +一人 +が +高慢 +ちきな +唐変木 +だ +と +云 +うと +一人 +が +もっと +大 +きな +家 +へ +這入 +りてえだろう +と +云 +う +また +一人 +が +御気 +の +毒 +だが +いくら +威張 +ったって +蔭弁慶 +だ +と +大 +きな +声 +をする +主人 +は +椽側 +へ +出 +て +負 +けないような +声 +で +やかましい +何 +だわざわざそんな +塀 +の +下 +へ +来 +て +と +怒鳴 +る +ワハハハハハサヴェジ +チ +だ +サヴェジ +チ +だ +と +口々 +に +罵 +しる +主人 +は +大 +に +逆鱗 +の +体 +で +突然起 +って +ステッキ +を +持 +って +往来 +へ +飛 +び +出 +す +迷亭 +は +手 +を +拍 +って +面白 +い +やれやれ +と +云 +う +寒月 +は +羽織 +の +紐 +を +撚 +ってにやにやする +吾輩 +は +主人 +のあとを +付 +けて +垣 +の +崩 +れから +往来 +へ +出 +て +見 +たら +真中 +に +主人 +が +手持無沙汰 +に +ステッキ +を +突 +いて +立 +っている +人通 +りは +一人 +もない +ちょっと +狐 +に +抓 +まれた +体 +である +四 +例 +によって +金田邸 +へ +忍 +び +込 +む +例 +によってとは +今更解釈 +する +必要 +もない +しばしばを +自乗 +したほどの +度合 +を +示 +す +語 +である +一度 +やった +事 +は +二度 +やりたいもので +二度試 +みた +事 +は +三度試 +みたいのは +人間 +にのみ +限 +らるる +好奇心 +ではない +猫 +といえどもこの +心理的特権 +を +有 +してこの +世界 +に +生 +れ +出 +でたものと +認定 +していただかねばならぬ +三度以上繰返 +す +時始 +めて +習慣 +なる +語 +を +冠 +せられて +この +行為 +が +生活上 +の +必要 +と +進化 +するのもまた +人間 +と +相違 +はない +何 +のために +かくまで +足繁 +く +金田邸 +へ +通 +うのかと +不審 +を +起 +すならその +前 +にちょっと +人間 +に +反問 +したい +事 +がある +なぜ +人間 +は +口 +から +煙 +を +吸 +い +込 +んで +鼻 +から +吐 +き +出 +すのであるか +腹 +の +足 +しにも +血 +の +道 +の +薬 +にもならないものを +恥 +かし +気 +もなく +吐呑 +して +憚 +からざる +以上 +は +吾輩 +が +金田 +に +出入 +するのを +あまり +大 +きな +声 +で +咎 +め +立 +てをして +貰 +いたくない +金田邸 +は +吾輩 +の +煙草 +である +忍 +び +込 +むと +云 +うと +語弊 +がある +何 +だか +泥棒 +か +間男 +のようで +聞 +き +苦 +しい +吾輩 +が +金田邸 +へ +行 +くのは +招待 +こそ +受 +けないが +決 +して +鰹 +の +切身 +をちょろまかしたり +眼鼻 +が +顔 +の +中心 +に +痙攣的 +に +密着 +している +狆君 +などと +密談 +するためではない +何探偵 +もってのほかの +事 +である +およそ +世 +の +中 +に +何 +が +賤 +しい +家業 +だと +云 +って +探偵 +と +高利貸 +ほど +下等 +な +職 +はないと +思 +っている +なるほど +寒月君 +のために +猫 +にあるまじきほどの +義侠心 +を +起 +して +一度 +は +金田家 +の +動静 +を +余所 +ながら +窺 +った +事 +はあるが +それはただの +一遍 +で +その +後 +は +決 +して +猫 +の +良心 +に +恥 +ずるような +陋劣 +な +振舞 +を +致 +した +事 +はない +そんなら +なぜ +忍 +び +込 +むと +云 +うような +胡乱 +な +文字 +を +使用 +した +さあ +それがすこぶる +意味 +のある +事 +だて +元来吾輩 +の +考 +によると +大空 +は +万物 +を +覆 +うため +大地 +は +万物 +を +載 +せるために +出来 +ている +いかに +執拗 +な +議論 +を +好 +む +人間 +でもこの +事実 +を +否定 +する +訳 +には +行 +くまい +さてこの +大空大地 +を +製造 +するために +彼等人類 +はどのくらいの +労力 +を +費 +やしているかと +云 +うと +尺寸 +の +手伝 +もしておらぬではないか +自分 +が +製造 +しておらぬものを +自分 +の +所有 +と +極 +める +法 +はなかろう +自分 +の +所有 +と +極 +めても +差 +し +支 +えないが +他 +の +出入 +を +禁 +ずる +理由 +はあるまい +この +茫々 +たる +大地 +を +小賢 +しくも +垣 +を +囲 +らし +棒杭 +を +立 +てて +某々所有地 +などと +劃 +し +限 +るのはあたかもかの +蒼天 +に +縄張 +して +この +部分 +は +我 +の +天 +あの +部分 +は +彼 +の +天 +と +届 +け +出 +るような +者 +だ +もし +土地 +を +切 +り +刻 +んで +一坪 +いくらの +所有権 +を +売買 +するなら +我等 +が +呼吸 +する +空気 +を +一尺立方 +に +割 +って +切売 +をしても +善 +い +訳 +である +空気 +の +切売 +が +出来 +ず +空 +の +縄張 +が +不当 +なら +地面 +の +私有 +も +不合理 +ではないか +如是観 +によりて +如是法 +を +信 +じている +吾輩 +はそれだからどこへでも +這入 +って +行 +く +もっとも +行 +きたくない +処 +へは +行 +かぬが +志 +す +方角 +へは +東西南北 +の +差別 +は +入 +らぬ +平気 +な +顔 +をして +のそのそと +参 +る +金田 +ごときものに +遠慮 +をする +訳 +がない +しかし +猫 +の +悲 +しさは +力 +ずくでは +到底人間 +には +叶 +わない +強勢 +は +権利 +なりとの +格言 +さえあるこの +浮世 +に +存在 +する +以上 +は +いかにこっちに +道理 +があっても +猫 +の +議論 +は +通 +らない +無理 +に +通 +そうとすると +車屋 +の +黒 +のごとく +不意 +に +肴屋 +の +天秤棒 +を +喰 +う +恐 +れがある +理 +はこっちにあるが +権力 +は +向 +うにあると +云 +う +場合 +に +理 +を +曲 +げて +一 +も +二 +もなく +屈従 +するか +または +権力 +の +目 +を +掠 +めて +我理 +を +貫 +くかと +云 +えば +吾輩 +は +無論後者 +を +択 +ぶのである +天秤棒 +は +避 +けざるべからざるが +故 +に +忍 +ばざるべからず +人 +の +邸内 +へは +這入 +り +込 +んで +差支 +えなき +故込 +まざるを +得 +ず +この +故 +に +吾輩 +は +金田邸 +へ +忍 +び +込 +むのである +忍 +び +込 +む +度 +が +重 +なるにつけ +探偵 +をする +気 +はないが +自然金田君一家 +の +事情 +が +見 +たくもない +吾輩 +の +眼 +に +映 +じて +覚 +えたくもない +吾輩 +の +脳裏 +に +印象 +を +留 +むるに +至 +るのはやむを +得 +ない +鼻子夫人 +が +顔 +を +洗 +うたんびに +念 +を +入 +れて +鼻 +だけ +拭 +く +事 +や +富子令嬢 +が +阿倍川餅 +を +無暗 +に +召 +し +上 +がらるる +事 +や +それから +金田君自身 +が +金田君 +は +妻君 +に +似合 +わず +鼻 +の +低 +い +男 +である +単 +に +鼻 +のみではない +顔全体 +が +低 +い +小供 +の +時分喧嘩 +をして +餓鬼大将 +のために +頸筋 +を +捉 +まえられて +うんと +精一杯 +に +土塀 +へ +圧 +し +付 +けられた +時 +の +顔 +が +四十年後 +の +今日 +まで +因果 +をなしておりはせぬかと +怪 +まるるくらい +平坦 +な +顔 +である +至極穏 +かで +危険 +のない +顔 +には +相違 +ないが +何 +となく +変化 +に +乏 +しい +いくら +怒 +っても +平 +かな +顔 +である +その +金田君 +が +鮪 +の +刺身 +を +食 +って +自分 +で +自分 +の +禿頭 +をぴちゃぴちゃ +叩 +く +事 +や +それから +顔 +が +低 +いばかりでなく +背 +が +低 +いので +無暗 +に +高 +い +帽子 +と +高 +い +下駄 +を +穿 +く +事 +や +それを +車夫 +がおかしがって +書生 +に +話 +す +事 +や +書生 +がなるほど +君 +の +観察 +は +機敏 +だと +感心 +する +事 +や +一々数 +え +切 +れない +近頃 +は +勝手口 +の +横 +を +庭 +へ +通 +り +抜 +けて +築山 +の +陰 +から +向 +うを +見渡 +して +障子 +が +立 +て +切 +って +物静 +かであるなと +見極 +めがつくと +徐々上 +り +込 +む +もし +人声 +が +賑 +かであるか +座敷 +から +見透 +かさるる +恐 +れがあると +思 +えば +池 +を +東 +へ +廻 +って +雪隠 +の +横 +から +知 +らぬ +間 +に +椽 +の +下 +へ +出 +る +悪 +い +事 +をした +覚 +はないから +何 +も +隠 +れる +事 +も +恐 +れる +事 +もないのだが +そこが +人間 +と +云 +う +無法者 +に +逢 +っては +不運 +と +諦 +めるより +仕方 +がないので +もし +世間 +が +熊坂長範 +ばかりになったらいかなる +盛徳 +の +君子 +もやはり +吾輩 +のような +態度 +に +出 +ずるであろう +金田君 +は +堂々 +たる +実業家 +であるから +固 +より +熊坂長範 +のように +五尺三寸 +を +振 +り +廻 +す +気遣 +はあるまいが +承 +る +処 +によれば +人 +を +人 +と +思 +わぬ +病気 +があるそうである +人 +を +人 +と +思 +わないくらいなら +猫 +を +猫 +とも +思 +うまい +して +見 +れば +猫 +たるものはいかなる +盛徳 +の +猫 +でも +彼 +の +邸内 +で +決 +して +油断 +は +出来 +ぬ +訳 +である +しかしその +油断 +の +出来 +ぬところが +吾輩 +にはちょっと +面白 +いので +吾輩 +がかくまでに +金田家 +の +門 +を +出入 +するのも +ただこの +危険 +が +冒 +して +見 +たいばかりかも +知 +れぬ +それは +追 +って +篤 +と +考 +えた +上 +猫 +の +脳裏 +を +残 +りなく +解剖 +し +得 +た +時改 +めて +御吹聴仕 +ろう +今日 +はどんな +模様 +だなと +例 +の +築山 +の +芝生 +の +上 +に +顎 +を +押 +しつけて +前面 +を +見渡 +すと +十五畳 +の +客間 +を +弥生 +の +春 +に +明 +け +放 +って +中 +には +金田夫婦 +と +一人 +の +来客 +との +御話最中 +である +生憎鼻子夫人 +の +鼻 +がこっちを +向 +いて +池越 +しに +吾輩 +の +額 +の +上 +を +正面 +から +睨 +め +付 +けている +鼻 +に +睨 +まれたのは +生 +れて +今日 +が +始 +めてである +金田君 +は +幸 +い +横顔 +を +向 +けて +客 +と +相対 +しているから +例 +の +平坦 +な +部分 +は +半分 +かくれて +見 +えぬが +その +代 +り +鼻 +の +在所 +が +判然 +しない +ただ +胡麻塩色 +の +口髯 +が +好 +い +加減 +な +所 +から +乱雑 +に +茂生 +しているので +あの +上 +に +孔 +が +二 +つあるはずだと +結論 +だけは +苦 +もなく +出来 +る +春風 +もああ +云 +う +滑 +かな +顔 +ばかり +吹 +いていたら +定 +めて +楽 +だろうと +ついでながら +想像 +を +逞 +しゅうして +見 +た +御客 +さんは +三人 +の +中 +で +一番普通 +な +容貌 +を +有 +している +ただし +普通 +なだけに +これぞと +取 +り +立 +てて +紹介 +するに +足 +るような +雑作 +は +一 +つもない +普通 +と +云 +うと +結構 +なようだが +普通 +の +極平凡 +の +堂 +に +上 +り +庸俗 +の +室 +に +入 +ったのはむしろ +憫然 +の +至 +りだ +かかる +無意味 +な +面構 +を +有 +すべき +宿命 +を +帯 +びて +明治 +の +昭代 +に +生 +れて +来 +たのは +誰 +だろう +例 +のごとく +椽 +の +下 +まで +行 +ってその +談話 +を +承 +わらなくては +分 +らぬ +それで +妻 +がわざわざあの +男 +の +所 +まで +出掛 +けて +行 +って +容子 +を +聞 +いたんだがね +と +金田君 +は +例 +のごとく +横風 +な +言葉使 +である +横風 +ではあるが +毫 +も +峻嶮 +なところがない +言語 +も +彼 +の +顔面 +のごとく +平板尨大 +である +なるほどあの +男 +が +水島 +さんを +教 +えた +事 +がございますので +なるほど +よい +御思 +い +付 +きで +なるほど +となるほどずくめのは +御客 +さんである +ところが +何 +だか +要領 +を +得 +んので +ええ +苦沙弥 +じゃ +要領 +を +得 +ない +訳 +で +あの +男 +は +私 +がいっしょに +下宿 +をしている +時分 +から +実 +に +煮 +え +切 +らない +そりゃ +御困 +りでございましたろう +と +御客 +さんは +鼻子夫人 +の +方 +を +向 +く +困 +るの +困 +らないのってあなた +私 +しゃこの +年 +になるまで +人 +のうちへ +行 +って +あんな +不取扱 +を +受 +けた +事 +はありゃしません +と +鼻子 +は +例 +によって +鼻嵐 +を +吹 +く +何 +か +無礼 +な +事 +でも +申 +しましたか +昔 +しから +頑固 +な +性分 +で +何 +しろ +十年一日 +のごとく +リ +ドル +専門 +の +教師 +をしているのでも +大体御分 +りになりましょう +と +御客 +さんは +体 +よく +調子 +を +合 +せている +いや +御話 +しにもならんくらいで +妻 +が +何 +か +聞 +くとまるで +剣 +もほろろの +挨拶 +だそうで +それは +怪 +しからん +訳 +で +一体少 +し +学問 +をしているととかく +慢心 +が +萌 +すもので +その +上貧乏 +をすると +負 +け +惜 +しみが +出 +ますから +いえ +世 +の +中 +には +随分無法 +な +奴 +がおりますよ +自分 +の +働 +きのないのにゃ +気 +が +付 +かないで +無暗 +に +財産 +のあるものに +喰 +って +掛 +るなんてえのが +まるで +彼等 +の +財産 +でも +捲 +き +上 +げたような +気分 +ですから +驚 +きますよ +あははは +と +御客 +さんは +大恐悦 +の +体 +である +いや +まことに +言語同断 +で +ああ +云 +うのは +必竟世間見 +ずの +我儘 +から +起 +るのだから +ちっと +懲 +らしめのためにいじめてやるが +好 +かろうと +思 +って +少 +し +当 +ってやったよ +なるほどそれでは +大分答 +えましたろう +全 +く +本人 +のためにもなる +事 +ですから +と +御客 +さんはいかなる +当 +り +方 +か +承 +らぬ +先 +からすでに +金田君 +に +同意 +している +ところが +鈴木 +さん +まあなんて +頑固 +な +男 +なんでしょう +学校 +へ +出 +ても +福地 +さんや +津木 +さんには +口 +も +利 +かないんだそうです +恐 +れ +入 +って +黙 +っているのかと +思 +ったらこの +間 +は +罪 +もない +宅 +の +書生 +を +ステッキ +を +持 +って +追 +っ +懸 +けたってんです +三十面 +さげて +よく +まあ +そんな +馬鹿 +な +真似 +が +出来 +たもんじゃありませんか +全 +くやけで +少 +し +気 +が +変 +になってるんですよ +へえどうしてまたそんな +乱暴 +な +事 +をやったんで +とこれには +さすがの +御客 +さんも +少 +し +不審 +を +起 +したと +見 +える +なあに +ただあの +男 +の +前 +を +何 +とか +云 +って +通 +ったんだそうです +すると +いきなり +ステッキ +を +持 +って +跣足 +で +飛 +び +出 +して +来 +たんだそうです +よしんば +ちっとやそっと +何 +か +云 +ったって +小供 +じゃありませんか +髯面 +の +大僧 +の +癖 +にしかも +教師 +じゃありませんか +さよう +教師 +ですからな +と +御客 +さんが +云 +うと +金田君 +も +教師 +だからな +と +云 +う +教師 +たる +以上 +はいかなる +侮辱 +を +受 +けても +木像 +のようにおとなしくしておらねばならぬとはこの +三人 +の +期 +せずして +一致 +した +論点 +と +見 +える +それに +あの +迷亭 +って +男 +はよっぽどな +酔興人 +ですね +役 +にも +立 +たない +嘘八百 +を +並 +べ +立 +てて +私 +しゃあんな +変梃 +な +人 +にゃ +初 +めて +逢 +いましたよ +ああ +迷亭 +ですか +あいかわらず +法螺 +を +吹 +くと +見 +えますね +やはり +苦沙弥 +の +所 +で +御逢 +いになったんですか +あれに +掛 +っちゃたまりません +あれも +昔 +し +自炊 +の +仲間 +でしたがあんまり +人 +を +馬鹿 +にするものですから +能 +く +喧嘩 +をしましたよ +誰 +だって +怒 +りまさあね +あんなじゃ +そりゃ +嘘 +をつくのも +宜 +うござんしょうさ +ね +義理 +が +悪 +るいとか +ばつを +合 +せなくっちゃあならないとか +そんな +時 +には +誰 +しも +心 +にない +事 +を +云 +うもんでさあ +しかしあの +男 +のは +吐 +かなくってすむのに +矢鱈 +に +吐 +くんだから +始末 +に +了 +えないじゃありませんか +何 +が +欲 +しくって +あんな +出鱈目 +を +よくまあ +しらじらしく +云 +えると +思 +いますよ +ごもっともで +全 +く +道楽 +からくる +嘘 +だから +困 +ります +せっかくあなた +真面目 +に +聞 +きに +行 +った +水島 +の +事 +も +滅茶滅茶 +になってしまいました +私 +ゃ +剛腹 +で +忌々 +しくって +それでも +義理 +は +義理 +でさあ +人 +のうちへ +物 +を +聞 +きに +行 +って +知 +らん +顔 +の +半兵衛 +もあんまりですから +後 +で +車夫 +に +ビ +ル +を +一 +ダ +ス +持 +たせてやったんです +ところがあなたどうでしょう +こんなものを +受取 +る +理由 +がない +持 +って +帰 +れって +云 +うんだそうで +いえ +御礼 +だから +どうか +御取 +り +下 +さいって +車夫 +が +云 +ったら +悪 +くいじゃあありませんか +俺 +は +ジャム +は +毎日舐 +めるが +ビ +ル +のような +苦 +い +者 +は +飲 +んだ +事 +がないって +ふいと +奥 +へ +這入 +ってしまったって +言 +い +草 +に +事 +を +欠 +いて +まあどうでしょう +失礼 +じゃありませんか +そりゃ +ひどい +と +御客 +さんも +今度 +は +本気 +に +苛 +いと +感 +じたらしい +そこで +今日 +わざわざ +君 +を +招 +いたのだがね +としばらく +途切 +れて +金田君 +の +声 +が +聞 +える +そんな +馬鹿者 +は +陰 +から +からかってさえいればすむようなものの +少々 +それでも +困 +る +事 +があるじゃて +と +鮪 +の +刺身 +を +食 +う +時 +のごとく +禿頭 +をぴちゃぴちゃ +叩 +く +もっとも +吾輩 +は +椽 +の +下 +にいるから +実際叩 +いたか +叩 +かないか +見 +えようはずがないが +この +禿頭 +の +音 +は +近来大分聞馴 +れている +比丘尼 +が +木魚 +の +音 +を +聞 +き +分 +けるごとく +椽 +の +下 +からでも +音 +さえたしかであればすぐ +禿頭 +だなと +出所 +を +鑑定 +する +事 +が +出来 +る +そこでちょっと +君 +を +煩 +わしたいと +思 +ってな +私 +に +出来 +ます +事 +なら +何 +でも +御遠慮 +なくどうか +今度東京勤務 +と +云 +う +事 +になりましたのも +全 +くいろいろ +御心配 +を +掛 +けた +結果 +にほかならん +訳 +でありますから +と +御客 +さんは +快 +よく +金田君 +の +依頼 +を +承諾 +する +この +口調 +で +見 +るとこの +御客 +さんはやはり +金田君 +の +世話 +になる +人 +と +見 +える +いやだんだん +事件 +が +面白 +く +発展 +してくるな +今日 +はあまり +天気 +が +宜 +いので +来 +る +気 +もなしに +来 +たのであるが +こう +云 +う +好材料 +を +得 +ようとは +全 +く +思 +い +掛 +けなんだ +御彼岸 +にお +寺詣 +りをして +偶然方丈 +で +牡丹餅 +の +御馳走 +になるような +者 +だ +金田君 +はどんな +事 +を +客人 +に +依頼 +するかなと +椽 +の +下 +から +耳 +を +澄 +して +聞 +いている +あの +苦沙弥 +と +云 +う +変物 +が +どう +云 +う +訳 +か +水島 +に +入 +れ +智慧 +をするので +あの +金田 +の +娘 +を +貰 +っては +行 +かんなどとほのめかすそうだ +なあ +鼻子 +そうだな +ほのめかすどころじゃないんです +あんな +奴 +の +娘 +を +貰 +う +馬鹿 +がどこの +国 +にあるものか +寒月君決 +して +貰 +っちゃいかんよって +云 +うんです +あんな +奴 +とは +何 +だ +失敬 +な +そんな +乱暴 +な +事 +を +云 +ったのか +云 +ったどころじゃありません +ちゃんと +車屋 +の +神 +さんが +知 +らせに +来 +てくれたんです +鈴木君 +どうだい +御聞 +の +通 +りの +次第 +さ +随分厄介 +だろうが +困 +りますね +ほかの +事 +と +違 +って +こう +云 +う +事 +には +他人 +が +妄 +りに +容喙 +するべきはずの +者 +ではありませんからな +そのくらいな +事 +はいかな +苦沙弥 +でも +心得 +ているはずですが +一体 +どうした +訳 +なんでしょう +それでの +君 +は +学生時代 +から +苦沙弥 +と +同宿 +をしていて +今 +はとにかく +昔 +は +親密 +な +間柄 +であったそうだから +御依頼 +するのだが +君当人 +に +逢 +ってな +よく +利害 +を +諭 +して +見 +てくれんか +何 +か +怒 +っているかも +知 +れんが +怒 +るのは +向 +が +悪 +るいからで +先方 +がおとなしくしてさえいれば +一身上 +の +便宜 +も +充分計 +ってやるし +気 +に +障 +わるような +事 +もやめてやる +しかし +向 +が +向 +ならこっちもこっちと +云 +う +気 +になるからな +つまりそんな +我 +を +張 +るのは +当人 +の +損 +だからな +ええ +全 +くおっしゃる +通 +り +愚 +な +抵抗 +をするのは +本人 +の +損 +になるばかりで +何 +の +益 +もない +事 +ですから +善 +く +申 +し +聞 +けましょう +それから +娘 +はいろいろと +申 +し +込 +もある +事 +だから +必 +ず +水島 +にやると +極 +める +訳 +にも +行 +かんが +だんだん +聞 +いて +見 +ると +学問 +も +人物 +も +悪 +くもないようだから +もし +当人 +が +勉強 +して +近 +い +内 +に +博士 +にでもなったらあるいはもらう +事 +が +出来 +るかも +知 +れんくらいはそれとなくほのめかしても +構 +わん +そう +云 +ってやったら +当人 +も +励 +みになって +勉強 +する +事 +でしょう +宜 +しゅうございます +それから +あの +妙 +な +事 +だが +水島 +にも +似合 +わん +事 +だと +思 +うが +あの +変物 +の +苦沙弥 +を +先生先生 +と +云 +って +苦沙弥 +の +云 +う +事 +は +大抵聞 +く +様子 +だから +困 +る +なにそりゃ +何 +も +水島 +に +限 +る +訳 +では +無論 +ないのだから +苦沙弥 +が +何 +と +云 +って +邪魔 +をしようと +わしの +方 +は +別 +に +差支 +えもせんが +水島 +さんが +可哀 +そうですからね +と +鼻子夫人 +が +口 +を +出 +す +水島 +と +云 +う +人 +には +逢 +った +事 +もございませんが +とにかくこちらと +御縁組 +が +出来 +れば +生涯 +の +幸福 +で +本人 +は +無論異存 +はないのでしょう +ええ +水島 +さんは +貰 +いたがっているんですが +苦沙弥 +だの +迷亭 +だのって +変 +り +者 +が +何 +だとか +かんだとか +云 +うものですから +そりゃ +善 +くない +事 +で +相当 +の +教育 +のあるものにも +似合 +わん +所作 +ですな +よく +私 +が +苦沙弥 +の +所 +へ +参 +って +談 +じましょう +ああ +どうか +御面倒 +でも +一 +つ +願 +いたい +それから +実 +は +水島 +の +事 +も +苦沙弥 +が +一番詳 +しいのだがせんだって +妻 +が +行 +った +時 +は +今 +の +始末 +で +碌々聞 +く +事 +も +出来 +なかった +訳 +だから +君 +から +今一応本人 +の +性行学才等 +をよく +聞 +いて +貰 +いたいて +かしこまりました +今日 +は +土曜 +ですからこれから +廻 +ったら +もう +帰 +っておりましょう +近頃 +はどこに +住 +んでおりますか +知 +らん +ここの +前 +を +右 +へ +突 +き +当 +って +左 +へ +一丁 +ばかり +行 +くと +崩 +れかかった +黒塀 +のあるうちです +と +鼻子 +が +教 +える +それじゃ +つい +近所 +ですな +訳 +はありません +帰 +りにちょっと +寄 +って +見 +ましょう +なあに +大体分 +りましょう +標札 +を +見 +れば +標札 +はあるときと +ないときとありますよ +名刺 +を +御饌粒 +で +門 +へ +貼 +り +付 +けるのでしょう +雨 +がふると +剥 +がれてしまいましょう +すると +御天気 +の +日 +にまた +貼 +り +付 +けるのです +だから +標札 +は +当 +にゃなりませんよ +あんな +面倒臭 +い +事 +をするよりせめて +木札 +でも +懸 +けたらよさそうなもんですがねえ +ほんとうにどこまでも +気 +の +知 +れない +人 +ですよ +どうも +驚 +きますな +しかし +崩 +れた +黒塀 +のうちと +聞 +いたら +大概分 +るでしょう +ええあんな +汚 +ないうちは +町内 +に +一軒 +しかないから +すぐ +分 +りますよ +あ +そうそうそれで +分 +らなければ +好 +い +事 +がある +何 +でも +屋根 +に +草 +が +生 +えたうちを +探 +して +行 +けば +間違 +っこありませんよ +よほど +特色 +のある +家 +ですな +アハハハハ +鈴木君 +が +御光来 +になる +前 +に +帰 +らないと +少 +し +都合 +が +悪 +い +談話 +もこれだけ +聞 +けば +大丈夫沢山 +である +椽 +の +下 +を +伝 +わって +雪隠 +を +西 +へ +廻 +って +築山 +の +陰 +から +往来 +へ +出 +て +急 +ぎ +足 +で +屋根 +に +草 +の +生 +えているうちへ +帰 +って +来 +て +何喰 +わぬ +顔 +をして +座敷 +の +椽 +へ +廻 +る +主人 +は +椽側 +へ +白毛布 +を +敷 +いて +腹這 +になって +麗 +かな +春日 +に +甲羅 +を +干 +している +太陽 +の +光線 +は +存外公平 +なもので +屋根 +に +ペンペン +草 +の +目標 +のある +陋屋 +でも +金田君 +の +客間 +のごとく +陽気 +に +暖 +かそうであるが +気 +の +毒 +な +事 +には +毛布 +だけが +春 +らしくない +製造元 +では +白 +のつもりで +織 +り +出 +して +唐物屋 +でも +白 +の +気 +で +売 +り +捌 +いたのみならず +主人 +も +白 +と +云 +う +注文 +で +買 +って +来 +たのであるが +何 +しろ +十二三年以前 +の +事 +だから +白 +の +時代 +はとくに +通 +り +越 +してただ +今 +は +濃灰色 +なる +変色 +の +時期 +に +遭遇 +しつつある +この +時期 +を +経過 +して +他 +の +暗黒色 +に +化 +けるまで +毛布 +の +命 +が +続 +くかどうだかは +疑問 +である +今 +でもすでに +万遍 +なく +擦 +り +切 +れて +竪横 +の +筋 +は +明 +かに +読 +まれるくらいだから +毛布 +と +称 +するのはもはや +僭上 +の +沙汰 +であって +毛 +の +字 +は +省 +いて +単 +に +ット +とでも +申 +すのが +適当 +である +しかし +主人 +の +考 +えでは +一年持 +ち +二年持 +ち +五年持 +ち +十年持 +った +以上 +は +生涯持 +たねばならぬと +思 +っているらしい +随分呑気 +な +事 +である +さてその +因縁 +のある +毛布 +の +上 +へ +前申 +す +通 +り +腹這 +になって +何 +をしているかと +思 +うと +両手 +で +出張 +った +顋 +を +支 +えて +右手 +の +指 +の +股 +に +巻煙草 +を +挟 +んでいる +ただそれだけである +もっとも +彼 +が +フケ +だらけの +頭 +の +裏 +には +宇宙 +の +大真理 +が +火 +の +車 +のごとく +廻転 +しつつあるかも +知 +れないが +外部 +から +拝見 +したところでは +そんな +事 +とは +夢 +にも +思 +えない +煙草 +の +火 +はだんだん +吸口 +の +方 +へ +逼 +って +一寸 +ばかり +燃 +え +尽 +した +灰 +の +棒 +がぱたりと +毛布 +の +上 +に +落 +つるのも +構 +わず +主人 +は +一生懸命 +に +煙草 +から +立 +ち +上 +る +煙 +の +行末 +を +見詰 +めている +その +煙 +りは +春風 +に +浮 +きつ +沈 +みつ +流 +れる +輪 +を +幾重 +にも +描 +いて +紫深 +き +細君 +の +洗髪 +の +根本 +へ +吹 +き +寄 +せつつある +おや +細君 +の +事 +を +話 +しておくはずだった +忘 +れていた +細君 +は +主人 +に +尻 +を +向 +けて +なに +失礼 +な +細君 +だ +別 +に +失礼 +な +事 +はないさ +礼 +も +非礼 +も +相互 +の +解釈次第 +でどうでもなる +事 +だ +主人 +は +平気 +で +細君 +の +尻 +のところへ +頬杖 +を +突 +き +細君 +は +平気 +で +主人 +の +顔 +の +先 +へ +荘厳 +なる +尻 +を +据 +えたまでの +事 +で +無礼 +も +糸瓜 +もないのである +御両人 +は +結婚後一 +ヵ +年 +も +立 +たぬ +間 +に +礼儀作法 +などと +窮屈 +な +境遇 +を +脱却 +せられた +超然的夫婦 +である +さてかくのごとく +主人 +に +尻 +を +向 +けた +細君 +はどう +云 +う +了見 +か +今日 +の +天気 +に +乗 +じて +尺 +に +余 +る +緑 +の +黒髪 +を +麩海苔 +と +生卵 +で +ゴシゴシ +洗濯 +せられた +者 +と +見 +えて +癖 +のない +奴 +を +見 +よがしに +肩 +から +背 +へ +振 +りかけて +無言 +のまま +小供 +の +袖 +なしを +熱心 +に +縫 +っている +実 +はその +洗髪 +を +乾 +かすために +唐縮緬 +の +布団 +と +針箱 +を +椽側 +へ +出 +して +恭 +しく +主人 +に +尻 +を +向 +けたのである +あるいは +主人 +の +方 +で +尻 +のある +見当 +へ +顔 +を +持 +って +来 +たのかも +知 +れない +そこで +先刻御話 +しをした +煙草 +の +煙 +りが +豊 +かに +靡 +く +黒髪 +の +間 +に +流 +れ +流 +れて +時 +ならぬ +陽炎 +の +燃 +えるところを +主人 +は +余念 +もなく +眺 +めている +しかしながら +煙 +は +固 +より +一所 +に +停 +まるものではない +その +性質 +として +上 +へ +上 +へと +立 +ち +登 +るのだから +主人 +の +眼 +もこの +煙 +りの +髪毛 +と +縺 +れ +合 +う +奇観 +を +落 +ちなく +見 +ようとすれば +是非共眼 +を +動 +かさなければならない +主人 +はまず +腰 +の +辺 +から +観察 +を +始 +めて +徐々 +と +背中 +を +伝 +って +肩 +から +頸筋 +に +掛 +ったが +それを +通 +り +過 +ぎてようよう +脳天 +に +達 +した +時 +覚 +えずあっと +驚 +いた +主人 +が +偕老同穴 +を +契 +った +夫人 +の +脳天 +の +真中 +には +真丸 +な +大 +きな +禿 +がある +しかもその +禿 +が +暖 +かい +日光 +を +反射 +して +今 +や +時 +を +得顔 +に +輝 +いている +思 +わざる +辺 +にこの +不思議 +な +大発見 +をなした +時 +の +主人 +の +眼 +は +眩 +ゆい +中 +に +充分 +の +驚 +きを +示 +して +烈 +しい +光線 +で +瞳孔 +の +開 +くのも +構 +わず +一心不乱 +に +見 +つめている +主人 +がこの +禿 +を +見 +た +時 +第一彼 +の +脳裏 +に +浮 +んだのはかの +家伝来 +の +仏壇 +に +幾世 +となく +飾 +り +付 +けられたる +御灯明皿 +である +彼 +の +一家 +は +真宗 +で +真宗 +では +仏壇 +に +身分不相応 +な +金 +を +掛 +けるのが +古例 +である +主人 +は +幼少 +の +時 +その +家 +の +倉 +の +中 +に +薄暗 +く +飾 +り +付 +けられたる +金箔厚 +き +厨子 +があって +その +厨子 +の +中 +にはいつでも +真鍮 +の +灯明皿 +がぶら +下 +って +その +灯明皿 +には +昼 +でもぼんやりした +灯 +がついていた +事 +を +記憶 +している +周囲 +が +暗 +い +中 +にこの +灯明皿 +が +比較的明瞭 +に +輝 +やいていたので +小供心 +にこの +灯 +を +何遍 +となく +見 +た +時 +の +印象 +が +細君 +の +禿 +に +喚 +び +起 +されて +突然飛 +び +出 +したものであろう +灯明皿 +は +一分立 +たぬ +間 +に +消 +えた +この +度 +は +観音様 +の +鳩 +の +事 +を +思 +い +出 +す +観音様 +の +鳩 +と +細君 +の +禿 +とは +何等 +の +関係 +もないようであるが +主人 +の +頭 +では +二 +つの +間 +に +密接 +な +聯想 +がある +同 +じく +小供 +の +時分 +に +浅草 +へ +行 +くと +必 +ず +鳩 +に +豆 +を +買 +ってやった +豆 +は +一皿 +が +文久二 +つで +赤 +い +土器 +へ +這入 +っていた +その +土器 +が +色 +と +云 +い +大 +さと +云 +いこの +禿 +によく +似 +ている +なるほど +似 +ているな +と +主人 +が +さも +感心 +したらしく +云 +うと +何 +がです +と +細君 +は +見向 +きもしない +何 +だって +御前 +の +頭 +にゃ +大 +きな +禿 +があるぜ +知 +ってるか +ええ +と +細君 +は +依然 +として +仕事 +の +手 +をやめずに +答 +える +別段露見 +を +恐 +れた +様子 +もない +超然 +たる +模範妻君 +である +嫁 +にくるときからあるのか +結婚後新 +たに +出来 +たのか +と +主人 +が +聞 +く +もし +嫁 +にくる +前 +から +禿 +げているなら +欺 +されたのであると +口 +へは +出 +さないが +心 +の +中 +で +思 +う +いつ +出来 +たんだか +覚 +えちゃいませんわ +禿 +なんざどうだって +宜 +いじゃありませんか +と +大 +に +悟 +ったものである +どうだって +宜 +いって +自分 +の +頭 +じゃないか +と +主人 +は +少々怒気 +を +帯 +びている +自分 +の +頭 +だから +どうだって +宜 +いんだわ +と +云 +ったが +さすが +少 +しは +気 +になると +見 +えて +右 +の +手 +を +頭 +に +乗 +せて +くるくる +禿 +を +撫 +でて +見 +る +おや +大分大 +きくなった +事 +こんなじゃ +無 +いと +思 +っていた +と +言 +ったところをもって +見 +ると +年 +に +合 +わして +禿 +があまり +大 +き +過 +ぎると +云 +う +事 +をようやく +自覚 +したらしい +女 +は +髷 +に +結 +うと +ここが +釣 +れますから +誰 +でも +禿 +げるんですわ +と +少 +しく +弁護 +しだす +そんな +速度 +で +みんな +禿 +げたら +四十 +くらいになれば +から +薬缶 +ばかり +出来 +なければならん +そりゃ +病気 +に +違 +いない +伝染 +するかも +知 +れん +今 +のうち +早 +く +甘木 +さんに +見 +て +貰 +え +と +主人 +はしきりに +自分 +の +頭 +を +撫 +で +廻 +して +見 +る +そんなに +人 +の +事 +をおっしゃるが +あなただって +鼻 +の +孔 +へ +白髪 +が +生 +えてるじゃありませんか +禿 +が +伝染 +するなら +白髪 +だって +伝染 +しますわ +と +細君少々 +ぷりぷりする +鼻 +の +中 +の +白髪 +は +見 +えんから +害 +はないが +脳天 +が +ことに +若 +い +女 +の +脳天 +がそんなに +禿 +げちゃ +見苦 +しい +不具 +だ +不具 +なら +なぜ +御貰 +いになったのです +御自分 +が +好 +きで +貰 +っておいて +不具 +だなんて +知 +らなかったからさ +全 +く +今日 +まで +知 +らなかったんだ +そんなに +威張 +るなら +なぜ +嫁 +に +来 +る +時頭 +を +見 +せなかったんだ +馬鹿 +な +事 +を +どこの +国 +に +頭 +の +試験 +をして +及第 +したら +嫁 +にくるなんて +ものが +在 +るもんですか +禿 +はまあ +我慢 +もするが +御前 +は +背 +いが +人並外 +れて +低 +い +はなはだ +見苦 +しくていかん +背 +いは +見 +ればすぐ +分 +るじゃありませんか +背 +の +低 +いのは +最初 +から +承知 +で +御貰 +いになったんじゃありませんか +それは +承知 +さ +承知 +には +相違 +ないがまだ +延 +びるかと +思 +ったから +貰 +ったのさ +廿 +にもなって +背 +いが +延 +びるなんて +あなたもよっぽど +人 +を +馬鹿 +になさるのね +と +細君 +は +袖 +なしを +抛 +り +出 +して +主人 +の +方 +に +捩 +じ +向 +く +返答次第 +ではその +分 +にはすまさんと +云 +う +権幕 +である +廿 +になったって +背 +いが +延 +びてならんと +云 +う +法 +はあるまい +嫁 +に +来 +てから +滋養分 +でも +食 +わしたら +少 +しは +延 +びる +見込 +みがあると +思 +ったんだ +と +真面目 +な +顔 +をして +妙 +な +理窟 +を +述 +べていると +門口 +の +ベル +が +勢 +よく +鳴 +り +立 +てて +頼 +むと +云 +う +大 +きな +声 +がする +いよいよ +鈴木君 +が +ペンペン +草 +を +目的 +に +苦沙弥先生 +の +臥竜窟 +を +尋 +ねあてたと +見 +える +細君 +は +喧嘩 +を +後日 +に +譲 +って +倉皇針箱 +と +袖 +なしを +抱 +えて +茶 +の +間 +へ +逃 +げ +込 +む +主人 +は +鼠色 +の +毛布 +を +丸 +めて +書斎 +へ +投 +げ +込 +む +やがて +下女 +が +持 +って +来 +た +名刺 +を +見 +て +主人 +はちょっと +驚 +ろいたような +顔付 +であったが +こちらへ +御通 +し +申 +してと +言 +い +棄 +てて +名刺 +を +握 +ったまま +後架 +へ +這入 +った +何 +のために +後架 +へ +急 +に +這入 +ったか +一向要領 +を +得 +ん +何 +のために +鈴木藤十郎君 +の +名刺 +を +後架 +まで +持 +って +行 +ったのかなおさら +説明 +に +苦 +しむ +とにかく +迷惑 +なのは +臭 +い +所 +へ +随行 +を +命 +ぜられた +名刺君 +である +下女 +が +更紗 +の +座布団 +を +床 +の +前 +へ +直 +して +どうぞこれへと +引 +き +下 +がった +跡 +で +鈴木君 +は +一応室内 +を +見廻 +わす +床 +に +掛 +けた +花開万国春 +とある +木菴 +の +贋物 +や +京製 +の +安青磁 +に +活 +けた +彼岸桜 +などを +一々順番 +に +点検 +したあとで +ふと +下女 +の +勧 +めた +布団 +の +上 +を +見 +るといつの +間 +にか +一疋 +の +猫 +がすまして +坐 +っている +申 +すまでもなくそれはかく +申 +す +吾輩 +である +この +時鈴木君 +の +胸 +のうちにちょっとの +間顔色 +にも +出 +ぬほどの +風波 +が +起 +った +この +布団 +は +疑 +いもなく +鈴木君 +のために +敷 +かれたものである +自分 +のために +敷 +かれた +布団 +の +上 +に +自分 +が +乗 +らぬ +先 +から +断 +りもなく +妙 +な +動物 +が +平然 +と +蹲踞 +している +これが +鈴木君 +の +心 +の +平均 +を +破 +る +第一 +の +条件 +である +もしこの +布団 +が +勧 +められたまま +主 +なくして +春風 +の +吹 +くに +任 +せてあったなら +鈴木君 +はわざと +謙遜 +の +意 +を +表 +して +主人 +がさあどうぞと +云 +うまでは +堅 +い +畳 +の +上 +で +我慢 +していたかも +知 +れない +しかし +早晩自分 +の +所有 +すべき +布団 +の +上 +に +挨拶 +もなく +乗 +ったものは +誰 +であろう +人間 +なら +譲 +る +事 +もあろうが +猫 +とは +怪 +しからん +乗 +り +手 +が +猫 +であると +云 +うのが +一段 +と +不愉快 +を +感 +ぜしめる +これが +鈴木君 +の +心 +の +平均 +を +破 +る +第二 +の +条件 +である +最後 +にその +猫 +の +態度 +がもっとも +癪 +に +障 +る +少 +しは +気 +の +毒 +そうにでもしている +事 +か +乗 +る +権利 +もない +布団 +の +上 +に +傲然 +と +構 +えて +丸 +い +無愛嬌 +な +眼 +をぱちつかせて +御前 +は +誰 +だいと +云 +わぬばかりに +鈴木君 +の +顔 +を +見 +つめている +これが +平均 +を +破壊 +する +第三 +の +条件 +である +これほど +不平 +があるなら +吾輩 +の +頸根 +っこを +捉 +えて +引 +きずり +卸 +したら +宜 +さそうなものだが +鈴木君 +はだまって +見 +ている +堂々 +たる +人間 +が +猫 +に +恐 +れて +手出 +しをせぬと +云 +う +事 +は +有 +ろうはずがないのに +なぜ +早 +く +吾輩 +を +処分 +して +自分 +の +不平 +を +洩 +らさないかと +云 +うと +これは +全 +く +鈴木君 +が +一個 +の +人間 +として +自己 +の +体面 +を +維持 +する +自重心 +の +故 +であると +察 +せらるる +もし +腕力 +に +訴 +えたなら +三尺 +の +童子 +も +吾輩 +を +自由 +に +上下 +し +得 +るであろうが +体面 +を +重 +んずる +点 +より +考 +えるといかに +金田君 +の +股肱 +たる +鈴木藤十郎 +その +人 +もこの +二尺四方 +の +真中 +に +鎮座 +まします +猫大明神 +を +如何 +ともする +事 +が +出来 +ぬのである +いかに +人 +の +見 +ていぬ +場所 +でも +猫 +と +座席争 +いをしたとあってはいささか +人間 +の +威厳 +に +関 +する +真面目 +に +猫 +を +相手 +にして +曲直 +を +争 +うのはいかにも +大人気 +ない +滑稽 +である +この +不名誉 +を +避 +けるためには +多少 +の +不便 +は +忍 +ばねばならぬ +しかし +忍 +ばねばならぬだけそれだけ +猫 +に +対 +する +憎悪 +の +念 +は +増 +す +訳 +であるから +鈴木君 +は +時々吾輩 +の +顔 +を +見 +ては +苦 +い +顔 +をする +吾輩 +は +鈴木君 +の +不平 +な +顔 +を +拝見 +するのが +面白 +いから +滑稽 +の +念 +を +抑 +えてなるべく +何喰 +わぬ +顔 +をしている +吾輩 +と +鈴木君 +の +間 +に +かくのごとき +無言劇 +が +行 +われつつある +間 +に +主人 +は +衣紋 +をつくろって +後架 +から +出 +て +来 +て +やあ +と +席 +に +着 +いたが +手 +に +持 +っていた +名刺 +の +影 +さえ +見 +えぬところをもって +見 +ると +鈴木藤十郎君 +の +名前 +は +臭 +い +所 +へ +無期徒刑 +に +処 +せられたものと +見 +える +名刺 +こそ +飛 +んだ +厄運 +に +際会 +したものだと +思 +う +間 +もなく +主人 +はこの +野郎 +と +吾輩 +の +襟 +がみを +攫 +んでえいとばかりに +椽側 +へ +擲 +きつけた +さあ +敷 +きたまえ +珍 +らしいな +いつ +東京 +へ +出 +て +来 +た +と +主人 +は +旧友 +に +向 +って +布団 +を +勧 +める +鈴木君 +はちょっとこれを +裏返 +した +上 +で +それへ +坐 +る +ついまだ +忙 +がしいものだから +報知 +もしなかったが +実 +はこの +間 +から +東京 +の +本社 +の +方 +へ +帰 +るようになってね +それは +結構 +だ +大分長 +く +逢 +わなかったな +君 +が +田舎 +へ +行 +ってから +始 +めてじゃないか +うん +もう +十年近 +くになるね +なにその +後時々東京 +へは +出 +て +来 +る +事 +もあるんだが +つい +用事 +が +多 +いもんだから +いつでも +失敬 +するような +訳 +さ +悪 +るく +思 +ってくれたもうな +会社 +の +方 +は +君 +の +職業 +とは +違 +って +随分忙 +がしいんだから +十年立 +つうちには +大分違 +うもんだな +と +主人 +は +鈴木君 +を +見上 +げたり +見下 +ろしたりしている +鈴木君 +は +頭 +を +美麗 +に +分 +けて +英国仕立 +の +トウィ +ド +を +着 +て +派手 +な +襟飾 +りをして +胸 +に +金鎖 +りさえ +ピカ +つかせている +体裁 +どうしても +苦沙弥君 +の +旧友 +とは +思 +えない +うん +こんな +物 +までぶら +下 +げなくちゃ +ならんようになってね +と +鈴木君 +はしきりに +金鎖 +りを +気 +にして +見 +せる +そりゃ +本 +ものかい +と +主人 +は +無作法 +な +質問 +をかける +十八金 +だよ +と +鈴木君 +は +笑 +いながら +答 +えたが +君 +も +大分年 +を +取 +ったね +たしか +小供 +があるはずだったが +一人 +かい +いいや +二人 +いいや +まだあるのか +じゃ +三人 +か +うん +三人 +ある +この +先幾人出来 +るか +分 +らん +相変 +らず +気楽 +な +事 +を +云 +ってるぜ +一番大 +きいのはいくつになるかね +もうよっぽどだろう +うん +いくつか +能 +く +知 +らんが +大方六 +つか +七 +つかだろう +ハハハ +教師 +は +呑気 +でいいな +僕 +も +教員 +にでもなれば +善 +かった +なって +見 +ろ +三日 +で +嫌 +になるから +そうかな +何 +だか +上品 +で +気楽 +で +閑暇 +があって +すきな +勉強 +が +出来 +て +よさそうじゃないか +実業家 +も +悪 +くもないが +我々 +のうちは +駄目 +だ +実業家 +になるならずっと +上 +にならなくっちゃいかん +下 +の +方 +になるとやはりつまらん +御世辞 +を +振 +り +撒 +いたり +好 +かん +猪口 +をいただきに +出 +たり +随分愚 +なもんだよ +僕 +は +実業家 +は +学校時代 +から +大嫌 +だ +金 +さえ +取 +れれば +何 +でもする +昔 +で +云 +えば +素町人 +だからな +と +実業家 +を +前 +に +控 +えて +太平楽 +を +並 +べる +まさか +そうばかりも +云 +えんがね +少 +しは +下品 +なところもあるのさ +とにかく +金 +と +情死 +をする +覚悟 +でなければやり +通 +せないから +ところがその +金 +と +云 +う +奴 +が +曲者 +で +今 +もある +実業家 +の +所 +へ +行 +って +聞 +いて +来 +たんだが +金 +を +作 +るにも +三角術 +を +使 +わなくちゃいけないと +云 +うのさ +義理 +をかく +人情 +をかく +恥 +をかくこれで +三角 +になるそうだ +面白 +いじゃないか +アハハハハ +誰 +だそんな +馬鹿 +は +馬鹿 +じゃない +なかなか +利口 +な +男 +なんだよ +実業界 +でちょっと +有名 +だがね +君知 +らんかしら +ついこの +先 +の +横丁 +にいるんだが +金田 +か +何 +んだあんな +奴 +大変怒 +ってるね +なあに +そりゃ +ほんの +冗談 +だろうがね +そのくらいにせんと +金 +は +溜 +らんと +云 +う +喩 +さ +君 +のようにそう +真面目 +に +解釈 +しちゃ +困 +る +三角術 +は +冗談 +でもいいが +あすこの +女房 +の +鼻 +はなんだ +君行 +ったんなら +見 +て +来 +たろう +あの +鼻 +を +細君 +か +細君 +はなかなかさばけた +人 +だ +鼻 +だよ +大 +きな +鼻 +の +事 +を +云 +ってるんだ +せんだって +僕 +はあの +鼻 +について +俳体詩 +を +作 +ったがね +何 +だい +俳体詩 +と +云 +うのは +俳体詩 +を +知 +らないのか +君 +も +随分時勢 +に +暗 +いな +ああ +僕 +のように +忙 +がしいと +文学 +などは +到底駄目 +さ +それに +以前 +からあまり +数奇 +でない +方 +だから +君 +シャ +レマン +の +鼻 +の +恰好 +を +知 +ってるか +アハハハハ +随分気楽 +だな +知 +らんよ +エルリントン +は +部下 +のものから +鼻々 +と +異名 +をつけられていた +君知 +ってるか +鼻 +の +事 +ばかり +気 +にして +どうしたんだい +好 +いじゃないか +鼻 +なんか +丸 +くても +尖 +んがってても +決 +してそうでない +君 +パスカル +の +事 +を +知 +ってるか +また +知 +ってるかか +まるで +試験 +を +受 +けに +来 +たようなものだ +パスカル +がどうしたんだい +パスカル +がこんな +事 +を +云 +っている +どんな +事 +を +もし +クレオパトラ +の +鼻 +が +少 +し +短 +かかったならば +世界 +の +表面 +に +大変化 +を +来 +したろうと +なるほど +それだから +君 +のようにそう +無雑作 +に +鼻 +を +馬鹿 +にしてはいかん +まあいいさ +これから +大事 +にするから +そりゃそうとして +今日来 +たのは +少 +し +君 +に +用事 +があって +来 +たんだがね +あの +元君 +の +教 +えたとか +云 +う +水島 +ええ +水島 +ええちょっと +思 +い +出 +せない +そら +君 +の +所 +へ +始終来 +ると +云 +うじゃないか +寒月 +か +そうそう +寒月寒月 +あの +人 +の +事 +についてちょっと +聞 +きたい +事 +があって +来 +たんだがね +結婚事件 +じゃないか +まあ +多少 +それに +類似 +の +事 +さ +今日金田 +へ +行 +ったら +この +間鼻 +が +自分 +で +来 +た +そうか +そうだって +細君 +もそう +云 +っていたよ +苦沙弥 +さんに +よく +伺 +おうと +思 +って +上 +ったら +生憎迷亭 +が +来 +ていて +茶々 +を +入 +れて +何 +が +何 +だか +分 +らなくしてしまったって +あんな +鼻 +をつけて +来 +るから +悪 +るいや +いえ +君 +の +事 +を +云 +うんじゃないよ +あの +迷亭君 +がおったもんだから +そう +立 +ち +入 +った +事 +を +聞 +く +訳 +にも +行 +かなかったので +残念 +だったから +もう +一遍僕 +に +行 +ってよく +聞 +いて +来 +てくれないかって +頼 +まれたものだからね +僕 +も +今 +までこんな +世話 +はした +事 +はないが +もし +当人同士 +が +嫌 +やでないなら +中 +へ +立 +って +纏 +めるのも +決 +して +悪 +い +事 +はないからね +それでやって +来 +たのさ +御苦労様 +と +主人 +は +冷淡 +に +答 +えたが +腹 +の +内 +では +当人同士 +と +云 +う +語 +を +聞 +いて +どう +云 +う +訳 +か +分 +らんが +ちょっと +心 +を +動 +かしたのである +蒸 +し +熱 +い +夏 +の +夜 +に +一縷 +の +冷風 +が +袖口 +を +潜 +ったような +気分 +になる +元来 +この +主人 +はぶっ +切 +ら +棒 +の +頑固光沢消 +しを +旨 +として +製造 +された +男 +であるが +さればと +云 +って +冷酷不人情 +な +文明 +の +産物 +とは +自 +からその +撰 +を +異 +にしている +彼 +が +何 +ぞと +云 +うと +むかっ +腹 +をたててぷんぷんするのでも +這裏 +の +消息 +は +会得 +できる +先日鼻 +と +喧嘩 +をしたのは +鼻 +が +気 +に +食 +わぬからで +鼻 +の +娘 +には +何 +の +罪 +もない +話 +しである +実業家 +は +嫌 +いだから +実業家 +の +片割 +れなる +金田某 +も +嫌 +に +相違 +ないがこれも +娘 +その +人 +とは +没交渉 +の +沙汰 +と +云 +わねばならぬ +娘 +には +恩 +も +恨 +みもなくて +寒月 +は +自分 +が +実 +の +弟 +よりも +愛 +している +門下生 +である +もし +鈴木君 +の +云 +うごとく +当人同志 +が +好 +いた +仲 +なら +間接 +にもこれを +妨害 +するのは +君子 +のなすべき +所作 +でない +苦沙弥先生 +はこれでも +自分 +を +君子 +と +思 +っている +もし +当人同志 +が +好 +いているなら +しかしそれが +問題 +である +この +事件 +に +対 +して +自己 +の +態度 +を +改 +めるには +まずその +真相 +から +確 +めなければならん +君 +その +娘 +は +寒月 +の +所 +へ +来 +たがってるのか +金田 +や +鼻 +はどうでも +構 +わんが +娘自身 +の +意向 +はどうなんだ +そりゃ +その +何 +だね +何 +でも +え +来 +たがってるんだろうじゃないか +鈴木君 +の +挨拶 +は +少々曖昧 +である +実 +は +寒月君 +の +事 +だけ +聞 +いて +復命 +さえすればいいつもりで +御嬢 +さんの +意向 +までは +確 +かめて +来 +なかったのである +従 +って +円転滑脱 +の +鈴木君 +もちょっと +狼狽 +の +気味 +に +見 +える +だろうた +判然 +しない +言葉 +だ +と +主人 +は +何事 +によらず +正面 +から +どやし +付 +けないと +気 +がすまない +いや +これゃちょっと +僕 +の +云 +いようがわるかった +令嬢 +の +方 +でもたしかに +意 +があるんだよ +いえ +全 +くだよ +え +細君 +が +僕 +にそう +云 +ったよ +何 +でも +時々 +は +寒月君 +の +悪口 +を +云 +う +事 +もあるそうだがね +あの +娘 +がか +ああ +怪 +しからん +奴 +だ +悪口 +を +云 +うなんて +第一 +それじゃ +寒月 +に +意 +がないんじゃないか +そこがさ +世 +の +中 +は +妙 +なもので +自分 +の +好 +いている +人 +の +悪口 +などは +殊更云 +って +見 +る +事 +もあるからね +そんな +愚 +な +奴 +がどこの +国 +にいるものか +と +主人 +は +斯様 +な +人情 +の +機微 +に +立 +ち +入 +った +事 +を +云 +われても +頓 +と +感 +じがない +その +愚 +な +奴 +が +随分世 +の +中 +にゃあるから +仕方 +がない +現 +に +金田 +の +妻君 +もそう +解釈 +しているのさ +戸惑 +いをした +糸瓜 +のようだなんて +時々寒月 +さんの +悪口 +を +云 +いますから +よっぽど +心 +の +中 +では +思 +ってるに +相違 +ありませんと +主人 +はこの +不可思議 +な +解釈 +を +聞 +いて +あまり +思 +い +掛 +けないものだから +眼 +を +丸 +くして +返答 +もせず +鈴木君 +の +顔 +を +大道易者 +のように +眤 +と +見 +つめている +鈴木君 +はこいつ +この +様子 +では +ことによるとやり +損 +なうなと +疳 +づいたと +見 +えて +主人 +にも +判断 +の +出来 +そうな +方面 +へと +話頭 +を +移 +す +君考 +えても +分 +るじゃないか +あれだけの +財産 +があってあれだけの +器量 +なら +どこへだって +相応 +の +家 +へやれるだろうじゃないか +寒月 +だってえらいかも +知 +れんが +身分 +から +云 +や +いや +身分 +と +云 +っちゃ +失礼 +かも +知 +れない +財産 +と +云 +う +点 +から +云 +や +まあ +だれが +見 +たって +釣 +り +合 +わんのだからね +それを +僕 +がわざわざ +出張 +するくらい +両親 +が +気 +を +揉 +んでるのは +本人 +が +寒月君 +に +意 +があるからの +事 +じゃあないか +と +鈴木君 +はなかなかうまい +理窟 +をつけて +説明 +を +与 +える +今度 +は +主人 +にも +納得 +が +出来 +たらしいのでようやく +安心 +したが +こんなところにまごまごしているとまた +吶喊 +を +喰 +う +危険 +があるから +早 +く +話 +しの +歩 +を +進 +めて +一刻 +も +早 +く +使命 +を +完 +うする +方 +が +万全 +の +策 +と +心付 +いた +それでね +今云 +う +通 +りの +訳 +であるから +先方 +で +云 +うには +何 +も +金銭 +や +財産 +はいらんからその +代 +り +当人 +に +附属 +した +資格 +が +欲 +しい +資格 +と +云 +うと +まあ +肩書 +だね +博士 +になったらやってもいいなんて +威張 +ってる +次第 +じゃない +誤解 +しちゃいかん +せんだって +細君 +の +来 +た +時 +は +迷亭君 +がいて +妙 +な +事 +ばかり +云 +うものだから +いえ +君 +が +悪 +いのじゃない +細君 +も +君 +の +事 +を +御世辞 +のない +正直 +ないい +方 +だと +賞 +めていたよ +全 +く +迷亭君 +がわるかったんだろう +それでさ +本人 +が +博士 +にでもなってくれれば +先方 +でも +世間 +へ +対 +して +肩身 +が +広 +い +面目 +があると +云 +うんだがね +どうだろう +近々 +の +内水島君 +は +博士論文 +でも +呈出 +して +博士 +の +学位 +を +受 +けるような +運 +びには +行 +くまいか +なあに +金田 +だけなら +博士 +も +学士 +もいらんのさ +ただ +世間 +と +云 +う +者 +があるとね +そう +手軽 +にも +行 +かんからな +こう +云 +われて +見 +ると +先方 +で +博士 +を +請求 +するのも +あながち +無理 +でもないように +思 +われて +来 +る +無理 +ではないように +思 +われて +来 +れば +鈴木君 +の +依頼通 +りにしてやりたくなる +主人 +を +活 +かすのも +殺 +すのも +鈴木君 +の +意 +のままである +なるほど +主人 +は +単純 +で +正直 +な +男 +だ +それじゃ +今度寒月 +が +来 +たら +博士論文 +をかくように +僕 +から +勧 +めて +見 +よう +しかし +当人 +が +金田 +の +娘 +を +貰 +うつもりかどうだか +それからまず +問 +い +正 +して +見 +なくちゃいかんからな +問 +い +正 +すなんて +君 +そんな +角張 +った +事 +をして +物 +が +纏 +まるものじゃない +やっぱり +普通 +の +談話 +の +際 +にそれとなく +気 +を +引 +いて +見 +るのが +一番近道 +だよ +気 +を +引 +いて +見 +る +うん +気 +を +引 +くと +云 +うと +語弊 +があるかも +知 +れん +なに +気 +を +引 +かんでもね +話 +しをしていると +自然分 +るもんだよ +君 +にゃ +分 +るかも +知 +れんが +僕 +にゃ +判然 +と +聞 +かん +事 +は +分 +らん +分 +らなけりゃ +まあ +好 +いさ +しかし +迷亭君見 +たように +余計 +な +茶々 +を +入 +れて +打 +ち +壊 +わすのは +善 +くないと +思 +う +仮令勧 +めないまでも +こんな +事 +は +本人 +の +随意 +にすべきはずのものだからね +今度寒月君 +が +来 +たらなるべくどうか +邪魔 +をしないようにしてくれ +給 +え +いえ +君 +の +事 +じゃない +あの +迷亭君 +の +事 +さ +あの +男 +の +口 +にかかると +到底助 +かりっこないんだから +と +主人 +の +代理 +に +迷亭 +の +悪口 +をきいていると +噂 +をすれば +陰 +の +喩 +に +洩 +れず +迷亭先生例 +のごとく +勝手口 +から +飄然 +と +春風 +に +乗 +じて +舞 +い +込 +んで +来 +る +いや +珍客 +だね +僕 +のような +狎客 +になると +苦沙弥 +はとかく +粗略 +にしたがっていかん +何 +でも +苦沙弥 +のうちへは +十年 +に +一遍 +くらいくるに +限 +る +この +菓子 +はいつもより +上等 +じゃないか +と +藤村 +の +羊羹 +を +無雑作 +に +頬張 +る +鈴木君 +はもじもじしている +主人 +はにやにやしている +迷亭 +は +口 +をもがもがさしている +吾輩 +はこの +瞬時 +の +光景 +を +椽側 +から +拝見 +して +無言劇 +と +云 +うものは +優 +に +成立 +し +得 +ると +思 +った +禅家 +で +無言 +の +問答 +をやるのが +以心伝心 +であるなら +この +無言 +の +芝居 +も +明 +かに +以心伝心 +の +幕 +である +すこぶる +短 +かいけれどもすこぶる +鋭 +どい +幕 +である +君 +は +一生旅烏 +かと +思 +ってたら +いつの +間 +にか +舞 +い +戻 +ったね +長生 +はしたいもんだな +どんな +僥倖 +に +廻 +り +合 +わんとも +限 +らんからね +と +迷亭 +は +鈴木君 +に +対 +しても +主人 +に +対 +するごとく +毫 +も +遠慮 +と +云 +う +事 +を +知 +らぬ +いかに +自炊 +の +仲間 +でも +十年 +も +逢 +わなければ +何 +となく +気 +のおけるものだが +迷亭君 +に +限 +って +そんな +素振 +も +見 +えぬのは +えらいのだか +馬鹿 +なのかちょっと +見当 +がつかぬ +可哀 +そうに +そんなに +馬鹿 +にしたものでもない +と +鈴木君 +は +当 +らず +障 +らずの +返事 +はしたが +何 +となく +落 +ちつきかねて +例 +の +金鎖 +を +神経的 +にいじっている +君電気鉄道 +へ +乗 +ったか +と +主人 +は +突然鈴木君 +に +対 +して +奇問 +を +発 +する +今日 +は +諸君 +からひやかされに +来 +たようなものだ +なんぼ +田舎者 +だって +これでも +街鉄 +を +六十株持 +ってるよ +そりゃ +馬鹿 +に +出来 +ないな +僕 +は +八百八十八株半持 +っていたが +惜 +しい +事 +に +大方虫 +が +喰 +ってしまって +今 +じゃ +半株 +ばかりしかない +もう +少 +し +早 +く +君 +が +東京 +へ +出 +てくれば +虫 +の +喰 +わないところを +十株 +ばかりやるところだったが +惜 +しい +事 +をした +相変 +らず +口 +が +悪 +るい +しかし +冗談 +は +冗談 +として +ああ +云 +う +株 +は +持 +ってて +損 +はないよ +年々高 +くなるばかりだから +そうだ +仮令半株 +だって +千年 +も +持 +ってるうちにゃ +倉 +が +三 +つくらい +建 +つからな +君 +も +僕 +もその +辺 +にぬかりはない +当世 +の +才子 +だが +そこへ +行 +くと +苦沙弥 +などは +憐 +れなものだ +株 +と +云 +えば +大根 +の +兄弟分 +くらいに +考 +えているんだから +とまた +羊羹 +をつまんで +主人 +の +方 +を +見 +ると +主人 +も +迷亭 +の +食 +い +気 +が +伝染 +して +自 +ずから +菓子皿 +の +方 +へ +手 +が +出 +る +世 +の +中 +では +万事積極的 +のものが +人 +から +真似 +らるる +権利 +を +有 +している +株 +などはどうでも +構 +わんが +僕 +は +曾呂崎 +に +一度 +でいいから +電車 +へ +乗 +らしてやりたかった +と +主人 +は +喰 +い +欠 +けた +羊羹 +の +歯痕 +を +撫然 +として +眺 +める +曾呂崎 +が +電車 +へ +乗 +ったら +乗 +るたんびに +品川 +まで +行 +ってしまうは +それよりやっぱり +天然居士 +で +沢庵石 +へ +彫 +り +付 +けられてる +方 +が +無事 +でいい +曾呂崎 +と +云 +えば +死 +んだそうだな +気 +の +毒 +だねえ +いい +頭 +の +男 +だったが +惜 +しい +事 +をした +と +鈴木君 +が +云 +うと +迷亭 +は +直 +ちに +引 +き +受 +けて +頭 +は +善 +かったが +飯 +を +焚 +く +事 +は +一番下手 +だったぜ +曾呂崎 +の +当番 +の +時 +には +僕 +あいつでも +外出 +をして +蕎麦 +で +凌 +いでいた +ほんとに +曾呂崎 +の +焚 +いた +飯 +は +焦 +げくさくって +心 +があって +僕 +も +弱 +った +御負 +けに +御菜 +に +必 +ず +豆腐 +をなまで +食 +わせるんだから +冷 +たくて +食 +われやせん +と +鈴木君 +も +十年前 +の +不平 +を +記憶 +の +底 +から +喚 +び +起 +す +苦沙弥 +はあの +時代 +から +曾呂崎 +の +親友 +で +毎晩 +いっしょに +汁粉 +を +食 +いに +出 +たが +その +祟 +りで +今 +じゃ +慢性胃弱 +になって +苦 +しんでいるんだ +実 +を +云 +うと +苦沙弥 +の +方 +が +汁粉 +の +数 +を +余計食 +ってるから +曾呂崎 +より +先 +へ +死 +んで +宜 +い +訳 +なんだ +そんな +論理 +がどこの +国 +にあるものか +俺 +の +汁粉 +より +君 +は +運動 +と +号 +して +毎晩竹刀 +を +持 +って +裏 +の +卵塔婆 +へ +出 +て +石塔 +を +叩 +いてるところを +坊主 +に +見 +つかって +剣突 +を +食 +ったじゃないか +と +主人 +も +負 +けぬ +気 +になって +迷亭 +の +旧悪 +を +曝 +く +アハハハ +そうそう +坊主 +が +仏様 +の +頭 +を +叩 +いては +安眠 +の +妨害 +になるからよしてくれって +言 +ったっけ +しかし +僕 +のは +竹刀 +だが +この +鈴木将軍 +のは +手暴 +だぜ +石塔 +と +相撲 +をとって +大小三個 +ばかり +転 +がしてしまったんだから +あの +時 +の +坊主 +の +怒 +り +方 +は +実 +に +烈 +しかった +是非元 +のように +起 +せと +云 +うから +人足 +を +傭 +うまで +待 +ってくれと +云 +ったら +人足 +じゃいかん +懺悔 +の +意 +を +表 +するためにあなたが +自身 +で +起 +さなくては +仏 +の +意 +に +背 +くと +云 +うんだからね +その +時 +の +君 +の +風采 +はなかったぜ +金巾 +のしゃつに +越中褌 +で +雨上 +りの +水溜 +りの +中 +でうんうん +唸 +って +それを +君 +がすました +顔 +で +写生 +するんだから +苛 +い +僕 +はあまり +腹 +を +立 +てた +事 +のない +男 +だが +あの +時 +ばかりは +失敬 +だと +心 +から +思 +ったよ +あの +時 +の +君 +の +言草 +をまだ +覚 +えているが +君 +は +知 +ってるか +十年前 +の +言草 +なんか +誰 +が +覚 +えているものか +しかしあの +石塔 +に +帰泉院殿黄鶴大居士安永五年辰正月 +と +彫 +ってあったのだけはいまだに +記憶 +している +あの +石塔 +は +古雅 +に +出来 +ていたよ +引 +き +越 +す +時 +に +盗 +んで +行 +きたかったくらいだ +実 +に +美学上 +の +原理 +に +叶 +って +ゴシック +趣味 +な +石塔 +だった +と +迷亭 +はまた +好 +い +加減 +な +美学 +を +振 +り +廻 +す +そりゃいいが +君 +の +言草 +がさ +こうだぜ +吾輩 +は +美学 +を +専攻 +するつもりだから +天地間 +の +面白 +い +出来事 +はなるべく +写生 +しておいて +将来 +の +参考 +に +供 +さなければならん +気 +の +毒 +だの +可哀相 +だのと +云 +う +私情 +は +学問 +に +忠実 +なる +吾輩 +ごときものの +口 +にすべきところでないと +平気 +で +云 +うのだろう +僕 +もあんまりな +不人情 +な +男 +だと +思 +ったから +泥 +だらけの +手 +で +君 +の +写生帖 +を +引 +き +裂 +いてしまった +僕 +の +有望 +な +画才 +が +頓挫 +して +一向振 +わなくなったのも +全 +くあの +時 +からだ +君 +に +機鋒 +を +折 +られたのだね +僕 +は +君 +に +恨 +がある +馬鹿 +にしちゃいけない +こっちが +恨 +めしいくらいだ +迷亭 +はあの +時分 +から +法螺吹 +だったな +と +主人 +は +羊羹 +を +食 +い +了 +って +再 +び +二人 +の +話 +の +中 +に +割 +り +込 +んで +来 +る +約束 +なんか +履行 +した +事 +がない +それで +詰問 +を +受 +けると +決 +して +詫 +びた +事 +がない +何 +とか +蚊 +とか +云 +う +あの +寺 +の +境内 +に +百日紅 +が +咲 +いていた +時分 +この +百日紅 +が +散 +るまでに +美学原論 +と +云 +う +著述 +をすると +云 +うから +駄目 +だ +到底出来 +る +気遣 +はないと +云 +ったのさ +すると +迷亭 +の +答 +えに +僕 +はこう +見 +えても +見掛 +けに +寄 +らぬ +意志 +の +強 +い +男 +である +そんなに +疑 +うなら +賭 +をしようと +云 +うから +僕 +は +真面目 +に +受 +けて +何 +でも +神田 +の +西洋料理 +を +奢 +りっこかなにかに +極 +めた +きっと +書物 +なんか +書 +く +気遣 +はないと +思 +ったから +賭 +をしたようなものの +内心 +は +少々恐 +ろしかった +僕 +に +西洋料理 +なんか +奢 +る +金 +はないんだからな +ところが +先生一向稿 +を +起 +す +景色 +がない +七日立 +っても +二十日立 +っても +一枚 +も +書 +かない +いよいよ +百日紅 +が +散 +って +一輪 +の +花 +もなくなっても +当人平気 +でいるから +いよいよ +西洋料理 +に +有 +りついたなと +思 +って +契約履行 +を +逼 +ると +迷亭 +すまして +取 +り +合 +わない +また +何 +とか +理窟 +をつけたのかね +と +鈴木君 +が +相 +の +手 +を +入 +れる +うん +実 +にずうずうしい +男 +だ +吾輩 +はほかに +能 +はないが +意志 +だけは +決 +して +君方 +に +負 +けはせんと +剛情 +を +張 +るのさ +一枚 +も +書 +かんのにか +と +今度 +は +迷亭君自身 +が +質問 +をする +無論 +さ +その +時君 +はこう +云 +ったぜ +吾輩 +は +意志 +の +一点 +においてはあえて +何人 +にも +一歩 +も +譲 +らん +しかし +残念 +な +事 +には +記憶 +が +人一倍無 +い +美学原論 +を +著 +わそうとする +意志 +は +充分 +あったのだがその +意志 +を +君 +に +発表 +した +翌日 +から +忘 +れてしまった +それだから +百日紅 +の +散 +るまでに +著書 +が +出来 +なかったのは +記憶 +の +罪 +で +意志 +の +罪 +ではない +意志 +の +罪 +でない +以上 +は +西洋料理 +などを +奢 +る +理由 +がないと +威張 +っているのさ +なるほど +迷亭君一流 +の +特色 +を +発揮 +して +面白 +い +と +鈴木君 +はなぜだか +面白 +がっている +迷亭 +のおらぬ +時 +の +語気 +とはよほど +違 +っている +これが +利口 +な +人 +の +特色 +かも +知 +れない +何 +が +面白 +いものか +と +主人 +は +今 +でも +怒 +っている +様子 +である +それは +御気 +の +毒様 +それだからその +埋合 +せをするために +孔雀 +の +舌 +なんかを +金 +と +太鼓 +で +探 +しているじゃないか +まあそう +怒 +らずに +待 +っているさ +しかし +著書 +と +云 +えば +君 +今日 +は +一大珍報 +を +齎 +らして +来 +たんだよ +君 +はくるたびに +珍報 +を +齎 +らす +男 +だから +油断 +が +出来 +ん +ところが +今日 +の +珍報 +は +真 +の +珍報 +さ +正札付一厘 +も +引 +けなしの +珍報 +さ +君寒月 +が +博士論文 +の +稿 +を +起 +したのを +知 +っているか +寒月 +はあんな +妙 +に +見識張 +った +男 +だから +博士論文 +なんて +無趣味 +な +労力 +はやるまいと +思 +ったら +あれでやっぱり +色気 +があるからおかしいじゃないか +君 +あの +鼻 +に +是非通知 +してやるがいい +この +頃 +は +団栗博士 +の +夢 +でも +見 +ているかも +知 +れない +鈴木君 +は +寒月 +の +名 +を +聞 +いて +話 +してはいけぬ +話 +してはいけぬと +顋 +と +眼 +で +主人 +に +合図 +する +主人 +には +一向意味 +が +通 +じない +さっき +鈴木君 +に +逢 +って +説法 +を +受 +けた +時 +は +金田 +の +娘 +の +事 +ばかりが +気 +の +毒 +になったが +今迷亭 +から +鼻々 +と +云 +われるとまた +先日喧嘩 +をした +事 +を +思 +い +出 +す +思 +い +出 +すと +滑稽 +でもあり +また +少々 +は +悪 +らしくもなる +しかし +寒月 +が +博士論文 +を +草 +しかけたのは +何 +よりの +御見 +やげで +こればかりは +迷亭先生自賛 +のごとくまずまず +近来 +の +珍報 +である +啻 +に +珍報 +のみならず +嬉 +しい +快 +よい +珍報 +である +金田 +の +娘 +を +貰 +おうが +貰 +うまいがそんな +事 +はまずどうでもよい +とにかく +寒月 +の +博士 +になるのは +結構 +である +自分 +のように +出来損 +いの +木像 +は +仏師屋 +の +隅 +で +虫 +が +喰 +うまで +白木 +のまま +燻 +っていても +遺憾 +はないが +これは +旨 +く +仕上 +がったと +思 +う +彫刻 +には +一日 +も +早 +く +箔 +を +塗 +ってやりたい +本当 +に +論文 +を +書 +きかけたのか +と +鈴木君 +の +合図 +はそっち +除 +けにして +熱心 +に +聞 +く +よく +人 +の +云 +う +事 +を +疑 +ぐる +男 +だ +もっとも +問題 +は +団栗 +だか +首縊 +りの +力学 +だか +確 +と +分 +らんがね +とにかく +寒月 +の +事 +だから +鼻 +の +恐縮 +するようなものに +違 +いない +さっきから +迷亭 +が +鼻々 +と +無遠慮 +に +云 +うのを +聞 +くたんびに +鈴木君 +は +不安 +の +様子 +をする +迷亭 +は +少 +しも +気 +が +付 +かないから +平気 +なものである +その +後鼻 +についてまた +研究 +をしたが +この +頃 +トリストラム +シャンデ +の +中 +に +鼻論 +があるのを +発見 +した +金田 +の +鼻 +なども +スタ +ン +に +見 +せたら +善 +い +材料 +になったろうに +残念 +な +事 +だ +鼻名 +を +千載 +に +垂 +れる +資格 +は +充分 +ありながら +あのままで +朽 +ち +果 +つるとは +不憫千万 +だ +今度 +ここへ +来 +たら +美学上 +の +参考 +のために +写生 +してやろう +と +相変 +らず +口 +から +出任 +せに +喋舌 +り +立 +てる +しかしあの +娘 +は +寒月 +の +所 +へ +来 +たいのだそうだ +と +主人 +が +今鈴木君 +から +聞 +いた +通 +りを +述 +べると +鈴木君 +はこれは +迷惑 +だと +云 +う +顔付 +をしてしきりに +主人 +に +目 +くばせをするが +主人 +は +不導体 +のごとく +一向電気 +に +感染 +しない +ちょっと +乙 +だな +あんな +者 +の +子 +でも +恋 +をするところが +しかし +大 +した +恋 +じゃなかろう +大方鼻恋 +くらいなところだぜ +鼻恋 +でも +寒月 +が +貰 +えばいいが +貰 +えばいいがって +君 +は +先日大反対 +だったじゃないか +今日 +はいやに +軟化 +しているぜ +軟化 +はせん +僕 +は +決 +して +軟化 +はせんしかし +しかしどうかしたんだろう +ねえ +鈴木 +君 +も +実業家 +の +末席 +を +汚 +す +一人 +だから +参考 +のために +言 +って +聞 +かせるがね +あの +金田某 +なる +者 +さ +あの +某 +なるものの +息女 +などを +天下 +の +秀才水島寒月 +の +令夫人 +と +崇 +め +奉 +るのは +少々提灯 +と +釣鐘 +と +云 +う +次第 +で +我々朋友 +たる +者 +が +冷々黙過 +する +訳 +に +行 +かん +事 +だと +思 +うんだが +たとい +実業家 +の +君 +でもこれには +異存 +はあるまい +相変 +らず +元気 +がいいね +結構 +だ +君 +は +十年前 +と +容子 +が +少 +しも +変 +っていないからえらい +と +鈴木君 +は +柳 +に +受 +けて +胡麻化 +そうとする +えらいと +褒 +めるなら +もう +少 +し +博学 +なところを +御目 +にかけるがね +昔 +しの +希臘人 +は +非常 +に +体育 +を +重 +んじたものであらゆる +競技 +に +貴重 +なる +懸賞 +を +出 +して +百方奨励 +の +策 +を +講 +じたものだ +しかるに +不思議 +な +事 +には +学者 +の +智識 +に +対 +してのみは +何等 +の +褒美 +も +与 +えたと +云 +う +記録 +がなかったので +今日 +まで +実 +は +大 +に +怪 +しんでいたところさ +なるほど +少 +し +妙 +だね +と +鈴木君 +はどこまでも +調子 +を +合 +せる +しかるについ +両三日前 +に +至 +って +美学研究 +の +際 +ふとその +理由 +を +発見 +したので +多年 +の +疑団 +は +一度 +に +氷解 +漆桶 +を +抜 +くがごとく +痛快 +なる +悟 +りを +得 +て +歓天喜地 +の +至境 +に +達 +したのさ +あまり +迷亭 +の +言葉 +が +仰山 +なので +さすが +御上手者 +の +鈴木君 +も +こりゃ +手 +に +合 +わないと +云 +う +顔付 +をする +主人 +はまた +始 +まったなと +云 +わぬばかりに +象牙 +の +箸 +で +菓子皿 +の +縁 +をかんかん +叩 +いて +俯 +つ +向 +いている +迷亭 +だけは +大得意 +で +弁 +じつづける +そこでこの +矛盾 +なる +現象 +の +説明 +を +明記 +して +暗黒 +の +淵 +から +吾人 +の +疑 +を +千載 +の +下 +に +救 +い +出 +してくれた +者 +は +誰 +だと +思 +う +学問 +あって +以来 +の +学者 +と +称 +せらるる +彼 +の +希臘 +の +哲人 +逍遥派 +の +元祖 +アリスト +トル +その +人 +である +彼 +の +説明 +に +曰 +くさ +おい +菓子皿 +などを +叩 +かんで +謹聴 +していなくちゃいかん +彼等希臘人 +が +競技 +において +得 +るところの +賞与 +は +彼等 +が +演 +ずる +技芸 +その +物 +より +貴重 +なものである +それ +故 +に +褒美 +にもなり +奨励 +の +具 +ともなる +しかし +智識 +その +物 +に +至 +ってはどうである +もし +智識 +に +対 +する +報酬 +として +何物 +をか +与 +えんとするならば +智識以上 +の +価値 +あるものを +与 +えざるべからず +しかし +智識以上 +の +珍宝 +が +世 +の +中 +にあろうか +無論 +あるはずがない +下手 +なものをやれば +智識 +の +威厳 +を +損 +する +訳 +になるばかりだ +彼等 +は +智識 +に +対 +して +千両箱 +を +オリムパス +の +山 +ほど +積 +み +クリ +サス +の +富 +を +傾 +け +尽 +しても +相当 +の +報酬 +を +与 +えんとしたのであるが +いかに +考 +えても +到底釣 +り +合 +うはずがないと +云 +う +事 +を +観破 +して +それより +以来 +と +云 +うものは +奇麗 +さっぱり +何 +にもやらない +事 +にしてしまった +黄白青銭 +が +智識 +の +匹敵 +でない +事 +はこれで +十分理解出来 +るだろう +さてこの +原理 +を +服膺 +した +上 +で +時事問題 +に +臨 +んで +見 +るがいい +金田某 +は +何 +だい +紙幣 +に +眼鼻 +をつけただけの +人間 +じゃないか +奇警 +なる +語 +をもって +形容 +するならば +彼 +は +一個 +の +活動紙幣 +に +過 +ぎんのである +活動紙幣 +の +娘 +なら +活動切手 +くらいなところだろう +翻 +って +寒月君 +は +如何 +と +見 +ればどうだ +辱 +けなくも +学問最高 +の +府 +を +第一位 +に +卒業 +して +毫 +も +倦怠 +の +念 +なく +長州征伐時代 +の +羽織 +の +紐 +をぶら +下 +げて +日夜団栗 +の +スタビリチ +を +研究 +し +それでもなお +満足 +する +様子 +もなく +近々 +の +中 +ロ +ド +ケルヴィン +を +圧倒 +するほどな +大論文 +を +発表 +しようとしつつあるではないか +たまたま +吾妻橋 +を +通 +り +掛 +って +身投 +げの +芸 +を +仕損 +じた +事 +はあるが +これも +熱誠 +なる +青年 +に +有 +りがちの +発作的所為 +で +毫 +も +彼 +が +智識 +の +問屋 +たるに +煩 +いを +及 +ぼすほどの +出来事 +ではない +迷亭一流 +の +喩 +をもって +寒月君 +を +評 +すれば +彼 +は +活動図書館 +である +智識 +をもって +捏 +ね +上 +げたる +二十八珊 +の +弾丸 +である +この +弾丸 +が +一 +たび +時機 +を +得 +て +学界 +に +爆発 +するなら +もし +爆発 +して +見給 +え +爆発 +するだろう +迷亭 +はここに +至 +って +迷亭一流 +と +自称 +する +形容詞 +が +思 +うように +出 +て +来 +ないので +俗 +に +云 +う +竜頭蛇尾 +の +感 +に +多少 +ひるんで +見 +えたがたちまち +活動切手 +などは +何千万枚 +あったって +粉 +な +微塵 +になってしまうさ +それだから +寒月 +には +あんな +釣 +り +合 +わない +女性 +は +駄目 +だ +僕 +が +不承知 +だ +百獣 +の +中 +でもっとも +聡明 +なる +大象 +と +もっとも +貪婪 +なる +小豚 +と +結婚 +するようなものだ +そうだろう +苦沙弥君 +と +云 +って +退 +けると +主人 +はまた +黙 +って +菓子皿 +を +叩 +き +出 +す +鈴木君 +は +少 +し +凹 +んだ +気味 +で +そんな +事 +も +無 +かろう +と +術 +なげに +答 +える +さっきまで +迷亭 +の +悪口 +を +随分 +ついた +揚句 +ここで +無暗 +な +事 +を +云 +うと +主人 +のような +無法者 +はどんな +事 +を +素 +っ +破抜 +くか +知 +れない +なるべくここは +好加減 +に +迷亭 +の +鋭鋒 +をあしらって +無事 +に +切 +り +抜 +けるのが +上分別 +なのである +鈴木君 +は +利口者 +である +いらざる +抵抗 +は +避 +けらるるだけ +避 +けるのが +当世 +で +無要 +の +口論 +は +封建時代 +の +遺物 +と +心得 +ている +人生 +の +目的 +は +口舌 +ではない +実行 +にある +自己 +の +思 +い +通 +りに +着々事件 +が +進捗 +すれば +それで +人生 +の +目的 +は +達 +せられたのである +苦労 +と +心配 +と +争論 +とがなくて +事件 +が +進捗 +すれば +人生 +の +目的 +は +極楽流 +に +達 +せられるのである +鈴木君 +は +卒業後 +この +極楽主義 +によって +成功 +し +この +極楽主義 +によって +金時計 +をぶら +下 +げ +この +極楽主義 +で +金田夫婦 +の +依頼 +をうけ +同 +じくこの +極楽主義 +でまんまと +首尾 +よく +苦沙弥君 +を +説 +き +落 +して +当該事件 +が +十中八九 +まで +成就 +したところへ +迷亭 +なる +常規 +をもって +律 +すべからざる +普通 +の +人間以外 +の +心理作用 +を +有 +するかと +怪 +まるる +風来坊 +が +飛 +び +込 +んで +来 +たので +少々 +その +突然 +なるに +面喰 +っているところである +極楽主義 +を +発明 +したものは +明治 +の +紳士 +で +極楽主義 +を +実行 +するものは +鈴木藤十郎君 +で +今 +この +極楽主義 +で +困却 +しつつあるものもまた +鈴木藤十郎君 +である +君 +は +何 +にも +知 +らんからそうでもなかろうなどと +澄 +し +返 +って +例 +になく +言葉寡 +なに +上品 +に +控 +え +込 +むが +せんだってあの +鼻 +の +主 +が +来 +た +時 +の +容子 +を +見 +たらいかに +実業家贔負 +の +尊公 +でも +辟易 +するに +極 +ってるよ +ねえ +苦沙弥君 +君大 +に +奮闘 +したじゃないか +それでも +君 +より +僕 +の +方 +が +評判 +がいいそうだ +アハハハ +なかなか +自信 +が +強 +い +男 +だ +それでなくては +サヴェジ +チ +なんて +生徒 +や +教師 +にからかわれてすまして +学校 +へ +出 +ちゃいられん +訳 +だ +僕 +も +意志 +は +決 +して +人 +に +劣 +らんつもりだが +そんなに +図太 +くは +出来 +ん +敬服 +の +至 +りだ +生徒 +や +教師 +が +少々愚図愚図言 +ったって +何 +が +恐 +ろしいものか +サントブ +ヴ +は +古今独歩 +の +で diff --git a/src/OT/Layout/GPOS/CursivePosFormat1.hh b/src/OT/Layout/GPOS/CursivePosFormat1.hh index e3888c555..b886ebccb 100644 --- a/src/OT/Layout/GPOS/CursivePosFormat1.hh +++ b/src/OT/Layout/GPOS/CursivePosFormat1.hh @@ -138,6 +138,9 @@ struct CursivePosFormat1 void collect_glyphs (hb_collect_glyphs_context_t *c) const { if (unlikely (!(this+coverage).collect_coverage (c->input))) return; } + void collect_second_glyphs (hb_set_digest_t *digest) const + { (this+coverage).collect_coverage (digest); } + const Coverage &get_coverage () const { return this+coverage; } bool apply (hb_ot_apply_context_t *c) const diff --git a/src/OT/Layout/GPOS/MarkBasePosFormat1.hh b/src/OT/Layout/GPOS/MarkBasePosFormat1.hh index c13dc65d4..e88bea9b7 100644 --- a/src/OT/Layout/GPOS/MarkBasePosFormat1.hh +++ b/src/OT/Layout/GPOS/MarkBasePosFormat1.hh @@ -88,6 +88,9 @@ struct MarkBasePosFormat1_2 if (unlikely (!(this+baseCoverage).collect_coverage (c->input))) return; } + void collect_second_glyphs (hb_set_digest_t *digest) const + { (this+baseCoverage).collect_coverage (digest); } + const Coverage &get_coverage () const { return this+markCoverage; } static inline bool accept (hb_buffer_t *buffer, unsigned idx) diff --git a/src/OT/Layout/GPOS/MarkLigPosFormat1.hh b/src/OT/Layout/GPOS/MarkLigPosFormat1.hh index 5b1a93e38..e6a4ef4ef 100644 --- a/src/OT/Layout/GPOS/MarkLigPosFormat1.hh +++ b/src/OT/Layout/GPOS/MarkLigPosFormat1.hh @@ -90,6 +90,9 @@ struct MarkLigPosFormat1_2 if (unlikely (!(this+ligatureCoverage).collect_coverage (c->input))) return; } + void collect_second_glyphs (hb_set_digest_t *digest) const + { (this+ligatureCoverage).collect_coverage (digest); } + const Coverage &get_coverage () const { return this+markCoverage; } static inline bool accept (hb_buffer_t *buffer, unsigned idx) diff --git a/src/OT/Layout/GPOS/MarkMarkPosFormat1.hh b/src/OT/Layout/GPOS/MarkMarkPosFormat1.hh index 3221704ca..7e62d3844 100644 --- a/src/OT/Layout/GPOS/MarkMarkPosFormat1.hh +++ b/src/OT/Layout/GPOS/MarkMarkPosFormat1.hh @@ -90,6 +90,9 @@ struct MarkMarkPosFormat1_2 if (unlikely (!(this+mark2Coverage).collect_coverage (c->input))) return; } + void collect_second_glyphs (hb_set_digest_t *digest) const + { (this+mark2Coverage).collect_coverage (digest); } + const Coverage &get_coverage () const { return this+mark1Coverage; } bool apply (hb_ot_apply_context_t *c) const diff --git a/src/OT/Layout/GPOS/PairPosFormat1.hh b/src/OT/Layout/GPOS/PairPosFormat1.hh index a8ded1e75..de1f036bc 100644 --- a/src/OT/Layout/GPOS/PairPosFormat1.hh +++ b/src/OT/Layout/GPOS/PairPosFormat1.hh @@ -101,18 +101,35 @@ struct PairPosFormat1_3 (this+pairSet[i]).collect_glyphs (c, valueFormat); } + void collect_second_glyphs (hb_set_digest_t *digest) const + { + unsigned count = pairSet.len; + for (unsigned i = 0; i < count; i++) + (this+pairSet[i]).collect_second_glyphs (digest, valueFormat); + } + const Coverage &get_coverage () const { return this+coverage; } struct external_cache_t { hb_ot_layout_mapping_cache_t coverage; + hb_set_digest_t pair_sets[HB_VAR_ARRAY]; }; void *external_cache_create () const { - external_cache_t *cache = (external_cache_t *) hb_malloc (sizeof (external_cache_t)); + unsigned count = pairSet.len; + unsigned size = sizeof (external_cache_t) - + HB_VAR_ARRAY * sizeof (hb_set_digest_t) + + count * sizeof (hb_set_digest_t); + external_cache_t *cache = (external_cache_t *) hb_malloc (size); if (likely (cache)) { cache->coverage.clear (); + for (unsigned i = 0; i < count; i++) + { + cache->pair_sets[i].init (); + (this+pairSet[i]).collect_second_glyphs (&cache->pair_sets[i], valueFormat); + } } return cache; } @@ -140,6 +157,16 @@ struct PairPosFormat1_3 return_trace (false); } +#ifndef HB_NO_OT_LAYOUT_LOOKUP_CACHE + if (cache && + index < pairSet.len && + !cache->pair_sets[index].may_have (buffer->info[skippy_iter.idx].codepoint)) + { + buffer->unsafe_to_concat (buffer->idx, skippy_iter.idx + 1); + return_trace (false); + } +#endif + return_trace ((this+pairSet[index]).apply (c, valueFormat, skippy_iter.idx)); } diff --git a/src/OT/Layout/GPOS/PairSet.hh b/src/OT/Layout/GPOS/PairSet.hh index 46718ea7f..b1936ed4d 100644 --- a/src/OT/Layout/GPOS/PairSet.hh +++ b/src/OT/Layout/GPOS/PairSet.hh @@ -84,6 +84,15 @@ struct PairSet : ValueBase c->input->add_array (&record->secondGlyph, len, record_size); } + template + void collect_second_glyphs (set_t *glyphs, + const ValueFormat *valueFormats) const + { + unsigned record_size = get_size (valueFormats); + const PairValueRecord *record = &firstPairValueRecord; + glyphs->add_array (&record->secondGlyph, len, record_size); + } + void collect_variation_indices (hb_collect_variation_indices_context_t *c, const ValueFormat *valueFormats) const { @@ -143,6 +152,9 @@ struct PairSet : ValueBase if (applied_first || applied_second) buffer->unsafe_to_break (buffer->idx, pos + 1); + else + /* Even a zero-valued pair record is a concat hazard. */ + buffer->unsafe_to_concat (buffer->idx, pos + 1); if (len2) { diff --git a/src/OT/Layout/GSUB/LigatureSet.hh b/src/OT/Layout/GSUB/LigatureSet.hh index cefae5d40..143b9a579 100644 --- a/src/OT/Layout/GSUB/LigatureSet.hh +++ b/src/OT/Layout/GSUB/LigatureSet.hh @@ -136,7 +136,10 @@ struct LigatureSet goto slow; if (seconds && !seconds->may_have (second)) + { + c->buffer->unsafe_to_concat (c->buffer->idx, unsafe_to); return_trace (false); + } bool unsafe_to_concat = false; for (unsigned int i = 0; i < num_ligs; i++) { diff --git a/src/OT/Layout/GSUB/LigatureSubstFormat1.hh b/src/OT/Layout/GSUB/LigatureSubstFormat1.hh index 759517ee8..4ec2676bf 100644 --- a/src/OT/Layout/GSUB/LigatureSubstFormat1.hh +++ b/src/OT/Layout/GSUB/LigatureSubstFormat1.hh @@ -79,6 +79,14 @@ struct LigatureSubstFormat1_2 ; } + void collect_second_glyphs (hb_set_digest_t *digest) const + { + + hb_iter (ligatureSet) + | hb_map (hb_add (this)) + | hb_apply ([digest] (const LigatureSet &_) { _.collect_seconds (*digest); }) + ; + } + const Coverage &get_coverage () const { return this+coverage; } bool would_apply (hb_would_apply_context_t *c) const diff --git a/src/OT/Var/VARC/VARC.cc b/src/OT/Var/VARC/VARC.cc index b001d3923..390ad6f49 100644 --- a/src/OT/Var/VARC/VARC.cc +++ b/src/OT/Var/VARC/VARC.cc @@ -33,7 +33,8 @@ VarComponent::decompile_record (const VARC &varc, hb_ubytes_t total_record, hb_vector_t *axis_indices, hb_vector_t *axis_values, - record_t *decoded) + record_t *decoded, + int64_t *budget) { const unsigned char *start = total_record.arrayZ; const unsigned char *record = start; @@ -94,6 +95,9 @@ VarComponent::decompile_record (const VARC &varc, } else axis_count = hb_len ((&varc+varc.axisIndicesList)[decoded->axis_indices_index]); + if (unlikely (budget && axis_count && + !hb_budget_spend (*budget, HB_BUDGET_1, axis_count))) + return false; if (axis_values) { if (unlikely (!axis_values->resize (axis_count))) return false; @@ -201,6 +205,7 @@ struct hb_transforming_pen_context_t hb_draw_funcs_t *dfuncs; void *data; hb_draw_state_t *st; + int64_t *budget_remaining; }; static void @@ -276,6 +281,12 @@ hb_transforming_pen_close_path (hb_draw_funcs_t *dfuncs HB_UNUSED, c->dfuncs->close_path (c->data, *c->st); } +static int64_t * +hb_transforming_pen_get_budget_remaining (hb_draw_funcs_t *, void *draw_data, void *) +{ + return ((hb_transforming_pen_context_t *) draw_data)->budget_remaining; +} + static inline void free_static_transforming_pen_funcs (); static struct hb_transforming_pen_funcs_lazy_loader_t : hb_draw_funcs_lazy_loader_t @@ -289,6 +300,7 @@ static struct hb_transforming_pen_funcs_lazy_loader_t : hb_draw_funcs_lazy_loade hb_draw_funcs_set_quadratic_to_func (funcs, hb_transforming_pen_quadratic_to, nullptr, nullptr); hb_draw_funcs_set_cubic_to_func (funcs, hb_transforming_pen_cubic_to, nullptr, nullptr); hb_draw_funcs_set_close_path_func (funcs, hb_transforming_pen_close_path, nullptr, nullptr); + hb_draw_funcs_set_get_budget_remaining_func (funcs, hb_transforming_pen_get_budget_remaining, nullptr, nullptr); hb_draw_funcs_make_immutable (funcs); @@ -318,6 +330,9 @@ VarComponent::get_path_at (const hb_varc_context_t &c, hb_ubytes_t total_record, hb_scalar_cache_t *cache) const { + if (unlikely (!hb_budget_spend (c.budget, HB_BUDGET_4))) + return hb_ubytes_t (); + const unsigned char *end = total_record.arrayZ + total_record.length; auto &VARC = *c.font->face->table.VARC->table; auto &varStore = &VARC+VARC.varStore; @@ -326,7 +341,8 @@ VarComponent::get_path_at (const hb_varc_context_t &c, auto &axisValues = c.scratch.axisValues; record_t component; if (unlikely (!decompile_record (VARC, total_record, - &axisIndices, &axisValues, &component))) + &axisIndices, &axisValues, &component, + &c.budget))) return hb_ubytes_t (); uint32_t flags = component.flags; @@ -347,8 +363,13 @@ VarComponent::get_path_at (const hb_varc_context_t &c, // Apply variations if any if ((flags & (unsigned) flags_t::AXIS_VALUES_HAVE_VARIATION) && show && coords && !axisValues.in_error ()) + { + if (unlikely (!hb_budget_spend (c.budget, axisValues.length, + coords.length))) + return hb_ubytes_t (); varStore.get_delta (component.axis_values_var_idx, coords, axisValues.as_array (), cache); + } auto component_coords = coords; /* Copying coords is expensive; so we have put an arbitrary @@ -363,6 +384,10 @@ VarComponent::get_path_at (const hb_varc_context_t &c, if (show) { // Only use coord_setter if there's actually any axis overrides. + if (unlikely (axisIndices && + !hb_budget_spend (c.budget, HB_BUDGET_1, + component_coords.length))) + return hb_ubytes_t (); coord_setter_t coord_setter (axisIndices ? component_coords : hb_array ()); for (unsigned i = 0; i < axisIndices.length; i++) coord_setter[axisIndices[i]] = roundf (axisValues[i]); @@ -379,6 +404,9 @@ VarComponent::get_path_at (const hb_varc_context_t &c, transformValues[numTransformValues++] = transform.name; VARC_PROCESS_TRANSFORM_COMPONENTS; #undef PROCESS_TRANSFORM_COMPONENT + if (unlikely (!hb_budget_spend (c.budget, numTransformValues, + coords.length))) + return hb_ubytes_t (); varStore.get_delta (transformVarIdx, coords, hb_array (transformValues, numTransformValues), cache); numTransformValues = 0; #define PROCESS_TRANSFORM_COMPONENT(shift, type, flag, name) \ @@ -436,8 +464,7 @@ VARC::get_path_at (const hb_varc_context_t &c, { /* Out of budget: draw nothing, but signal success so remaining * leaves are skipped instead of falling back per-glyph. */ - if (unlikely (c.budget_left <= 0)) return true; - c.budget_left--; + if (unlikely (!hb_budget_spend (c.budget, HB_BUDGET_1))) return true; hb_transform_t<> leaf_transform = transform; leaf_transform.x0 *= c.font->x_multf; @@ -448,27 +475,27 @@ VARC::get_path_at (const hb_varc_context_t &c, hb_transforming_pen_context_t context {leaf_transform, c.draw_session->funcs, c.draw_session->draw_data, - &c.draw_session->st}; + &c.draw_session->st, + &c.budget}; hb_draw_session_t transformer_session {transformer_funcs, &context}; hb_draw_session_t &shape_draw_session = leaf_transform.is_identity () ? *c.draw_session : transformer_session; - if (c.font->face->table.glyf->get_path_at (c.font, glyph, shape_draw_session, coords, c.scratch.glyf_scratch, nullptr, &c.budget_left)) return true; + if (c.font->face->table.glyf->get_path_at (c.font, glyph, shape_draw_session, coords, c.scratch.glyf_scratch, nullptr, &shape_draw_session.get_budget ())) return true; #ifndef HB_NO_CFF - if (c.font->face->table.cff2->get_path_at (c.font, glyph, shape_draw_session, coords, &c.budget_left)) return true; - if (c.font->face->table.cff1->get_path (c.font, glyph, shape_draw_session, &c.budget_left)) return true; // Doesn't have variations + if (c.font->face->table.cff2->get_path_at (c.font, glyph, shape_draw_session, coords, &shape_draw_session.get_budget ())) return true; + if (c.font->face->table.cff1->get_path (c.font, glyph, shape_draw_session, &shape_draw_session.get_budget ())) return true; // Doesn't have variations #endif return false; } else if (c.extents) { - if (unlikely (c.budget_left <= 0)) return true; - c.budget_left--; + if (unlikely (!hb_budget_spend (c.budget, HB_BUDGET_1))) return true; hb_glyph_extents_t glyph_extents; - if (!c.font->face->table.glyf->get_extents_at (c.font, glyph, &glyph_extents, coords, &c.budget_left)) + if (!c.font->face->table.glyf->get_extents_at (c.font, glyph, &glyph_extents, coords, &c.budget)) #ifndef HB_NO_CFF - if (!c.font->face->table.cff2->get_extents_at (c.font, glyph, &glyph_extents, coords, &c.budget_left)) - if (!c.font->face->table.cff1->get_extents (c.font, glyph, &glyph_extents, &c.budget_left)) // Doesn't have variations + if (!c.font->face->table.cff2->get_extents_at (c.font, glyph, &glyph_extents, coords, &c.budget)) + if (!c.font->face->table.cff1->get_extents (c.font, glyph, &glyph_extents, &c.budget)) // Doesn't have variations #endif return false; diff --git a/src/OT/Var/VARC/VARC.hh b/src/OT/Var/VARC/VARC.hh index 1ece8d82c..17f0da3c0 100644 --- a/src/OT/Var/VARC/VARC.hh +++ b/src/OT/Var/VARC/VARC.hh @@ -38,10 +38,9 @@ struct hb_varc_context_t mutable hb_decycler_t decycler; mutable signed edges_left; mutable signed depth_left; - /* Work budget shared by all leaf glyphs loaded from glyf/CFF/CFF2, - * so their per-glyph work limits cannot multiply with our own - * composite-graph limits. */ - mutable int64_t budget_left; + /* Renderer-owned live budget, shared by VARC record processing and + * every leaf loaded from glyf/CFF/CFF2. */ + int64_t &budget; hb_varc_scratch_t &scratch; }; @@ -103,7 +102,8 @@ struct VarComponent hb_ubytes_t record, hb_vector_t *axis_indices, hb_vector_t *axis_values, - record_t *decoded /* OUT */); + record_t *decoded /* OUT */, + int64_t *budget = nullptr); }; struct VarCompositeGlyph @@ -154,13 +154,14 @@ struct VARC hb_draw_session_t &draw_session, hb_varc_scratch_t &scratch) const { + int64_t &budget = draw_session.get_budget (); hb_varc_context_t c {font, &draw_session, nullptr, hb_decycler_t {}, HB_MAX_GRAPH_EDGE_COUNT, HB_MAX_NESTING_LEVEL, - HB_VARC_MAX_WORK, + budget, scratch}; return get_path_at (c, gid, @@ -173,13 +174,14 @@ struct VARC hb_extents_t<> *extents, hb_varc_scratch_t &scratch) const { + int64_t budget = HB_BUDGET_GLYPH; hb_varc_context_t c {font, nullptr, extents, hb_decycler_t {}, HB_MAX_GRAPH_EDGE_COUNT, HB_MAX_NESTING_LEVEL, - HB_VARC_MAX_WORK, + budget, scratch}; return get_path_at (c, gid, diff --git a/src/OT/glyf/Glyph.hh b/src/OT/glyf/Glyph.hh index 83d3eaed0..1376d5386 100644 --- a/src/OT/glyf/Glyph.hh +++ b/src/OT/glyf/Glyph.hh @@ -314,7 +314,8 @@ struct Glyph hb_array_t coords = hb_array_t (), hb_scalar_cache_t *gvar_cache = nullptr, unsigned int depth = 0, - unsigned *edge_count = nullptr) const + unsigned *edge_count = nullptr, + int64_t *budget = nullptr) const { if (unlikely (depth > HB_MAX_NESTING_LEVEL)) return false; unsigned stack_edge_count = 0; @@ -322,6 +323,10 @@ struct Glyph if (unlikely (*edge_count > HB_MAX_GRAPH_EDGE_COUNT)) return false; (*edge_count)++; + int64_t stack_budget = HB_BUDGET_GLYPH; + if (!budget) budget = &stack_budget; + if (unlikely (!hb_budget_spend (*budget, HB_BUDGET_16))) return false; + if (head_maxp_info) { head_maxp_info->maxComponentDepth = hb_max (head_maxp_info->maxComponentDepth, depth); @@ -390,7 +395,8 @@ struct Glyph points.as_array ().sub_array (old_length), scratch, gvar_cache, - phantom_only && type == SIMPLE)) + phantom_only && type == SIMPLE, + budget)) return false; } else @@ -400,7 +406,8 @@ struct Glyph points.as_array ().sub_array (old_length), scratch, gvar_cache, - phantom_only && type == SIMPLE)) + phantom_only && type == SIMPLE, + budget)) return false; } #endif @@ -452,7 +459,8 @@ struct Glyph coords, gvar_cache, depth + 1, - edge_count))) + edge_count, + budget))) { points.resize (old_length); return false; diff --git a/src/OT/glyf/glyf.hh b/src/OT/glyf/glyf.hh index ce563977a..bb92d0f60 100644 --- a/src/OT/glyf/glyf.hh +++ b/src/OT/glyf/glyf.hh @@ -238,15 +238,22 @@ struct glyf_accelerator_t bool get_points (hb_font_t *font, hb_codepoint_t gid, T consumer, hb_array_t coords, hb_glyf_scratch_t &scratch, - hb_scalar_cache_t *gvar_cache = nullptr) const + hb_scalar_cache_t *gvar_cache = nullptr, + int64_t *budget = nullptr) const { if (gid >= num_glyphs) return false; + int64_t stack_budget = HB_BUDGET_GLYPH; + if (!budget) budget = &stack_budget; + auto &all_points = scratch.all_points; all_points.clear (); bool phantom_only = !consumer.is_consuming_contour_points (); - if (unlikely (!glyph_for_gid (gid).get_points (font, *this, all_points, scratch, nullptr, nullptr, nullptr, true, true, phantom_only, coords, gvar_cache))) + if (unlikely (!glyph_for_gid (gid).get_points (font, *this, all_points, scratch, nullptr, nullptr, nullptr, true, true, phantom_only, coords, gvar_cache, 0, nullptr, budget))) + return false; + + if (unlikely (!hb_budget_spend (*budget, HB_BUDGET_1, all_points.length))) return false; unsigned count = all_points.length; @@ -470,8 +477,9 @@ struct glyf_accelerator_t gid, points_aggregator_t (font, extents, nullptr, true), coords, - *scratch); - if (budget) *budget -= scratch->all_points.length; + *scratch, + nullptr, + budget); release_scratch (scratch); return ret; } @@ -508,7 +516,9 @@ struct glyf_accelerator_t } bool - get_path (hb_font_t *font, hb_codepoint_t gid, hb_draw_session_t &draw_session, hb_scalar_cache_t *gvar_cache = nullptr) const + get_path (hb_font_t *font, hb_codepoint_t gid, hb_draw_session_t &draw_session, + hb_scalar_cache_t *gvar_cache = nullptr, + int64_t *budget = nullptr) const { if (!has_data ()) return false; @@ -519,7 +529,8 @@ struct glyf_accelerator_t hb_array (font->coords, font->has_nonzero_coords ? font->num_coords : 0), *scratch, - gvar_cache); + gvar_cache, + budget); release_scratch (scratch); @@ -537,8 +548,8 @@ struct glyf_accelerator_t bool ret = get_points (font, gid, glyf_impl::path_builder_t (font, draw_session), coords, scratch, - gvar_cache); - if (budget) *budget -= scratch.all_points.length; + gvar_cache, + budget); return ret; } diff --git a/src/gen-use-table.py b/src/gen-use-table.py index bd930f6c9..3e64700e9 100755 --- a/src/gen-use-table.py +++ b/src/gen-use-table.py @@ -408,7 +408,7 @@ def map_to_use(data): if U in [0x11302, 0x11303, 0x114C1]: UIPC = Top assert (UIPC in [Not_Applicable, Visual_Order_Left] or - U in {0x0F7F, 0x11A3A} or + U == 0x0F7F or USE in use_positions), "%s %s %s %s %s %s %s" % (hex(U), UIPC, USE, UISC, UDI, UGC, AJT) pos_mapping = use_positions.get(USE, None) diff --git a/src/graph/classdef-graph.hh b/src/graph/classdef-graph.hh index fa604c90e..2f071214d 100644 --- a/src/graph/classdef-graph.hh +++ b/src/graph/classdef-graph.hh @@ -26,6 +26,7 @@ #include "graph.hh" #include "../hb-ot-layout-common.hh" +#include "graph-result.hh" #ifndef GRAPH_CLASSDEF_GRAPH_HH #define GRAPH_CLASSDEF_GRAPH_HH @@ -34,88 +35,99 @@ namespace graph { struct ClassDefFormat1 : public OT::ClassDefFormat1_3 { - bool sanitize (const graph_t::vertex_t& vertex) const + graph_result_t sanitize (const graph_t::vertex_t& vertex) const { - size_t vertex_len = vertex.obj.tail - vertex.obj.head; + size_t vertex_len = vertex.table_size(); constexpr unsigned min_size = OT::ClassDefFormat1_3::min_size; - if (vertex_len < min_size) return false; + if (unlikely (vertex_len < min_size)) return Err(SANITIZE_FAILURE); hb_barrier (); - return vertex_len >= min_size + classValue.get_size () - classValue.len.get_size (); + if (unlikely (vertex_len < min_size + classValue.get_size () - classValue.len.get_size ())) + return Err(SANITIZE_FAILURE); + return Ok(); } }; struct ClassDefFormat2 : public OT::ClassDefFormat2_4 { - bool sanitize (const graph_t::vertex_t& vertex) const + graph_result_t sanitize (const graph_t::vertex_t& vertex) const { - size_t vertex_len = vertex.obj.tail - vertex.obj.head; + size_t vertex_len = vertex.table_size(); constexpr unsigned min_size = OT::ClassDefFormat2_4::min_size; - if (vertex_len < min_size) return false; + if (unlikely (vertex_len < min_size)) return Err(SANITIZE_FAILURE); hb_barrier (); - return vertex_len >= min_size + rangeRecord.get_size () - rangeRecord.len.get_size (); + if (unlikely (vertex_len < min_size + rangeRecord.get_size () - rangeRecord.len.get_size ())) + return Err(SANITIZE_FAILURE); + return Ok(); } }; struct ClassDef : public OT::ClassDef { template - static bool add_class_def (gsubgpos_graph_context_t& c, - unsigned parent_id, - unsigned link_position, - It glyph_and_class, - unsigned max_size) + static graph_result_t add_class_def (gsubgpos_graph_context_t& c, + unsigned parent_id, + unsigned link_position, + It glyph_and_class, + unsigned max_size) { - unsigned class_def_prime_id = c.graph.new_node (nullptr, nullptr); + TRY_ASSIGN (unsigned class_def_prime_id, c.graph.new_node (nullptr, nullptr)); auto& class_def_prime_vertex = c.graph.vertices_[class_def_prime_id]; - if (!make_class_def (c, glyph_and_class, class_def_prime_id, max_size)) - return false; + TRY (make_class_def (c, glyph_and_class, class_def_prime_id, max_size)); - auto* class_def_link = c.graph.vertices_[parent_id].obj.real_links.push (); - class_def_link->width = SmallTypes::size; - class_def_link->objidx = class_def_prime_id; - class_def_link->position = link_position; - class_def_prime_vertex.add_parent (parent_id, false); + TRY(c.graph.vertices_[parent_id].add_real_link (SmallTypes::size, class_def_prime_id, link_position)); + TRY(class_def_prime_vertex.add_parent (parent_id, false)); - return true; + return Ok(); } template - static bool make_class_def (gsubgpos_graph_context_t& c, - It glyph_and_class, - unsigned dest_obj, - unsigned max_size) + static graph_result_t make_class_def (gsubgpos_graph_context_t& c, + It glyph_and_class, + unsigned dest_obj, + unsigned max_size) { char* buffer = (char*) hb_calloc (1, max_size); + if (unlikely (!buffer)) + return Err(ALLOCATION_FAILURE); + hb_serialize_context_t serializer (buffer, max_size); OT::ClassDef_serialize (&serializer, glyph_and_class); serializer.end_serialize (); - if (serializer.in_error ()) + if (unlikely (serializer.in_error ())) { hb_free (buffer); - return false; + return Err(ALLOCATION_FAILURE); } hb_bytes_t class_def_copy = serializer.copy_bytes (); - if (!class_def_copy.arrayZ) return false; - // Give ownership to the context, it will cleanup the buffer. - if (!c.add_buffer ((char *) class_def_copy.arrayZ)) + if (unlikely (!class_def_copy.arrayZ)) { - hb_free ((char *) class_def_copy.arrayZ); - return false; + hb_free (buffer); + return Err(ALLOCATION_FAILURE); } - auto& obj = c.graph.vertices_[dest_obj].obj; - obj.head = (char *) class_def_copy.arrayZ; - obj.tail = obj.head + class_def_copy.length; + // Give ownership to the context, it will cleanup the buffer. + auto res = c.add_buffer ((char *) class_def_copy.arrayZ); + if (unlikely (!res.is_ok ())) + { + hb_free (buffer); + hb_free ((char *) class_def_copy.arrayZ); + return res; + } + + + auto& v = c.graph.vertices_[dest_obj]; + char* head = (char *) class_def_copy.arrayZ; + v.set_buffer (head, head + class_def_copy.length); hb_free (buffer); - return true; + return Ok(); } - bool sanitize (const graph_t::vertex_t& vertex) const + graph_result_t sanitize (const graph_t::vertex_t& vertex) const { - size_t vertex_len = vertex.obj.tail - vertex.obj.head; - if (vertex_len < OT::ClassDef::min_size) return false; + size_t vertex_len = vertex.table_size(); + if (unlikely (vertex_len < OT::ClassDef::min_size)) return Err(SANITIZE_FAILURE); hb_barrier (); switch (u.format.v) { @@ -126,7 +138,7 @@ struct ClassDef : public OT::ClassDef case 3: case 4: #endif - default: return false; + default: return Err(SANITIZE_FAILURE); } } }; @@ -142,33 +154,33 @@ struct class_def_size_estimator_t constexpr static unsigned bytes_per_glyph = 2; template - class_def_size_estimator_t (It glyph_and_class) - : num_ranges_per_class (), glyphs_per_class () + static graph_result_t create (It glyph_and_class) { - reset(); + class_def_size_estimator_t estimator; + estimator.reset(); for (auto p : + glyph_and_class) { unsigned gid = p.first; unsigned klass = p.second; hb_set_t* glyphs; - if (glyphs_per_class.has (klass, &glyphs) && glyphs) { + if (estimator.glyphs_per_class.has (klass, &glyphs) && glyphs) { glyphs->add (gid); continue; } hb_set_t new_glyphs; new_glyphs.add (gid); - glyphs_per_class.set (klass, std::move (new_glyphs)); + estimator.glyphs_per_class.set (klass, std::move (new_glyphs)); } - if (in_error ()) return; + TRY(estimator.to_result ()); - for (unsigned klass : glyphs_per_class.keys ()) + for (unsigned klass : estimator.glyphs_per_class.keys ()) { if (!klass) continue; // class 0 doesn't get encoded. - const hb_set_t& glyphs = glyphs_per_class.get (klass); + const hb_set_t& glyphs = estimator.glyphs_per_class.get (klass); hb_codepoint_t start = HB_SET_VALUE_INVALID; hb_codepoint_t end = HB_SET_VALUE_INVALID; @@ -176,23 +188,25 @@ struct class_def_size_estimator_t while (glyphs.next_range (&start, &end)) count++; - num_ranges_per_class.set (klass, count); + estimator.num_ranges_per_class.set (klass, count); } + + TRY(estimator.to_result ()); + return estimator; } void reset() { class_def_1_size = class_def_format1_base_size; class_def_2_size = class_def_format2_base_size; + coverage_size_val = coverage_base_size; included_glyphs.clear(); included_classes.clear(); } - // Compute the size of coverage for all glyphs added via 'add_class_def_size'. + // Size of coverage for all glyphs added via 'add_class_def_size'. unsigned coverage_size () const { - unsigned format1_size = coverage_base_size + bytes_per_glyph * included_glyphs.get_population(); - unsigned format2_size = coverage_base_size + bytes_per_range * num_glyph_ranges(); - return hb_min(format1_size, format2_size); + return coverage_size_val; } // Compute the new size of the ClassDef table if all glyphs associated with 'klass' were added. @@ -201,7 +215,10 @@ struct class_def_size_estimator_t if (!included_classes.has(klass)) { hb_set_t* glyphs = nullptr; if (glyphs_per_class.has(klass, &glyphs)) { + unsigned num_glyphs = included_glyphs.get_population(); included_glyphs.union_(*glyphs); + if (num_glyphs != included_glyphs.get_population()) + coverage_size_val = compute_coverage_size (); } class_def_1_size = class_def_format1_base_size; @@ -230,25 +247,36 @@ struct class_def_size_estimator_t return count; } - bool in_error () + private: + graph_result_t to_result() const { - if (num_ranges_per_class.in_error ()) return true; - if (glyphs_per_class.in_error ()) return true; + TRY (graph_result_t::from (num_ranges_per_class, ALLOCATION_FAILURE)); + TRY (graph_result_t::from (glyphs_per_class, ALLOCATION_FAILURE)); for (const hb_set_t& s : glyphs_per_class.values ()) { - if (s.in_error ()) return true; + TRY (graph_result_t::from (s, ALLOCATION_FAILURE)); } - return false; + return Ok(); + } + + class_def_size_estimator_t () + : num_ranges_per_class (), glyphs_per_class () {} + + unsigned compute_coverage_size () const + { + unsigned format1_size = coverage_base_size + bytes_per_glyph * included_glyphs.get_population(); + unsigned format2_size = coverage_base_size + bytes_per_range * num_glyph_ranges(); + return hb_min(format1_size, format2_size); } - private: hb_hashmap_t num_ranges_per_class; hb_hashmap_t glyphs_per_class; hb_set_t included_classes; hb_set_t included_glyphs; unsigned class_def_1_size; unsigned class_def_2_size; + unsigned coverage_size_val; }; diff --git a/src/graph/coverage-graph.hh b/src/graph/coverage-graph.hh index 457aab771..1fe969d0a 100644 --- a/src/graph/coverage-graph.hh +++ b/src/graph/coverage-graph.hh @@ -32,42 +32,47 @@ namespace graph { -static bool sanitize ( +static graph_result_t sanitize ( const OT::Layout::Common::CoverageFormat1_3* thiz, const graph_t::vertex_t& vertex ) { - size_t vertex_len = vertex.obj.tail - vertex.obj.head; + size_t vertex_len = vertex.table_size(); constexpr unsigned min_size = OT::Layout::Common::CoverageFormat1_3::min_size; - if (vertex_len < min_size) return false; + if (unlikely (vertex_len < min_size)) return Err(SANITIZE_FAILURE); hb_barrier (); - return vertex_len >= min_size + thiz->glyphArray.get_size () - thiz->glyphArray.len.get_size (); + if (unlikely (vertex_len < min_size + thiz->glyphArray.get_size () - thiz->glyphArray.len.get_size ())) + return Err(SANITIZE_FAILURE); + return Ok(); } -static bool sanitize ( +static graph_result_t sanitize ( const OT::Layout::Common::CoverageFormat2_4* thiz, const graph_t::vertex_t& vertex ) { - size_t vertex_len = vertex.obj.tail - vertex.obj.head; + size_t vertex_len = vertex.table_size(); constexpr unsigned min_size = OT::Layout::Common::CoverageFormat2_4::min_size; - if (vertex_len < min_size) return false; + if (unlikely (vertex_len < min_size)) return Err(SANITIZE_FAILURE); hb_barrier (); - return vertex_len >= min_size + thiz->rangeRecord.get_size () - thiz->rangeRecord.len.get_size (); + if (unlikely (vertex_len < min_size + thiz->rangeRecord.get_size () - thiz->rangeRecord.len.get_size ())) + return Err(SANITIZE_FAILURE); + return Ok(); } struct Coverage : public OT::Layout::Common::Coverage { - static Coverage* clone_coverage (gsubgpos_graph_context_t& c, - unsigned coverage_id, - unsigned new_parent_id, - unsigned link_position, - unsigned start, unsigned end) + static graph_result_t clone_coverage (gsubgpos_graph_context_t& c, + unsigned coverage_id, + unsigned new_parent_id, + unsigned link_position, + unsigned start, unsigned end) { unsigned coverage_size = c.graph.vertices_[coverage_id].table_size (); auto& coverage_v = c.graph.vertices_[coverage_id]; - Coverage* coverage_table = (Coverage*) coverage_v.obj.head; - if (!coverage_table || !coverage_table->sanitize (coverage_v)) - return nullptr; + const Coverage* coverage_table = (const Coverage*) coverage_v.obj().head; + if (unlikely (!coverage_table)) + return Err(INVALID_ARGUMENT); + TRY (coverage_table->sanitize (coverage_v)); auto new_coverage = + hb_zip (coverage_table->iter (), hb_range ()) @@ -81,35 +86,32 @@ struct Coverage : public OT::Layout::Common::Coverage } template - static Coverage* add_coverage (gsubgpos_graph_context_t& c, - unsigned parent_id, - unsigned link_position, - It glyphs, - unsigned max_size) + static graph_result_t add_coverage (gsubgpos_graph_context_t& c, + unsigned parent_id, + unsigned link_position, + It glyphs, + unsigned max_size) { - unsigned coverage_prime_id = c.graph.new_node (nullptr, nullptr); + TRY_ASSIGN (unsigned coverage_prime_id, c.graph.new_node (nullptr, nullptr)); auto& coverage_prime_vertex = c.graph.vertices_[coverage_prime_id]; - if (!make_coverage (c, glyphs, coverage_prime_id, max_size)) - return nullptr; + TRY (make_coverage (c, glyphs, coverage_prime_id, max_size)); - auto* coverage_link = c.graph.vertices_[parent_id].obj.real_links.push (); - coverage_link->width = SmallTypes::size; - coverage_link->objidx = coverage_prime_id; - coverage_link->position = link_position; - coverage_prime_vertex.add_parent (parent_id, false); + TRY(c.graph.vertices_[parent_id].add_real_link (SmallTypes::size, coverage_prime_id, link_position)); + TRY(coverage_prime_vertex.add_parent (parent_id, false)); - return (Coverage*) coverage_prime_vertex.obj.head; + return Ok(); } // Filter an existing coverage table to glyphs at indices [start, end) and replace it with the filtered version. - static bool filter_coverage (gsubgpos_graph_context_t& c, - unsigned existing_coverage, - unsigned start, unsigned end) { + static graph_result_t filter_coverage (gsubgpos_graph_context_t& c, + unsigned existing_coverage, + unsigned start, unsigned end) { unsigned coverage_size = c.graph.vertices_[existing_coverage].table_size (); auto& coverage_v = c.graph.vertices_[existing_coverage]; - Coverage* coverage_table = (Coverage*) coverage_v.obj.head; - if (!coverage_table || !coverage_table->sanitize (coverage_v)) - return false; + const Coverage* coverage_table = (const Coverage*) coverage_v.obj().head; + if (unlikely (!coverage_table)) + return Err(INVALID_ARGUMENT); + TRY (coverage_table->sanitize (coverage_v)); auto new_coverage = + hb_zip (coverage_table->iter (), hb_range ()) @@ -124,42 +126,51 @@ struct Coverage : public OT::Layout::Common::Coverage // Replace the coverage table at dest obj with one covering 'glyphs'. template - static bool make_coverage (gsubgpos_graph_context_t& c, - It glyphs, - unsigned dest_obj, - unsigned max_size) + static graph_result_t make_coverage (gsubgpos_graph_context_t& c, + It glyphs, + unsigned dest_obj, + unsigned max_size) { char* buffer = (char*) hb_calloc (1, max_size); + if (unlikely (!buffer)) + return Err(ALLOCATION_FAILURE); + hb_serialize_context_t serializer (buffer, max_size); OT::Layout::Common::Coverage_serialize (&serializer, glyphs); serializer.end_serialize (); - if (serializer.in_error ()) + if (unlikely (serializer.in_error ())) { hb_free (buffer); - return false; + return Err(ALLOCATION_FAILURE); } hb_bytes_t coverage_copy = serializer.copy_bytes (); - if (!coverage_copy.arrayZ) return false; - // Give ownership to the context, it will cleanup the buffer. - if (!c.add_buffer ((char *) coverage_copy.arrayZ)) - { - hb_free ((char *) coverage_copy.arrayZ); - return false; + if (unlikely (!coverage_copy.arrayZ)) { + hb_free (buffer); + return Err(ALLOCATION_FAILURE); } - auto& obj = c.graph.vertices_[dest_obj].obj; - obj.head = (char *) coverage_copy.arrayZ; - obj.tail = obj.head + coverage_copy.length; + // Give ownership to the context, it will cleanup the buffer. + auto res = c.add_buffer ((char *) coverage_copy.arrayZ); + if (unlikely (!res.is_ok ())) + { + hb_free (buffer); + hb_free ((char *) coverage_copy.arrayZ); + return res; + } + + auto& v = c.graph.vertices_[dest_obj]; + char* head = (char *) coverage_copy.arrayZ; + v.set_buffer (head, head + coverage_copy.length); hb_free (buffer); - return true; + return Ok(); } - bool sanitize (const graph_t::vertex_t& vertex) const + graph_result_t sanitize (const graph_t::vertex_t& vertex) const { - size_t vertex_len = vertex.obj.tail - vertex.obj.head; - if (vertex_len < OT::Layout::Common::Coverage::min_size) return false; + size_t vertex_len = vertex.table_size (); + if (unlikely (vertex_len < OT::Layout::Common::Coverage::min_size)) return Err(SANITIZE_FAILURE); hb_barrier (); switch (u.format.v) { @@ -170,7 +181,7 @@ struct Coverage : public OT::Layout::Common::Coverage case 3: case 4: #endif - default: return false; + default: return Err(SANITIZE_FAILURE); } } }; diff --git a/src/graph/graph-result.hh b/src/graph/graph-result.hh new file mode 100644 index 000000000..ad6029c8c --- /dev/null +++ b/src/graph/graph-result.hh @@ -0,0 +1,67 @@ +/* + * Copyright © 2026 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Google Author(s): Garret Rieger + */ + +#ifndef GRAPH_GRAPH_RESULT_HH +#define GRAPH_GRAPH_RESULT_HH + +#include "../hb-result.hh" + +namespace graph { + +enum graph_error_t { + ALLOCATION_FAILURE, + LIMIT_EXCEEDED, + INVALID_ARGUMENT, + CYCLE_DETECTED, + SANITIZE_FAILURE, + OUT_OF_BOUNDS, + ORPHANED_NODES, + OVERFLOW_RESOLUTION_FAILED, + UNKNOWN, +}; + +static inline const char* to_string(graph_error_t e) { + switch (e) { + case ALLOCATION_FAILURE: return "Memory Allocation Failed"; + case LIMIT_EXCEEDED: return "Limit Exceeded"; + case INVALID_ARGUMENT: return "Invalid Argument"; + case CYCLE_DETECTED: return "Cycle in Graph"; + case SANITIZE_FAILURE: return "Failed Sanitization"; + case OUT_OF_BOUNDS: return "Out of Bounds"; + case ORPHANED_NODES: return "Graph is not fully connected"; + case OVERFLOW_RESOLUTION_FAILED: return "Overflows are not able to be resolved"; + case UNKNOWN: + default: + return "Unknown Error"; + } +} + +template +using graph_result_t = hb_result_t; + +} // namespace graph + +#endif /* GRAPH_GRAPH_RESULT_HH */ diff --git a/src/graph/graph.hh b/src/graph/graph.hh index d1030dbdb..0399f7f3e 100644 --- a/src/graph/graph.hh +++ b/src/graph/graph.hh @@ -27,10 +27,13 @@ #include "../hb-set.hh" #include "../hb-priority-queue.hh" #include "../hb-serialize.hh" +#include "graph-result.hh" #ifndef GRAPH_GRAPH_HH #define GRAPH_GRAPH_HH +#define HB_GRAPH_INVALID ((unsigned) -1) + namespace graph { /** @@ -39,33 +42,119 @@ namespace graph { */ struct graph_t { + // TODO(garretrieger): experiment with using scratch vector for visited sets instead of allocating + // a new hb_set_t each time. + struct vertex_t { - hb_serialize_context_t::object_t obj; + // TODO(garretrieger): have vertex_t gaurantee that head/tail are non null and head < tail + // so downstream users don't need to constantly check that. + + // TODO(garretrieger): have vertex_t gaurantee that all link indexes are valid (ie < vertices_.length) + // so downstream users don't need to constantly check that. + + // TODO(garretrieger): track where the real links are currently sorted, and automatically sort + // prior to accessing iterator for real links. Avoids needing to manually trigger sorting by + // downstream users. + int64_t distance = 0 ; unsigned space = 0 ; unsigned start = 0; unsigned end = 0; unsigned priority = 0; + private: + hb_serialize_context_t::object_t obj_; unsigned incoming_edges_ = 0; - unsigned single_parent = (unsigned) -1; + unsigned single_parent = HB_GRAPH_INVALID; bool has_incoming_virtual_edges_ = false; hb_hashmap_t parents; hb_set_t virtual_parents; public: + vertex_t () + {} + + explicit vertex_t(const hb_serialize_context_t::object_t& obj) : obj_(obj) + {} + auto parents_iter () const HB_AUTO_RETURN ( hb_concat ( - hb_iter (&single_parent, single_parent != (unsigned) -1), + hb_iter (&single_parent, single_parent != HB_GRAPH_INVALID), parents.keys_ref () ) ) - bool in_error () const + void set_buffer (char* head, char* tail) { + obj_.head = head; + obj_.tail = tail; + } + + void shrink_buffer (size_t count) { - return parents.in_error () || virtual_parents.in_error (); + obj_.tail -= count; + } + + auto all_links_writer () HB_AUTO_RETURN (( obj_.all_links_writer() )); + auto real_links_writer () HB_AUTO_RETURN (( obj_.real_links.writer() )); + auto virtual_links_writer () HB_AUTO_RETURN (( obj_.virtual_links.writer() )); + + void sort_real_links () { + obj_.real_links.qsort (); + } + + graph_result_t add_real_link (unsigned width, unsigned obj_idx, unsigned position) { + auto* link = obj_.real_links.push (); + TRY (graph_result_t::from (obj_.real_links, ALLOCATION_FAILURE)); + link->width = width; + link->objidx = obj_idx; + link->position = position; + return Ok(); + } + + graph_result_t add_virtual_link (unsigned obj_idx) { + auto* link = obj_.virtual_links.push (); + TRY (graph_result_t::from (obj_.virtual_links, ALLOCATION_FAILURE)); + link->objidx = obj_idx; + return Ok(); + } + + graph_result_t add_real_link (const hb_serialize_context_t::object_t::link_t& link) + { + obj_.real_links.push (link); + return graph_result_t::from (obj_.real_links, ALLOCATION_FAILURE); + } + + graph_result_t set_real_links (hb_vector_t&& links) + { + TRY(graph_result_t::from (links, ALLOCATION_FAILURE)); + obj_.real_links = links; + return Ok(); + } + + void clear_real_links () + { + obj_.real_links.reset(); + } + + void clear_virtual_links () + { + obj_.virtual_links.reset(); + } + + graph_result_t add_virtual_link (const hb_serialize_context_t::object_t::link_t& link) + { + obj_.virtual_links.push (link); + return graph_result_t::from (obj_.virtual_links, ALLOCATION_FAILURE); + } + + const hb_serialize_context_t::object_t& obj() const { return obj_; } + + template + T as () const + { + return reinterpret_cast (obj_.head); } bool has_incoming_virtual_edges () const @@ -73,17 +162,17 @@ struct graph_t return has_incoming_virtual_edges_; } - bool link_positions_valid (unsigned num_objects, bool removed_nil) + graph_result_t link_positions_valid (unsigned num_objects, bool removed_nil) { hb_set_t assigned_bytes; - for (const auto& l : obj.real_links) + for (const auto& l : obj_.real_links) { - if (l.objidx >= num_objects - || (removed_nil && !l.objidx)) + if (unlikely (l.objidx >= num_objects + || (removed_nil && !l.objidx))) { DEBUG_MSG (SUBSET_REPACK, nullptr, "Invalid graph. Invalid object index."); - return false; + return Err(INVALID_ARGUMENT); } unsigned start = l.position; @@ -93,37 +182,37 @@ struct graph_t { DEBUG_MSG (SUBSET_REPACK, nullptr, "Invalid graph. Invalid link width."); - return false; + return Err(INVALID_ARGUMENT); } if (unlikely (end >= table_size ())) { DEBUG_MSG (SUBSET_REPACK, nullptr, "Invalid graph. Link position is out of bounds."); - return false; + return Err(OUT_OF_BOUNDS); } if (unlikely (assigned_bytes.intersects (start, end))) { DEBUG_MSG (SUBSET_REPACK, nullptr, "Invalid graph. Found offsets whose positions overlap."); - return false; + return Err(INVALID_ARGUMENT); } assigned_bytes.add_range (start, end); } - return !assigned_bytes.in_error (); + return graph_result_t::from (assigned_bytes, ALLOCATION_FAILURE); } void normalize () { - obj.real_links.qsort (); - for (auto& l : obj.real_links) + obj_.real_links.qsort (); + for (const auto& l : obj_.real_links) { for (unsigned i = 0; i < l.width; i++) { - obj.head[l.position + i] = 0; + obj_.head[l.position + i] = 0; } } } @@ -157,17 +246,17 @@ struct graph_t return false; } - return links_equal (obj.real_links, other.obj.real_links, graph, other_graph, depth); + return links_equal (obj_.real_links, other.obj_.real_links, graph, other_graph, depth); } hb_bytes_t as_bytes () const { - return hb_bytes_t (obj.head, table_size ()); + return hb_bytes_t (obj_.head, table_size ()); } friend void swap (vertex_t& a, vertex_t& b) { - hb_swap (a.obj, b.obj); + hb_swap (a.obj_, b.obj_); hb_swap (a.distance, b.distance); hb_swap (a.space, b.space); hb_swap (a.single_parent, b.single_parent); @@ -180,17 +269,17 @@ struct graph_t hb_swap (a.priority, b.priority); } - hb_hashmap_t + graph_result_t> position_to_index_map () const { hb_hashmap_t result; - result.alloc (obj.real_links.length); - for (const auto& l : obj.real_links) { + result.alloc (obj_.real_links.length); + for (const auto& l : obj_.real_links) { result.set (l.position, l.objidx); } - return result; + return graph_result_t>::from (std::move(result), ALLOCATION_FAILURE); } bool is_shared () const @@ -202,14 +291,14 @@ struct graph_t { if (HB_DEBUG_SUBSET_REPACK) { - assert (incoming_edges_ == (single_parent != (unsigned) -1) + + assert (incoming_edges_ == (single_parent != HB_GRAPH_INVALID) + (parents.values_ref () | hb_reduce (hb_add, 0))); } return incoming_edges_; } unsigned incoming_edges_from_parent (unsigned parent_index) const { - if (single_parent != (unsigned) -1) { + if (single_parent != HB_GRAPH_INVALID) { return single_parent == parent_index ? 1 : 0; } @@ -221,14 +310,14 @@ struct graph_t { incoming_edges_ = 0; has_incoming_virtual_edges_ = false; - single_parent = (unsigned) -1; + single_parent = HB_GRAPH_INVALID; parents.reset (); virtual_parents.reset (); } - void add_parent (unsigned parent_index, bool is_virtual) + graph_result_t add_parent (unsigned parent_index, bool is_virtual) { - assert (parent_index != (unsigned) -1); + assert (parent_index != HB_GRAPH_INVALID); has_incoming_virtual_edges_ |= is_virtual; if (is_virtual) virtual_parents.add (parent_index); @@ -237,14 +326,14 @@ struct graph_t { single_parent = parent_index; incoming_edges_ = 1; - return; + return to_result(); } - else if (single_parent != (unsigned) -1) + else if (single_parent != HB_GRAPH_INVALID) { assert (incoming_edges_ == 1); if (!parents.set (single_parent, 1)) - return; - single_parent = (unsigned) -1; + return to_result (); + single_parent = HB_GRAPH_INVALID; } unsigned *v; @@ -255,13 +344,15 @@ struct graph_t } else if (parents.set (parent_index, 1)) incoming_edges_++; + + return to_result(); } void remove_parent (unsigned parent_index) { if (parent_index == single_parent) { - single_parent = (unsigned) -1; + single_parent = HB_GRAPH_INVALID; incoming_edges_--; virtual_parents.reset (); return; @@ -287,26 +378,30 @@ struct graph_t } } - void remove_real_link (unsigned child_index, const void* offset) + void remove_real_link_unordered (unsigned link_array_index) { + obj_.real_links.remove_unordered (link_array_index); + } + + void remove_real_link_unordered (unsigned child_index, const void* offset) { - unsigned count = obj.real_links.length; + unsigned count = obj_.real_links.length; for (unsigned i = 0; i < count; i++) { - auto& link = obj.real_links.arrayZ[i]; + auto& link = obj_.real_links.arrayZ[i]; if (link.objidx != child_index) continue; - if ((obj.head + link.position) != offset) + if ((obj_.head + link.position) != offset) continue; - obj.real_links.remove_unordered (i); + obj_.real_links.remove_unordered (i); return; } } - void remap_parent (unsigned old_index, unsigned new_index) + graph_result_t remap_parent (unsigned old_index, unsigned new_index) { - if (single_parent != (unsigned) -1) + if (single_parent != HB_GRAPH_INVALID) { if (single_parent == old_index) { @@ -317,7 +412,7 @@ struct graph_t virtual_parents.add (new_index); } } - return; + return graph_result_t::from(virtual_parents, ALLOCATION_FAILURE); } const unsigned *pv; @@ -340,11 +435,13 @@ struct graph_t virtual_parents.del (old_index); virtual_parents.add (new_index); } + + return graph_result_t::from(virtual_parents, ALLOCATION_FAILURE); } bool is_leaf () const { - return !obj.real_links.length && !obj.virtual_links.length; + return !obj_.real_links.length && !obj_.virtual_links.length; } bool raise_priority () @@ -369,7 +466,7 @@ struct graph_t } size_t table_size () const { - return obj.tail - obj.head; + return obj_.tail - obj_.head; } int64_t modified_distance (unsigned order) const @@ -389,7 +486,7 @@ struct graph_t int64_t distance_modifier () const { if (!priority) return 0; - int64_t table_size = obj.tail - obj.head; + int64_t table_size = obj_.tail - obj_.head; if (priority == 1) return -table_size / 2; @@ -398,6 +495,14 @@ struct graph_t } private: + graph_result_t to_result() const { + if (unlikely ( + parents.in_error() || virtual_parents.in_error() || + obj_.real_links.in_error() || obj_.virtual_links.in_error())) + return Err(ALLOCATION_FAILURE); + return Ok(); + } + bool links_equal (const hb_vector_t& this_links, const hb_vector_t& other_links, const graph_t& graph, @@ -455,8 +560,6 @@ struct graph_t typename std::conditional::type vertex; typename std::conditional::type table; - operator bool () const - { return table && vertex; } }; /* @@ -467,29 +570,29 @@ struct graph_t * serializer */ template - graph_t (const T& objects) - : parents_invalid (true), - distance_invalid (true), - positions_invalid (true), - successful (true), - buffers () + static graph_result_t create (const T& objects) { - if (objects.length > HB_REPACKER_MAX_VERTICES) + if (unlikely (objects.length > HB_REPACKER_MAX_VERTICES)) { DEBUG_MSG (SUBSET_REPACK, nullptr, "constructing graph: num of objects %u exceeds HB_REPACKER_MAX_VERTICES.", objects.length); - check_success (false); - return; + return Err(LIMIT_EXCEEDED); } - num_roots_for_space_.push (1); + graph_t g; + g.num_roots_for_space_.push (1); + TRY (graph_result_t::from (g.num_roots_for_space_, ALLOCATION_FAILURE)); + bool removed_nil = false; - vertices_.alloc (objects.length); - ordering_.resize (objects.length); - ordering_scratch_.alloc (objects.length); + const unsigned count = objects.length; + g.vertices_.alloc (count); + g.ordering_.resize (count); + g.ordering_scratch_.alloc (count); + TRY (graph_result_t::from (g.vertices_, ALLOCATION_FAILURE)); + TRY (graph_result_t::from (g.ordering_, ALLOCATION_FAILURE)); + TRY (graph_result_t::from (g.ordering_scratch_, ALLOCATION_FAILURE)); - unsigned count = objects.length; unsigned order = objects.length; unsigned skip = 0; for (unsigned i = 0; i < count; i++) @@ -500,37 +603,57 @@ struct graph_t { removed_nil = true; order--; - ordering_.resize(objects.length - 1); + g.ordering_.resize (count - 1); skip++; continue; } - vertex_t* v = vertices_.push (); - if (check_success (!vertices_.in_error ())) - v->obj = *objects.arrayZ[i]; + hb_serialize_context_t::object_t obj (*objects.arrayZ[i]); + if (unlikely (obj.in_error ())) { + return Err(ALLOCATION_FAILURE); + } + vertex_t* v = g.vertices_.push (std::move (obj)); - check_success (v->link_positions_valid (count, removed_nil)); + TRY (v->link_positions_valid (count, removed_nil)); // To start we set the ordering to match the provided objects // list. Note: objects are provided to us in reverse order (ie. // the last object is the root). unsigned obj_idx = i - skip; - ordering_[--order] = obj_idx; + g.ordering_[--order] = obj_idx; if (!removed_nil) continue; // Fix indices to account for removed nil object. - for (auto& l : v->obj.all_links_writer ()) { + for (auto& l : v->all_links_writer ()) { l.objidx--; } } + + auto r = g.is_fully_connected(); + if (r.is_err() && r.error() == ORPHANED_NODES) { + g.print_orphaned_nodes (); + } + TRY(r); + + return g; } + graph_t (const graph_t&) = delete; + graph_t& operator = (const graph_t&) = delete; + graph_t (graph_t&&) = default; + graph_t& operator = (graph_t&&) = default; + ~graph_t () { for (char* b : buffers) hb_free (b); } +private: + graph_t () = default; + +public: + bool operator== (const graph_t& other) const { return root ().equals (root_idx(), other.root_idx(), other.root (), *this, other, 0); @@ -541,10 +664,10 @@ struct graph_t { const auto& v = vertices_[id]; printf("%u: %u [", id, (unsigned int)v.table_size()); - for (const auto &l : v.obj.real_links) { + for (const auto &l : v.obj().real_links) { printf("%u, ", l.objidx); } - for (const auto &l : v.obj.virtual_links) { + for (const auto &l : v.obj().virtual_links) { printf("v%u, ", l.objidx); } printf("]\n"); @@ -558,14 +681,6 @@ struct graph_t v.normalize (); } - bool in_error () const - { - return !successful || - vertices_.in_error () || - ordering_.in_error() || - num_roots_for_space_.in_error (); - } - const vertex_t& root () const { return vertices_[root_idx ()]; @@ -581,39 +696,38 @@ struct graph_t const hb_serialize_context_t::object_t& object (unsigned i) const { - return vertices_[i].obj; + return vertices_[i].obj(); } - bool add_buffer (char* buffer) + graph_result_t add_buffer (char* buffer) { buffers.push (buffer); - return !buffers.in_error (); + return graph_result_t::from (buffers, ALLOCATION_FAILURE); } /* * Adds a 16 bit link from parent_id to child_id */ template - void add_link (T* offset, - unsigned parent_id, - unsigned child_id) + graph_result_t add_link (T* offset, + unsigned parent_id, + unsigned child_id) { + if (unlikely (parent_id >= vertices_.length || child_id >= vertices_.length)) + return Err(OUT_OF_BOUNDS); auto& v = vertices_[parent_id]; - auto* link = v.obj.real_links.push (); - link->width = 2; - link->objidx = child_id; - link->position = (char*) offset - (char*) v.obj.head; - vertices_[child_id].add_parent (parent_id, false); + TRY(v.add_real_link(2, child_id, (char*) offset - (char*) v.obj().head)); + return vertices_[child_id].add_parent (parent_id, false); } /* * Generates a new topological sorting of graph ordered by the shortest * distance to each node if positions are marked as invalid. */ - void sort_shortest_distance_if_needed () + graph_result_t sort_shortest_distance_if_needed () { - if (!positions_invalid) return; - sort_shortest_distance (); + if (!positions_invalid) return Ok(); + return sort_shortest_distance (); } @@ -621,25 +735,30 @@ struct graph_t * Generates a new topological sorting of graph ordered by the shortest * distance to each node. */ - void sort_shortest_distance () + graph_result_t sort_shortest_distance () { positions_invalid = true; if (vertices_.length <= 1) { // Graph of 1 or less doesn't need sorting. - return; + return Ok(); } - update_distances (); + TRY (update_distances ()); hb_priority_queue_t queue; queue.alloc (vertices_.length); + TRY (graph_result_t::from (queue, ALLOCATION_FAILURE)); + hb_vector_t &new_ordering = ordering_scratch_; - if (unlikely (!check_success (new_ordering.resize (vertices_.length)))) return; + new_ordering.resize (vertices_.length); + TRY (graph_result_t::from (new_ordering, ALLOCATION_FAILURE)); hb_vector_t removed_edges; - if (unlikely (!check_success (removed_edges.resize (vertices_.length)))) return; - update_parents (); + removed_edges.resize (vertices_.length); + TRY (graph_result_t::from (removed_edges, ALLOCATION_FAILURE)); + + TRY (update_parents ()); queue.insert (root ().modified_distance (0), root_idx ()); unsigned order = 1; @@ -648,16 +767,18 @@ struct graph_t { unsigned next_id = queue.pop_minimum().second; - if (unlikely (!check_success(pos < new_ordering.length))) { + if (unlikely (pos >= new_ordering.length)) { // We are out of ids. Which means we've visited a node more than once. // This graph contains a cycle which is not allowed. DEBUG_MSG (SUBSET_REPACK, nullptr, "Invalid graph. Contains cycle."); - return; + return Err(CYCLE_DETECTED); } new_ordering[pos++] = next_id; const vertex_t& next = vertices_[next_id]; - for (const auto& link : next.obj.all_links ()) { + for (const auto& link : next.obj().all_links ()) { + if (unlikely (link.objidx >= vertices_.length)) + return Err(OUT_OF_BOUNDS); removed_edges[link.objidx]++; const auto& v = vertices_[link.objidx]; if (!(v.incoming_edges () - removed_edges[link.objidx])) @@ -671,14 +792,17 @@ struct graph_t } } - check_success (!queue.in_error ()); - check_success (!new_ordering.in_error ()); + TRY (graph_result_t::from (queue, ALLOCATION_FAILURE)); + TRY (graph_result_t::from (new_ordering, ALLOCATION_FAILURE)); hb_swap (ordering_, new_ordering); - if (!check_success (pos == vertices_.length)) { + if (unlikely (pos != vertices_.length)) { print_orphaned_nodes (); + return Err(ORPHANED_NODES); } + + return Ok(); } /* @@ -686,7 +810,7 @@ struct graph_t * More specifically this looks for the top most 24 bit or 32 bit links in the graph. * Some special casing is done that is specific to the layout of GSUB/GPOS tables. */ - void find_space_roots (hb_set_t& visited, hb_set_t& roots) + graph_result_t find_space_roots (hb_set_t& visited, hb_set_t& roots) { unsigned root_index = root_idx (); for (unsigned i : ordering_) @@ -694,7 +818,7 @@ struct graph_t if (visited.has (i)) continue; // Only real links can form 32 bit spaces - for (auto& l : vertices_[i].obj.real_links) + for (const auto& l : vertices_[i].obj().real_links) { if (l.is_signed || l.width < 3) continue; @@ -711,59 +835,64 @@ struct graph_t // that extension subtables beneath a 24bit lookup become the spaces instead // of the offset to the lookup. hb_set_t sub_roots; - find_32bit_roots (l.objidx, sub_roots); + TRY (find_32bit_roots (l.objidx, sub_roots)); if (sub_roots) { for (unsigned sub_root_idx : sub_roots) { roots.add (sub_root_idx); - find_subgraph (sub_root_idx, visited); + TRY (find_subgraph (sub_root_idx, visited)); } continue; } } roots.add (l.objidx); - find_subgraph (l.objidx, visited); + TRY (find_subgraph (l.objidx, visited)); } } + + TRY(graph_result_t::from (visited, ALLOCATION_FAILURE)); + TRY(graph_result_t::from (roots, ALLOCATION_FAILURE)); + return Ok(); } template - const vertex_and_table_t as_table (unsigned parent, const void* offset, Ts... ds) + graph_result_t> as_table (unsigned parent, const void* offset, Ts... ds) { - return as_table_from_index (index_for_offset (parent, offset), std::forward(ds)...); + TRY_ASSIGN (unsigned idx, index_for_offset (parent, offset)); + return as_table_from_index (idx, std::forward(ds)...); } template - vertex_and_table_t as_mutable_table (unsigned parent, const void* offset, Ts... ds) + graph_result_t> as_mutable_table (unsigned parent, const void* offset, Ts... ds) { - return as_table_from_index (mutable_index_for_offset (parent, offset), std::forward(ds)...); + TRY_ASSIGN (auto idx, mutable_index_for_offset (parent, offset)); + return as_table_from_index (idx, std::forward(ds)...); } template - vertex_and_table_t as_table_from_index (unsigned index, Ts... ds) + graph_result_t> as_table_from_index (unsigned index, Ts... ds) { - if (index >= vertices_.length) - return vertex_and_table_t (); + if (unlikely (index >= vertices_.length)) + return Err(OUT_OF_BOUNDS); vertex_and_table_t r; r.vertex = (typename std::conditional::type) &vertices_[index]; - r.table = (typename std::conditional::type) r.vertex->obj.head; + r.table = r.vertex->template as::type> (); r.index = index; - if (!r.table) - return vertex_and_table_t (); - - if (!r.table->sanitize (*(r.vertex), std::forward(ds)...)) - return vertex_and_table_t (); + if (unlikely (!r.table)) + return Err(INVALID_ARGUMENT); + TRY(r.table->sanitize (*(r.vertex), std::forward(ds)...)); return r; } // Finds the object id of the object pointed to by the offset at 'offset' // within object[node_idx]. - unsigned index_for_offset (unsigned node_idx, const void* offset) const + graph_result_t index_for_offset (unsigned node_idx, const void* offset) const { + if (unlikely (node_idx >= vertices_.length)) return Err(OUT_OF_BOUNDS); const auto& node = object (node_idx); - if (offset < node.head || offset >= node.tail) return -1; + if (unlikely (offset < node.head || offset >= node.tail)) return Err(OUT_OF_BOUNDS); unsigned count = node.real_links.length; for (unsigned i = 0; i < count; i++) @@ -772,19 +901,22 @@ struct graph_t const auto& link = node.real_links.arrayZ[i]; if (offset != node.head + link.position) continue; - return link.objidx; + return Ok(link.objidx); } - return -1; + return Err(INVALID_ARGUMENT); } // Finds the object id of the object pointed to by the offset at 'offset' // within object[node_idx]. Ensures that the returned object is safe to mutate. // That is, if the original child object is shared by parents other than node_idx // it will be duplicated and the duplicate will be returned instead. - unsigned mutable_index_for_offset (unsigned node_idx, const void* offset) + graph_result_t mutable_index_for_offset (unsigned node_idx, const void* offset) { - unsigned child_idx = index_for_offset (node_idx, offset); + TRY_ASSIGN (unsigned child_idx, index_for_offset (node_idx, offset)); + if (unlikely (child_idx >= vertices_.length)) + return Err(OUT_OF_BOUNDS); + auto& child = vertices_[child_idx]; for (unsigned p : child.parents_iter ()) { @@ -793,7 +925,7 @@ struct graph_t } } - return child_idx; + return Ok(child_idx); } @@ -802,43 +934,44 @@ struct graph_t * Currently, this is implemented specifically tailored to the structure of a GPOS/GSUB * (including with 24bit offsets) table. */ - bool assign_spaces () + graph_result_t assign_spaces () { - update_parents (); + TRY (update_parents ()); hb_set_t visited; hb_set_t roots; - find_space_roots (visited, roots); + TRY (find_space_roots (visited, roots)); // Mark everything not in the subgraphs of the roots as visited. This prevents // subgraphs from being connected via nodes not in those subgraphs. visited.invert (); - if (!roots) return false; + if (!roots) return Ok(false); while (roots) { uint32_t next = HB_SET_VALUE_INVALID; - if (unlikely (!check_success (!roots.in_error ()))) break; + TRY (graph_result_t::from (roots, ALLOCATION_FAILURE)); if (!roots.next (&next)) break; hb_set_t connected_roots; - find_connected_nodes (next, roots, visited, connected_roots); - if (unlikely (!check_success (!connected_roots.in_error ()))) break; + TRY (find_connected_nodes (next, roots, visited, connected_roots)); + TRY (graph_result_t::from (connected_roots, ALLOCATION_FAILURE)); - isolate_subgraph (connected_roots); - if (unlikely (!check_success (!connected_roots.in_error ()))) break; + TRY (isolate_subgraph (connected_roots)); + TRY (graph_result_t::from (connected_roots, ALLOCATION_FAILURE)); unsigned next_space = this->next_space (); - if (next_space >= HB_REPACKER_MAX_SPACES) + if (unlikely (next_space >= HB_REPACKER_MAX_SPACES)) { DEBUG_MSG (SUBSET_REPACK, nullptr, "num of spaces %u exceeds HB_REPACKER_MAX_SPACES.", next_space); - check_success (false); - break; + return Err(LIMIT_EXCEEDED); } num_roots_for_space_.push (0); + TRY(graph_result_t::from (num_roots_for_space_, ALLOCATION_FAILURE)); + for (unsigned root : connected_roots) { DEBUG_MSG (SUBSET_REPACK, nullptr, "Subgraph %u gets space %u", root, next_space); @@ -852,9 +985,7 @@ struct graph_t // into the 32 bit space as needed, instead of using isolation. } - - - return true; + return Ok(true); } /* @@ -864,9 +995,9 @@ struct graph_t * * Indices stored in roots will be updated if any of the roots are duplicated to new indices. */ - bool isolate_subgraph (hb_set_t& roots) + graph_result_t isolate_subgraph (hb_set_t& roots) { - update_parents (); + TRY(update_parents ()); hb_map_t subgraph; // incoming edges to root_idx should be all 32 bit in length so we don't need to de-dup these @@ -874,11 +1005,12 @@ struct graph_t hb_set_t parents; for (unsigned root_idx : roots) { + if (unlikely (root_idx >= vertices_.length)) + return Err(OUT_OF_BOUNDS); subgraph.set (root_idx, wide_parents (root_idx, parents)); - find_subgraph (root_idx, subgraph); + TRY (find_subgraph (root_idx, subgraph)); } - if (subgraph.in_error ()) - return false; + TRY (graph_result_t::from (subgraph, ALLOCATION_FAILURE)); hb_map_t index_map; bool made_changes = false; @@ -892,15 +1024,14 @@ struct graph_t { // Only de-dup objects with incoming links from outside the subgraph. made_changes = true; - duplicate_subgraph (entry.first, index_map); + TRY (duplicate_subgraph (entry.first, index_map)); } } - if (in_error ()) - return false; + TRY (graph_result_t::from (index_map, ALLOCATION_FAILURE)); if (!made_changes) - return false; + return Ok(false); auto new_subgraph = + subgraph.keys () @@ -911,8 +1042,8 @@ struct graph_t }) ; - remap_obj_indices (index_map, new_subgraph); - remap_obj_indices (index_map, parents.iter (), true); + TRY(remap_obj_indices (index_map, new_subgraph)); + TRY(remap_obj_indices (index_map, parents.iter (), true)); // Update roots set with new indices as needed. for (auto next : roots) @@ -925,7 +1056,7 @@ struct graph_t } } - return true; + return Ok(true); } // BFS graph traversal starting at start_idx. @@ -942,22 +1073,22 @@ struct graph_t // This traversal does not use a visited set internally, it is the responsibility of visit_edge // to track and filter visited nodes if required for the particular traversal. template - void traverse_directed_bfs (unsigned start_idx, VisitEdgeFunc&& visit_edge) + graph_result_t traverse_directed_bfs (unsigned start_idx, VisitEdgeFunc&& visit_edge) { - if (unlikely (!check_success(start_idx < vertices_.length))) + if (unlikely (start_idx >= vertices_.length)) { DEBUG_MSG (SUBSET_REPACK, nullptr, "traverse_directed_bfs: unexpected start_idx out of bounds."); - return; + return Err(OUT_OF_BOUNDS); } // For performance we want to avoid allocating extra memory. So use the ordering_scratch_ // buffer to implement a queue for BFS. - if (unlikely (!check_success (ordering_scratch_.resize (vertices_.length)))) - return; + ordering_scratch_.resize (vertices_.length); + TRY (graph_result_t::from (ordering_scratch_, ALLOCATION_FAILURE)); if (!visit_edge (HB_CODEPOINT_INVALID, nullptr, start_idx, 0)) - return; + return Ok(); unsigned head = 0; unsigned tail = 0; @@ -973,34 +1104,35 @@ struct graph_t unsigned node_idx = queue[head++]; const auto& v = vertices_[node_idx]; - unsigned num_real = v.obj.real_links.length; - unsigned total_links = num_real + v.obj.virtual_links.length; + unsigned num_real = v.obj().real_links.length; + unsigned total_links = num_real + v.obj().virtual_links.length; for (unsigned i = 0; i < total_links; i++) { // vertices_ may have re-alloc'd inside an op() call, so reassign the v ref. const auto& v = vertices_[node_idx]; const auto& link = (i < num_real) - ? v.obj.real_links[i] - : v.obj.virtual_links[i - num_real]; + ? v.obj().real_links[i] + : v.obj().virtual_links[i - num_real]; unsigned child_idx = link.objidx; if (!visit_edge (node_idx, &link, child_idx, depth + 1)) continue; - if (unlikely (!check_success (tail < queue.length))) - return; + if (unlikely (tail >= queue.length)) + return Err(CYCLE_DETECTED); queue[tail++] = child_idx; } } depth++; } + return Ok(); } - void find_subgraph (unsigned node_idx, hb_map_t& subgraph) + graph_result_t find_subgraph (unsigned node_idx, hb_map_t& subgraph) { - traverse_directed_bfs (node_idx, [&] ( + return traverse_directed_bfs (node_idx, [&] ( unsigned parent, const hb_serialize_context_t::object_t::link_t* link, unsigned child, @@ -1017,9 +1149,9 @@ struct graph_t }); } - void find_subgraph (unsigned node_idx, hb_set_t& subgraph) + graph_result_t find_subgraph (unsigned node_idx, hb_set_t& subgraph) { - traverse_directed_bfs (node_idx, [&] ( + return traverse_directed_bfs (node_idx, [&] ( unsigned parent, const hb_serialize_context_t::object_t::link_t* link, unsigned child, @@ -1030,10 +1162,10 @@ struct graph_t }); } - size_t find_subgraph_size (unsigned node_idx, hb_set_t& subgraph, unsigned max_depth = -1) + graph_result_t find_subgraph_size (unsigned node_idx, hb_set_t& subgraph, unsigned max_depth = HB_GRAPH_INVALID) { size_t size = 0; - traverse_directed_bfs (node_idx, [&] ( + TRY (traverse_directed_bfs (node_idx, [&] ( unsigned parent, const hb_serialize_context_t::object_t::link_t* link, unsigned child, @@ -1041,23 +1173,23 @@ struct graph_t if (subgraph.has (child)) return false; subgraph.add (child); - const auto& o = vertices_[child].obj; + const auto& o = vertices_[child].obj(); size += o.tail - o.head; return depth < max_depth; - }); - return size; + })); + return Ok(size); } /* * Finds the topmost children of 32bit offsets in the subgraph starting * at node_idx. Found indices are placed into 'found'. */ - void find_32bit_roots (unsigned node_idx, hb_set_t& found) + graph_result_t find_32bit_roots (unsigned node_idx, hb_set_t& found) { // Note: this specifically requires a BFS based traversal to ensure we don't recurse through // a node that is accessible via both 32bit and non-32 bit links. hb_set_t visited; - traverse_directed_bfs (node_idx, [&] ( + return traverse_directed_bfs (node_idx, [&] ( unsigned parent, const hb_serialize_context_t::object_t::link_t* link, unsigned child, @@ -1087,32 +1219,35 @@ struct graph_t * Returns the id of the child node that was moved. */ template - unsigned move_child (unsigned old_parent_idx, - const O* old_offset, - unsigned new_parent_idx, - const O* new_offset) + graph_result_t move_child (unsigned old_parent_idx, + const O* old_offset, + unsigned new_parent_idx, + const O* new_offset) { distance_invalid = true; positions_invalid = true; + if (unlikely (old_parent_idx >= vertices_.length || + new_parent_idx >= vertices_.length)) + return Err(OUT_OF_BOUNDS); + auto& old_v = vertices_[old_parent_idx]; auto& new_v = vertices_[new_parent_idx]; - unsigned child_id = index_for_offset (old_parent_idx, - old_offset); + TRY_ASSIGN (unsigned child_id, index_for_offset (old_parent_idx, + old_offset)); + if (unlikely (child_id >= vertices_.length)) + return Err(OUT_OF_BOUNDS); - auto* new_link = new_v.obj.real_links.push (); - new_link->width = O::static_size; - new_link->objidx = child_id; - new_link->position = (const char*) new_offset - (const char*) new_v.obj.head; + TRY(new_v.add_real_link(O::static_size, child_id, (const char*) new_offset - (const char*) new_v.obj().head)); auto& child = vertices_[child_id]; - child.add_parent (new_parent_idx, false); + TRY(child.add_parent (new_parent_idx, false)); - old_v.remove_real_link (child_id, old_offset); + old_v.remove_real_link_unordered (child_id, old_offset); child.remove_parent (old_parent_idx); - return child_id; + return Ok(child_id); } /* @@ -1122,12 +1257,16 @@ struct graph_t * parent starting at new_pos_start. */ template - void move_children (unsigned old_parent_idx, - unsigned old_pos_start, - unsigned old_pos_end, - unsigned new_parent_idx, - unsigned new_pos_start) + graph_result_t move_children (unsigned old_parent_idx, + unsigned old_pos_start, + unsigned old_pos_end, + unsigned new_parent_idx, + unsigned new_pos_start) { + if (unlikely (old_parent_idx >= vertices_.length || + new_parent_idx >= vertices_.length)) + return Err(OUT_OF_BOUNDS); + distance_invalid = true; positions_invalid = true; @@ -1135,28 +1274,29 @@ struct graph_t auto& new_v = vertices_[new_parent_idx]; hb_vector_t old_links; - for (const auto& l : old_v.obj.real_links) + for (const auto& l : old_v.obj().real_links) { if (l.position < old_pos_start || l.position >= old_pos_end) { - old_links.push(l); + old_links.push (l); continue; } unsigned array_pos = l.position - old_pos_start; unsigned child_id = l.objidx; - auto* new_link = new_v.obj.real_links.push (); - new_link->width = O::static_size; - new_link->objidx = child_id; - new_link->position = new_pos_start + array_pos; + if (unlikely (child_id >= vertices_.length)) + return Err(OUT_OF_BOUNDS); + + TRY(new_v.add_real_link(O::static_size, child_id, new_pos_start + array_pos)); auto& child = vertices_[child_id]; - child.add_parent (new_parent_idx, false); + TRY(child.add_parent (new_parent_idx, false)); child.remove_parent (old_parent_idx); } - old_v.obj.real_links = std::move (old_links); + TRY (graph_result_t::from (old_links, ALLOCATION_FAILURE)); + return old_v.set_real_links(std::move (old_links)); } /* @@ -1164,84 +1304,92 @@ struct graph_t * links. index_map is updated with mappings from old id to new id. If a duplication has already * been performed for a given index, then it will be skipped. */ - void duplicate_subgraph (unsigned node_idx, hb_map_t& index_map) + graph_result_t duplicate_subgraph (unsigned node_idx, hb_map_t& index_map) { - traverse_directed_bfs (node_idx, [&] ( + graph_result_t result = Ok(); + TRY (traverse_directed_bfs (node_idx, [&] ( unsigned parent, const hb_serialize_context_t::object_t::link_t* link, unsigned child, unsigned _) { - if (index_map.has (child)) return false; - unsigned clone_idx = duplicate (child); - if (!check_success (clone_idx != (unsigned) -1)) return false; - index_map.set (child, clone_idx); + if (result.is_err () || index_map.has (child)) return false; + auto r = duplicate (child); + if (unlikely (r.is_err ())) + { + result = Err(r.error ()); + return false; + } + index_map.set (child, *r); return true; - }); + })); + + return graph_result_t::from(index_map, ALLOCATION_FAILURE); } /* * Creates a copy of node_idx and returns it's new index. */ - unsigned duplicate (unsigned node_idx, bool copy_table = false) + graph_result_t duplicate (unsigned node_idx, bool copy_table = false) { - if (vertices_.length >= HB_REPACKER_MAX_VERTICES) + if (unlikely (node_idx >= vertices_.length)) + return Err(OUT_OF_BOUNDS); + + if (unlikely (vertices_.length >= HB_REPACKER_MAX_VERTICES)) { DEBUG_MSG (SUBSET_REPACK, nullptr, "duplicating node: num of vertices %u exceeds HB_REPACKER_MAX_VERTICES.", vertices_.length); - check_success (false); - return -1; + return Err(LIMIT_EXCEEDED); } positions_invalid = true; distance_invalid = true; auto* clone = vertices_.push (); + TRY (graph_result_t::from (vertices_, ALLOCATION_FAILURE)); + unsigned clone_idx = vertices_.length - 1; - ordering_.push(clone_idx); + ordering_.push (clone_idx); + TRY (graph_result_t::from (ordering_, ALLOCATION_FAILURE)); auto& child = vertices_[node_idx]; - if (vertices_.in_error () || ordering_.in_error()) { - return -1; - } - unsigned table_size = child.obj.tail - child.obj.head; + unsigned table_size = child.obj().tail - child.obj().head; if (copy_table && table_size) { char* buffer = (char*) hb_malloc (table_size); - if (!check_success (buffer && add_buffer (buffer))) + if (unlikely (!buffer)) + return Err(ALLOCATION_FAILURE); + auto res = add_buffer (buffer); + if (unlikely (res.is_err ())) { hb_free (buffer); - return -1; + return Err(res.error ()); } - hb_memcpy (buffer, child.obj.head, table_size); - clone->obj.head = buffer; - clone->obj.tail = buffer + table_size; + hb_memcpy (buffer, child.obj().head, table_size); + clone->set_buffer(buffer, buffer + table_size); } else { - clone->obj.head = child.obj.head; - clone->obj.tail = child.obj.tail; + clone->set_buffer(child.obj().head, child.obj().tail); } clone->distance = child.distance; clone->space = child.space; clone->reset_parents (); - for (const auto& l : child.obj.real_links) + for (const auto& l : child.obj().real_links) { - clone->obj.real_links.push (l); - vertices_[l.objidx].add_parent (clone_idx, false); - } - for (const auto& l : child.obj.virtual_links) - { - clone->obj.virtual_links.push (l); - vertices_[l.objidx].add_parent (clone_idx, true); + TRY(clone->add_real_link (l)); + TRY(vertices_[l.objidx].add_parent (clone_idx, false)); } - check_success (!clone->obj.real_links.in_error ()); - check_success (!clone->obj.virtual_links.in_error ()); + for (const auto& l : child.obj().virtual_links) + { + TRY(clone->add_virtual_link (l)); + TRY(vertices_[l.objidx].add_parent (clone_idx, true)); + } - return clone_idx; + return Ok(clone_idx); } /* @@ -1252,16 +1400,19 @@ struct graph_t * Returns the index of the newly created duplicate. * * If the child_idx only has incoming edges from parent_idx, - * duplication isn't possible and this will return -1. + * duplication isn't possible and this will return an error. */ - unsigned duplicate (unsigned parent_idx, unsigned child_idx, bool copy_table = false) + graph_result_t duplicate (unsigned parent_idx, unsigned child_idx, bool copy_table = false) { - update_parents (); + if (unlikely (parent_idx >= vertices_.length || child_idx >= vertices_.length)) + return Err(OUT_OF_BOUNDS); + + TRY (update_parents ()); const auto& child = vertices_[child_idx]; - unsigned links_to_child = child.incoming_edges_from_parent(parent_idx); + unsigned links_to_child = child.incoming_edges_from_parent (parent_idx); - if (child.incoming_edges () <= links_to_child || child.has_incoming_virtual_edges()) + if (unlikely (child.incoming_edges () <= links_to_child || child.has_incoming_virtual_edges ())) { // Can't duplicate this node, doing so would orphan the original one as all remaining links // to child are from parent. @@ -1272,30 +1423,29 @@ struct graph_t // to by virtual edges). DEBUG_MSG (SUBSET_REPACK, nullptr, " Not duplicating %u => %u", parent_idx, child_idx); - return -1; + return Err(INVALID_ARGUMENT); } DEBUG_MSG (SUBSET_REPACK, nullptr, " Duplicating %u => %u", parent_idx, child_idx); - unsigned clone_idx = duplicate (child_idx, copy_table); - if (clone_idx == (unsigned) -1) return -1; + TRY_ASSIGN (unsigned clone_idx, duplicate (child_idx, copy_table)); // duplicate shifts the root node idx, so if parent_idx was root update it. if (parent_idx == clone_idx) parent_idx++; auto& parent = vertices_[parent_idx]; unsigned count = 0; - unsigned num_real = parent.obj.real_links.length; - for (auto& l : parent.obj.all_links_writer ()) + unsigned num_real = parent.obj().real_links.length; + for (auto& l : parent.all_links_writer ()) { count++; if (l.objidx != child_idx) continue; - reassign_link (l, parent_idx, clone_idx, count > num_real); + TRY(reassign_link (l, parent_idx, clone_idx, count > num_real)); } - return clone_idx; + return Ok(clone_idx); } /* @@ -1307,25 +1457,29 @@ struct graph_t * * If the child_idx only has incoming edges from parents, * duplication isn't possible or duplication fails and this will - * return -1. + * return an error. */ - unsigned duplicate (const hb_set_t* parents, unsigned child_idx) + graph_result_t duplicate (const hb_set_t* parents, unsigned child_idx) { - if (parents->is_empty()) { - return -1; - } + if (unlikely (!parents || parents->is_empty ())) + return Err(INVALID_ARGUMENT); - update_parents (); + if (unlikely (child_idx >= vertices_.length)) + return Err(OUT_OF_BOUNDS); + + TRY (update_parents ()); const auto& child = vertices_[child_idx]; unsigned links_to_child = 0; - unsigned last_parent = parents->get_max(); - unsigned first_parent = parents->get_min(); + unsigned last_parent = parents->get_max (); + unsigned first_parent = parents->get_min (); for (unsigned parent_idx : *parents) { - links_to_child += child.incoming_edges_from_parent(parent_idx); + if (unlikely (parent_idx >= vertices_.length)) + return Err(OUT_OF_BOUNDS); + links_to_child += child.incoming_edges_from_parent (parent_idx); } - if (child.incoming_edges () <= links_to_child || child.has_incoming_virtual_edges()) + if (unlikely (child.incoming_edges () <= links_to_child || child.has_incoming_virtual_edges ())) { // Can't duplicate this node, doing so would orphan the original one as all remaining links // to child are from parent. @@ -1335,65 +1489,61 @@ struct graph_t // with virtual edges may end up orphaned by duplication (ie. where one copy is only pointed // to by virtual edges). DEBUG_MSG (SUBSET_REPACK, nullptr, " Not duplicating %u, ..., %u => %u", first_parent, last_parent, child_idx); - return -1; + return Err(INVALID_ARGUMENT); } DEBUG_MSG (SUBSET_REPACK, nullptr, " Duplicating %u, ..., %u => %u", first_parent, last_parent, child_idx); - unsigned clone_idx = duplicate (child_idx); - if (clone_idx == (unsigned) -1) return false; + TRY_ASSIGN (unsigned clone_idx, duplicate (child_idx)); for (unsigned parent_idx : *parents) { // duplicate shifts the root node idx, so if parent_idx was root update it. if (parent_idx == clone_idx) parent_idx++; auto& parent = vertices_[parent_idx]; unsigned count = 0; - unsigned num_real = parent.obj.real_links.length; - for (auto& l : parent.obj.all_links_writer ()) + unsigned num_real = parent.obj().real_links.length; + for (auto& l : parent.all_links_writer ()) { count++; if (l.objidx != child_idx) continue; - reassign_link (l, parent_idx, clone_idx, count > num_real); + TRY(reassign_link (l, parent_idx, clone_idx, count > num_real)); } } - return clone_idx; + return Ok(clone_idx); } /* * Adds a new node to the graph, not connected to anything. */ - unsigned new_node (char* head, char* tail) + graph_result_t new_node (char* head, char* tail) { - if (vertices_.length >= HB_REPACKER_MAX_VERTICES) + if (unlikely (vertices_.length >= HB_REPACKER_MAX_VERTICES)) { DEBUG_MSG (SUBSET_REPACK, nullptr, "creating new node: num of vertices %u exceeds HB_REPACKER_MAX_VERTICES.", vertices_.length); - check_success (false); - return -1; + return Err(LIMIT_EXCEEDED); } positions_invalid = true; distance_invalid = true; auto* clone = vertices_.push (); + TRY (graph_result_t::from (vertices_, ALLOCATION_FAILURE)); + unsigned clone_idx = vertices_.length - 1; - ordering_.push(clone_idx); + ordering_.push (clone_idx); + TRY (graph_result_t::from (ordering_, ALLOCATION_FAILURE)); - if (vertices_.in_error () || ordering_.in_error()) { - return -1; - } - - clone->obj.head = head; - clone->obj.tail = tail; + clone->set_buffer (head, tail); clone->distance = 0; clone->space = 0; - return clone_idx; + return Ok(clone_idx); } /* @@ -1402,59 +1552,61 @@ struct graph_t * Returns the index of the newly created child. * */ - unsigned remap_child (unsigned parent_idx, unsigned old_child_idx) + graph_result_t remap_child (unsigned parent_idx, unsigned old_child_idx) { - unsigned new_child_idx = duplicate (old_child_idx); - if (new_child_idx == (unsigned) -1) return -1; + if (unlikely (parent_idx >= vertices_.length || old_child_idx >= vertices_.length)) + return Err(OUT_OF_BOUNDS); + + TRY_ASSIGN (unsigned new_child_idx, duplicate (old_child_idx)); auto& parent = vertices_[parent_idx]; - for (auto& l : parent.obj.real_links) + for (auto& l : parent.real_links_writer ()) { if (l.objidx != old_child_idx) continue; - reassign_link (l, parent_idx, new_child_idx, false); + TRY(reassign_link (l, parent_idx, new_child_idx, false)); } - for (auto& l : parent.obj.virtual_links) + for (auto& l : parent.virtual_links_writer ()) { if (l.objidx != old_child_idx) continue; - reassign_link (l, parent_idx, new_child_idx, true); + TRY(reassign_link (l, parent_idx, new_child_idx, true)); } - return new_child_idx; + return Ok(new_child_idx); } /* * Raises the sorting priority of all children. */ - bool raise_childrens_priority (unsigned parent_idx) + graph_result_t raise_childrens_priority (unsigned parent_idx) { DEBUG_MSG (SUBSET_REPACK, nullptr, " Raising priority of all children of %u", parent_idx); // This operation doesn't change ordering until a sort is run, so no need // to invalidate positions. It does not change graph structure so no need // to update distances or edge counts. - auto& parent = vertices_[parent_idx].obj; + if (unlikely (parent_idx >= vertices_.length)) return Err(OUT_OF_BOUNDS); bool made_change = false; - for (auto& l : parent.all_links_writer ()) + for (auto& l : vertices_[parent_idx].all_links_writer ()) made_change |= vertices_[l.objidx].raise_priority (); - return made_change; + return Ok(made_change); } - bool is_fully_connected () + graph_result_t is_fully_connected () { - update_parents(); + TRY(update_parents()); - if (root().incoming_edges ()) + if (unlikely (root().incoming_edges ())) // Root cannot have parents. - return false; + return Err(ORPHANED_NODES); for (unsigned i = 0; i < root_idx (); i++) { - if (!vertices_[i].incoming_edges ()) - return false; + if (unlikely (!vertices_[i].incoming_edges ())) + return Err(ORPHANED_NODES); } - return true; + return Ok(); } #if 0 @@ -1507,27 +1659,6 @@ struct graph_t } #endif - void print_orphaned_nodes () - { - if (!DEBUG_ENABLED(SUBSET_REPACK)) return; - - DEBUG_MSG (SUBSET_REPACK, nullptr, "Graph is not fully connected."); - - parents_invalid = true; - update_parents(); - - if (root().incoming_edges ()) { - DEBUG_MSG (SUBSET_REPACK, nullptr, "Root node has incoming edges."); - } - - for (unsigned i = 0; i < root_idx (); i++) - { - const auto& v = vertices_[i]; - if (!v.incoming_edges ()) - DEBUG_MSG (SUBSET_REPACK, nullptr, "Node %u is orphaned.", i); - } - } - unsigned num_roots_for_space (unsigned space) const { return num_roots_for_space_[space]; @@ -1538,20 +1669,22 @@ struct graph_t return num_roots_for_space_.length; } - void move_to_new_space (const hb_set_t& indices) + graph_result_t move_to_new_space (const hb_set_t& indices) { - if (num_roots_for_space_.length >= HB_REPACKER_MAX_SPACES) + if (unlikely (num_roots_for_space_.length >= HB_REPACKER_MAX_SPACES)) { DEBUG_MSG (SUBSET_REPACK, nullptr, "move_to_new_space: num of spaces %u exceeds HB_REPACKER_MAX_SPACES.", num_roots_for_space_.length); - check_success (false); - return; + return Err(LIMIT_EXCEEDED); } num_roots_for_space_.push (0); + TRY (graph_result_t::from (num_roots_for_space_, ALLOCATION_FAILURE)); unsigned new_space = num_roots_for_space_.length - 1; for (unsigned index : indices) { + if (unlikely (index >= vertices_.length)) + return Err(OUT_OF_BOUNDS); auto& node = vertices_[index]; num_roots_for_space_[node.space] = num_roots_for_space_[node.space] - 1; num_roots_for_space_[new_space] = num_roots_for_space_[new_space] + 1; @@ -1559,39 +1692,38 @@ struct graph_t distance_invalid = true; positions_invalid = true; } + return Ok(); } unsigned space_for (unsigned index, unsigned* root = nullptr) const { - loop: - assert (index < vertices_.length); - const auto& node = vertices_[index]; - if (node.space) + while (true) { - if (root != nullptr) - *root = index; - return node.space; - } + assert (index < vertices_.length); + const auto& node = vertices_[index]; + if (node.space) + { + if (root != nullptr) + *root = index; + return node.space; + } - if (!node.incoming_edges ()) - { - if (root) - *root = index; - return 0; - } + if (!node.incoming_edges ()) + { + if (root) + *root = index; + return 0; + } - index = *node.parents_iter (); - goto loop; + index = *node.parents_iter (); + } } - void err_other_error () { this->successful = false; } - size_t total_size_in_bytes () const { size_t total_size = 0; unsigned count = vertices_.length; for (unsigned i = 0; i < count; i++) { - const auto& obj = vertices_.arrayZ[i].obj; - size_t size = obj.tail - obj.head; + size_t size = vertices_.arrayZ[i].table_size (); total_size += size; } return total_size; @@ -1600,6 +1732,27 @@ struct graph_t private: + void print_orphaned_nodes () + { + if (!DEBUG_ENABLED(SUBSET_REPACK)) return; + + DEBUG_MSG (SUBSET_REPACK, nullptr, "Graph is not fully connected."); + + parents_invalid = true; + (void) update_parents(); + + if (root().incoming_edges ()) { + DEBUG_MSG (SUBSET_REPACK, nullptr, "Root node has incoming edges."); + } + + for (unsigned i = 0; i < vertices_.length; i++) + { + const auto& v = vertices_[i]; + if (!v.incoming_edges ()) + DEBUG_MSG (SUBSET_REPACK, nullptr, "Node %u is orphaned.", i); + } + } + /* * Returns the numbers of incoming edges that are 24 or 32 bits wide. */ @@ -1609,7 +1762,7 @@ struct graph_t for (unsigned p : vertices_[node_idx].parents_iter ()) { // Only real links can be wide - for (const auto& l : vertices_[p].obj.real_links) + for (const auto& l : vertices_[p].obj().real_links) { if (l.objidx == node_idx && (l.width == 3 || l.width == 4) @@ -1623,16 +1776,13 @@ struct graph_t return count; } - bool check_success (bool success) - { return this->successful && (success || ((void) err_other_error (), false)); } - public: /* * Creates a map from objid to # of incoming edges. */ - void update_parents () + graph_result_t update_parents () { - if (!parents_invalid) return; + if (!parents_invalid) return Ok(); unsigned count = vertices_.length; @@ -1641,19 +1791,21 @@ struct graph_t for (unsigned p = 0; p < count; p++) { - for (auto& l : vertices_.arrayZ[p].obj.real_links) - vertices_[l.objidx].add_parent (p, false); + for (const auto& l : vertices_.arrayZ[p].obj().real_links) + { + if (unlikely (l.objidx >= count)) return Err(INVALID_ARGUMENT); + TRY(vertices_[l.objidx].add_parent (p, false)); + } - for (auto& l : vertices_.arrayZ[p].obj.virtual_links) - vertices_[l.objidx].add_parent (p, true); + for (const auto& l : vertices_.arrayZ[p].obj().virtual_links) + { + if (unlikely (l.objidx >= count)) return Err(INVALID_ARGUMENT); + TRY(vertices_[l.objidx].add_parent (p, true)); + } } - for (unsigned i = 0; i < count; i++) - // parents arrays must be accurate or downstream operations like cycle detection - // and sorting won't work correctly. - check_success (!vertices_.arrayZ[i].in_error ()); - parents_invalid = false; + return Ok(); } /* @@ -1668,7 +1820,7 @@ struct graph_t { auto& v = vertices_[i]; v.start = current_pos; - current_pos += v.obj.tail - v.obj.head; + current_pos += v.obj().tail - v.obj().head; v.end = current_pos; } @@ -1679,9 +1831,9 @@ struct graph_t * Finds the distance to each object in the graph * from the initial node. */ - void update_distances () + graph_result_t update_distances () { - if (!distance_invalid) return; + if (!distance_invalid) return Ok(); // Uses Dijkstra's algorithm to find all of the shortest distances. // https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm @@ -1701,9 +1853,11 @@ struct graph_t hb_priority_queue_t queue; queue.alloc (count); queue.insert (0, root_idx ()); + TRY (graph_result_t::from (queue, ALLOCATION_FAILURE)); hb_vector_t visited; visited.resize (vertices_.length); + TRY (graph_result_t::from (visited, ALLOCATION_FAILURE)); while (!queue.in_error () && !queue.is_empty ()) { @@ -1713,12 +1867,15 @@ struct graph_t int64_t next_distance = next.distance; visited[next_idx] = true; - for (const auto& link : next.obj.all_links ()) + for (const auto& link : next.obj().all_links ()) { + if (unlikely (link.objidx >= vertices_.length)) + return Err(OUT_OF_BOUNDS); + if (visited[link.objidx]) continue; auto& child_v = vertices_.arrayZ[link.objidx]; - const auto& child = child_v.obj; + const auto& child = child_v.obj (); unsigned link_width = link.width ? link.width : 4; // treat virtual offsets as 32 bits wide int64_t child_weight = (child.tail - child.head) + ((int64_t) 1 << (link_width * 8)) * (child_v.space + 1); @@ -1732,14 +1889,15 @@ struct graph_t } } - check_success (!queue.in_error ()); - if (!check_success (queue.is_empty ())) + TRY (graph_result_t::from (queue, ALLOCATION_FAILURE)); + if (unlikely (!queue.is_empty ())) { print_orphaned_nodes (); - return; + return Err(ORPHANED_NODES); } distance_invalid = false; + return Ok(); } private: @@ -1747,7 +1905,7 @@ struct graph_t * Updates a link in the graph to point to a different object. Corrects the * parents vector on the previous and new child nodes. */ - void reassign_link (hb_serialize_context_t::object_t::link_t& link, + graph_result_t reassign_link (hb_serialize_context_t::object_t::link_t& link, unsigned parent_idx, unsigned new_idx, bool is_virtual) @@ -1755,33 +1913,34 @@ struct graph_t unsigned old_idx = link.objidx; link.objidx = new_idx; vertices_[old_idx].remove_parent (parent_idx); - vertices_[new_idx].add_parent (parent_idx, is_virtual); + return vertices_[new_idx].add_parent (parent_idx, is_virtual); } /* * Updates all objidx's in all links using the provided mapping. Corrects incoming edge counts. */ template - void remap_obj_indices (const hb_map_t& id_map, - Iterator subgraph, - bool only_wide = false) + graph_result_t remap_obj_indices (const hb_map_t& id_map, + Iterator subgraph, + bool only_wide = false) { - if (!id_map) return; + if (!id_map) return Ok(); for (unsigned i : subgraph) { - auto& obj = vertices_[i].obj; - unsigned num_real = obj.real_links.length; + auto& vertex = vertices_[i]; + unsigned num_real = vertex.obj().real_links.length; unsigned count = 0; - for (auto& link : obj.all_links_writer ()) + for (auto& link : vertex.all_links_writer ()) { count++; const uint32_t *v; if (!id_map.has (link.objidx, &v)) continue; if (only_wide && (link.is_signed || (link.width != 4 && link.width != 3))) continue; - reassign_link (link, i, *v, count > num_real); + TRY(reassign_link (link, i, *v, count > num_real)); } } + return Ok(); } /* @@ -1791,27 +1950,29 @@ struct graph_t * Connected targets will be added to connected and removed from targets. All visited nodes * will be added to visited. */ - void find_connected_nodes (unsigned start_idx, - hb_set_t& targets, - hb_set_t& visited, - hb_set_t& connected) + graph_result_t find_connected_nodes (unsigned start_idx, + hb_set_t& targets, + hb_set_t& visited, + hb_set_t& connected) { - if (unlikely (!check_success (!visited.in_error ()))) return; - if (visited.has (start_idx)) return; - if (unlikely (!check_success(start_idx < vertices_.length))) + TRY (graph_result_t::from (visited, ALLOCATION_FAILURE)); + if (visited.has (start_idx)) return Ok(); + if (unlikely (start_idx >= vertices_.length)) { DEBUG_MSG (SUBSET_REPACK, nullptr, "find_connected_nodes: unexpected start_idx out of bounds."); - return; + return Err(OUT_OF_BOUNDS); } // For performance we want to avoid allocating extra memory. So use the ordering_scratch_ // buffer to implement a stack for DFS. - if (unlikely (!check_success (ordering_scratch_.resize (vertices_.length)))) return; + ordering_scratch_.resize (vertices_.length); + TRY (graph_result_t::from (ordering_scratch_, ALLOCATION_FAILURE)); auto& stack = ordering_scratch_; unsigned stack_len = 0; + graph_result_t res = Ok(); auto handle_node = [&] (unsigned node_idx) { visited.add (node_idx); if (targets.has (node_idx)) { @@ -1819,12 +1980,16 @@ struct graph_t connected.add (node_idx); } - if (unlikely (!check_success (stack_len < stack.length))) return false; + if (unlikely (stack_len >= stack.length)) + { + res = Err(CYCLE_DETECTED); + return false; + } stack[stack_len++] = node_idx; return true; }; - if (!handle_node (start_idx)) return; + if (!handle_node (start_idx)) return res; while (stack_len > 0) { @@ -1832,19 +1997,24 @@ struct graph_t const auto& v = vertices_[node_idx]; // Graph is treated as undirected so search children and parents of node_idx - for (const auto& l : v.obj.all_links ()) + for (const auto& l : v.obj().all_links ()) { unsigned child_idx = l.objidx; if (visited.has (child_idx)) continue; - if (!handle_node (child_idx)) return; + if (!handle_node (child_idx)) return res; } for (unsigned parent_idx : v.parents_iter ()) { if (visited.has (parent_idx)) continue; - if (!handle_node (parent_idx)) return; + if (!handle_node (parent_idx)) return res; } } + + TRY (graph_result_t::from (visited, ALLOCATION_FAILURE)); + TRY (graph_result_t::from (connected, ALLOCATION_FAILURE)); + + return Ok(); } public: @@ -1861,10 +2031,9 @@ struct graph_t hb_vector_t ordering_scratch_; private: - bool parents_invalid; - bool distance_invalid; - bool positions_invalid; - bool successful; + bool parents_invalid = true; + bool distance_invalid = true; + bool positions_invalid = true; hb_vector_t num_roots_for_space_; hb_vector_t buffers; }; diff --git a/src/graph/gsubgpos-context.cc b/src/graph/gsubgpos-context.cc index d66eb49cf..02c5e8742 100644 --- a/src/graph/gsubgpos-context.cc +++ b/src/graph/gsubgpos-context.cc @@ -28,34 +28,41 @@ namespace graph { +graph_result_t gsubgpos_graph_context_t::create (hb_tag_t table_tag_, + graph_t& graph_) +{ + gsubgpos_graph_context_t context (table_tag_, graph_); + + if (unlikely (table_tag_ != HB_OT_TAG_GPOS + && table_tag_ != HB_OT_TAG_GSUB)) + return Err(INVALID_ARGUMENT); + + TRY_ASSIGN (const GSTAR* gstar, graph::GSTAR::graph_to_gstar (context.graph)); + TRY(gstar->find_lookups (context.graph, context.lookups)); + TRY_ASSIGN (context.lookup_list_index, gstar->get_lookup_list_index (context.graph)); + + return context; +} + gsubgpos_graph_context_t::gsubgpos_graph_context_t (hb_tag_t table_tag_, graph_t& graph_) : table_tag (table_tag_), graph (graph_), lookup_list_index (0), lookups () -{ - if (table_tag_ != HB_OT_TAG_GPOS - && table_tag_ != HB_OT_TAG_GSUB) - return; +{} - GSTAR* gstar = graph::GSTAR::graph_to_gstar (graph_); - if (gstar) { - gstar->find_lookups (graph, lookups); - lookup_list_index = gstar->get_lookup_list_index (graph_); - } -} - -unsigned gsubgpos_graph_context_t::create_node (unsigned size) +graph_result_t gsubgpos_graph_context_t::create_node (unsigned size) { char* buffer = (char*) hb_calloc (1, size); - if (!buffer) - return -1; + if (unlikely (!buffer)) + return Err(ALLOCATION_FAILURE); - if (!add_buffer (buffer)) { + auto res = add_buffer (buffer); + if (unlikely (!res.is_ok ())) { // Allocation did not get stored for freeing later. hb_free (buffer); - return -1; + return Err(res.error ()); } return graph.new_node (buffer, buffer + size); diff --git a/src/graph/gsubgpos-context.hh b/src/graph/gsubgpos-context.hh index 8969d0078..947669f87 100644 --- a/src/graph/gsubgpos-context.hh +++ b/src/graph/gsubgpos-context.hh @@ -36,6 +36,9 @@ struct Lookup; struct gsubgpos_graph_context_t { + HB_INTERNAL static graph_result_t create (hb_tag_t table_tag_, + graph_t& graph_); + hb_tag_t table_tag; graph_t& graph; unsigned lookup_list_index; @@ -43,17 +46,18 @@ struct gsubgpos_graph_context_t hb_hashmap_t subtable_to_extension; hb_hashmap_t> split_subtables; - HB_INTERNAL gsubgpos_graph_context_t (hb_tag_t table_tag_, - graph_t& graph_); - HB_INTERNAL unsigned create_node (unsigned size); + HB_INTERNAL graph_result_t create_node (unsigned size); - bool add_buffer (char* buffer) + graph_result_t add_buffer (char* buffer) { return graph.add_buffer (buffer); } private: + HB_INTERNAL gsubgpos_graph_context_t (hb_tag_t table_tag_, + graph_t& graph_); + HB_INTERNAL unsigned num_non_ext_subtables (); }; diff --git a/src/graph/gsubgpos-graph.hh b/src/graph/gsubgpos-graph.hh index dd6ed1bdd..12cf33409 100644 --- a/src/graph/gsubgpos-graph.hh +++ b/src/graph/gsubgpos-graph.hh @@ -50,10 +50,12 @@ struct ExtensionFormat1 : public OT::ExtensionFormat1 this->extensionOffset = 0; } - bool sanitize (const graph_t::vertex_t& vertex) const + graph_result_t sanitize (const graph_t::vertex_t& vertex) const { - size_t vertex_len = vertex.obj.tail - vertex.obj.head; - return vertex_len >= OT::ExtensionFormat1::static_size; + size_t vertex_len = vertex.table_size (); + if (unlikely (vertex_len < OT::ExtensionFormat1::static_size)) + return Err(SANITIZE_FAILURE); + return Ok(); } unsigned get_lookup_type () const @@ -61,7 +63,7 @@ struct ExtensionFormat1 : public OT::ExtensionFormat1 return this->extensionLookupType; } - unsigned get_subtable_index (graph_t& graph, unsigned this_index) const + graph_result_t get_subtable_index (graph_t& graph, unsigned this_index) const { return graph.index_for_offset (this_index, &this->extensionOffset); } @@ -74,12 +76,13 @@ struct Lookup : public OT::Lookup return subTable.len; } - bool sanitize (const graph_t::vertex_t& vertex) const + graph_result_t sanitize (const graph_t::vertex_t& vertex) const { - size_t vertex_len = vertex.obj.tail - vertex.obj.head; - if (vertex_len < OT::Lookup::min_size) return false; + size_t vertex_len = vertex.table_size (); + if (unlikely (vertex_len < OT::Lookup::min_size)) return Err(SANITIZE_FAILURE); hb_barrier (); - return vertex_len >= this->get_size (); + if (unlikely (vertex_len < this->get_size ())) return Err(SANITIZE_FAILURE); + return Ok(); } bool is_extension (hb_tag_t table_tag) const @@ -93,15 +96,15 @@ struct Lookup : public OT::Lookup return flag & 0x0010u; } - bool make_extension (gsubgpos_graph_context_t& c, - unsigned this_index) + graph_result_t make_extension (gsubgpos_graph_context_t& c, + unsigned this_index) { unsigned type = lookupType; unsigned ext_type = extension_type (c.table_tag); if (!ext_type || is_extension (c.table_tag)) { // NOOP - return true; + return Ok(); } DEBUG_MSG (SUBSET_REPACK, nullptr, @@ -111,42 +114,45 @@ struct Lookup : public OT::Lookup for (unsigned i = 0; i < subTable.len; i++) { - unsigned subtable_index = c.graph.index_for_offset (this_index, &subTable[i]); - if (!make_subtable_extension (c, + TRY_ASSIGN (unsigned subtable_index, c.graph.index_for_offset (this_index, &subTable[i])); + TRY (make_subtable_extension (c, this_index, - subtable_index)) - return false; + subtable_index)); } lookupType = ext_type; - return true; + return Ok(); } - bool split_subtables_if_needed (gsubgpos_graph_context_t& c, - unsigned this_index) + graph_result_t split_subtables_if_needed (gsubgpos_graph_context_t& c, + unsigned this_index) { unsigned type = lookupType; bool is_ext = is_extension (c.table_tag); if (c.table_tag != HB_OT_TAG_GPOS && c.table_tag != HB_OT_TAG_GSUB) - return true; + return Ok(); if (!is_ext && !is_supported_gpos_type(type, c) && !is_supported_gsub_type(type, c)) - return true; + return Ok(); hb_vector_t>> all_new_subtables; for (unsigned i = 0; i < subTable.len; i++) { - unsigned subtable_index = c.graph.index_for_offset (this_index, &subTable[i]); + // This assumes we are working with something like a GSUB/GPOS table, if + // sanitization fails we ignore and skip splitting for the particular sub table. + auto idx_res = c.graph.index_for_offset (this_index, &subTable[i]); + if (!idx_res.is_ok ()) continue; + unsigned subtable_index = *idx_res; if (is_ext) { unsigned ext_subtable_index = subtable_index; ExtensionFormat1* extension = (ExtensionFormat1*) c.graph.object (ext_subtable_index).head; - if (!extension || !extension->sanitize (c.graph.vertices_[ext_subtable_index])) + if (!extension || !extension->sanitize (c.graph.vertices_[ext_subtable_index]).is_ok ()) continue; - subtable_index = extension->get_subtable_index (c.graph, ext_subtable_index); + TRY_ASSIGN (subtable_index, extension->get_subtable_index (c.graph, ext_subtable_index)); type = extension->get_lookup_type (); if (!is_supported_gpos_type(type, c) && !is_supported_gsub_type(type, c)) continue; @@ -158,6 +164,7 @@ struct Lookup : public OT::Lookup if (split_result->length == 0) continue; all_new_subtables.push (hb_pair(i, *split_result)); + TRY (graph_result_t::from (all_new_subtables, ALLOCATION_FAILURE)); } else { @@ -167,9 +174,15 @@ struct Lookup : public OT::Lookup switch (type) { case 2: - new_sub_tables = split_subtable (c, subtable_index); break; + { + TRY_ASSIGN (new_sub_tables, split_subtable (c, subtable_index)); + break; + } case 4: - new_sub_tables = split_subtable (c, subtable_index); break; + { + TRY_ASSIGN (new_sub_tables, split_subtable (c, subtable_index)); + break; + } default: break; } @@ -177,42 +190,46 @@ struct Lookup : public OT::Lookup switch (type) { case 4: - new_sub_tables = split_subtable (c, subtable_index); break; + { + TRY_ASSIGN (new_sub_tables, split_subtable (c, subtable_index)); + break; + } default: break; } } - if (new_sub_tables.in_error ()) return false; - c.split_subtables.set (subtable_index, new_sub_tables); - if (new_sub_tables) + TRY (graph_result_t::from (c.split_subtables, ALLOCATION_FAILURE)); + if (new_sub_tables) { all_new_subtables.push (hb_pair (i, std::move (new_sub_tables))); + TRY (graph_result_t::from (all_new_subtables, ALLOCATION_FAILURE)); + } } } if (all_new_subtables) { - return add_sub_tables (c, this_index, type, all_new_subtables); + TRY (add_sub_tables (c, this_index, type, all_new_subtables)); } - return true; + return Ok(); } template - hb_vector_t split_subtable (gsubgpos_graph_context_t& c, - unsigned objidx) + graph_result_t> split_subtable (gsubgpos_graph_context_t& c, + unsigned objidx) { T* sub_table = (T*) c.graph.object (objidx).head; - if (!sub_table || !sub_table->sanitize (c.graph.vertices_[objidx])) - return hb_vector_t (); + if (!sub_table || !sub_table->sanitize (c.graph.vertices_[objidx]).is_ok ()) + return Ok(hb_vector_t ()); return sub_table->split_subtables (c, objidx); } - bool add_sub_tables (gsubgpos_graph_context_t& c, - unsigned this_index, - unsigned type, - const hb_vector_t>>& subtable_ids) + graph_result_t add_sub_tables (gsubgpos_graph_context_t& c, + unsigned this_index, + unsigned type, + const hb_vector_t>>& subtable_ids) { bool is_ext = is_extension (c.table_tag); auto* v = &c.graph.vertices_[this_index]; @@ -225,19 +242,19 @@ struct Lookup : public OT::Lookup size_t new_size = v->table_size () + new_subtable_count * OT::Offset16::static_size; char* buffer = (char*) hb_calloc (1, new_size); - if (!buffer) return false; - if (!c.add_buffer (buffer)) + if (unlikely (!buffer)) return Err(ALLOCATION_FAILURE); + auto res = c.add_buffer (buffer); + if (unlikely (!res.is_ok ())) { hb_free (buffer); - return false; + return res; } - hb_memcpy (buffer, v->obj.head, v->table_size()); + hb_memcpy (buffer, v->obj ().head, v->table_size()); if (use_mark_filtering_set ()) - hb_memcpy (buffer + new_size - 2, v->obj.tail - 2, 2); + hb_memcpy (buffer + new_size - 2, v->obj ().tail - 2, 2); - v->obj.head = buffer; - v->obj.tail = buffer + new_size; + v->set_buffer (buffer, buffer + new_size); Lookup* new_lookup = (Lookup*) buffer; @@ -252,29 +269,27 @@ struct Lookup : public OT::Lookup { if (is_ext) { - unsigned ext_id = create_extension_subtable (c, subtable_id, type); - c.graph.vertices_[subtable_id].add_parent (ext_id, false); + TRY_ASSIGN (unsigned ext_id, create_extension_subtable (c, subtable_id, type)); + TRY(c.graph.vertices_[subtable_id].add_parent (ext_id, false)); subtable_id = ext_id; // the reference to v may have changed on adding a node, so reassign it. v = &c.graph.vertices_[this_index]; } - auto* link = v->obj.real_links.push (); - link->width = 2; - link->objidx = subtable_id; - link->position = (char*) &new_lookup->subTable[offset_index++] - - (char*) new_lookup; - c.graph.vertices_[subtable_id].add_parent (this_index, false); + TRY(v->add_real_link(2, subtable_id, + (char*) &new_lookup->subTable[offset_index++] - (char*) new_lookup)); + TRY(c.graph.vertices_[subtable_id].add_parent (this_index, false)); } } // Repacker sort order depends on link order, which we've messed up so resort it. - v->obj.real_links.qsort (); + v->sort_real_links (); // The head location of the lookup has changed, invalidating the lookups map entry // in the context. Update the map. c.lookups.set (this_index, new_lookup); - return true; + TRY (graph_result_t::from (c.lookups, ALLOCATION_FAILURE)); + return Ok(); } void fix_existing_subtable_links (gsubgpos_graph_context_t& c, @@ -290,58 +305,50 @@ struct Lookup : public OT::Lookup unsigned insert_offset = Lookup::min_size + insert_index * OT::Offset16::static_size; shift += p.second.length; - for (auto& l : v.obj.all_links_writer ()) + for (auto& l : v.all_links_writer ()) { if (l.position > insert_offset) l.position += pos_offset; } } } - unsigned create_extension_subtable (gsubgpos_graph_context_t& c, - unsigned subtable_index, - unsigned type) + graph_result_t create_extension_subtable (gsubgpos_graph_context_t& c, + unsigned subtable_index, + unsigned type) { unsigned extension_size = OT::ExtensionFormat1::static_size; - unsigned ext_index = c.create_node (extension_size); - if (ext_index == (unsigned) -1) - return -1; + TRY_ASSIGN (unsigned ext_index, c.create_node (extension_size)); auto& ext_vertex = c.graph.vertices_[ext_index]; ExtensionFormat1* extension = - (ExtensionFormat1*) ext_vertex.obj.head; + ext_vertex.as*> (); extension->reset (type); // Make extension point at the subtable. - auto* l = ext_vertex.obj.real_links.push (); + TRY(ext_vertex.add_real_link (4, subtable_index, 4)); - l->width = 4; - l->objidx = subtable_index; - l->position = 4; - - return ext_index; + return Ok(ext_index); } - bool make_subtable_extension (gsubgpos_graph_context_t& c, - unsigned lookup_index, - unsigned subtable_index) + graph_result_t make_subtable_extension (gsubgpos_graph_context_t& c, + unsigned lookup_index, + unsigned subtable_index) { unsigned type = lookupType; - unsigned ext_index = -1; + unsigned ext_index = HB_GRAPH_INVALID; unsigned* existing_ext_index = nullptr; if (c.subtable_to_extension.has(subtable_index, &existing_ext_index)) { ext_index = *existing_ext_index; } else { - ext_index = create_extension_subtable(c, subtable_index, type); + TRY_ASSIGN (ext_index, create_extension_subtable(c, subtable_index, type)); c.subtable_to_extension.set(subtable_index, ext_index); + TRY (graph_result_t::from (c.subtable_to_extension, ALLOCATION_FAILURE)); } - if (ext_index == (unsigned) -1) - return false; - auto& subtable_vertex = c.graph.vertices_[subtable_index]; auto& lookup_vertex = c.graph.vertices_[lookup_index]; - for (auto& l : lookup_vertex.obj.real_links.writer ()) + for (auto& l : lookup_vertex.real_links_writer ()) { if (l.objidx == subtable_index) { // Change lookup to point at the extension. @@ -353,11 +360,11 @@ struct Lookup : public OT::Lookup // Make extension point at the subtable. auto& ext_vertex = c.graph.vertices_[ext_index]; - ext_vertex.add_parent (lookup_index, false); + TRY(ext_vertex.add_parent (lookup_index, false)); if (!existing_ext_index) - subtable_vertex.remap_parent (lookup_index, ext_index); + TRY(subtable_vertex.remap_parent (lookup_index, ext_index)); - return true; + return Ok(); } private: @@ -388,24 +395,25 @@ struct Lookup : public OT::Lookup template struct LookupList : public OT::LookupList { - bool sanitize (const graph_t::vertex_t& vertex) const + graph_result_t sanitize (const graph_t::vertex_t& vertex) const { - size_t vertex_len = vertex.obj.tail - vertex.obj.head; - if (vertex_len < OT::LookupList::min_size) return false; + size_t vertex_len = vertex.table_size (); + if (unlikely (vertex_len < OT::LookupList::min_size)) return Err(SANITIZE_FAILURE); hb_barrier (); - return vertex_len >= OT::LookupList::item_size * this->len; + if (unlikely (vertex_len < OT::LookupList::item_size * this->len)) return Err(SANITIZE_FAILURE); + return Ok(); } }; struct GSTAR : public OT::GSUBGPOS { - static GSTAR* graph_to_gstar (graph_t& graph) + static graph_result_t graph_to_gstar (graph_t& graph) { const auto& r = graph.root (); - GSTAR* gstar = (GSTAR*) r.obj.head; - if (!gstar || !gstar->sanitize (r)) - return nullptr; + const GSTAR* gstar = (GSTAR*) r.obj ().head; + if (unlikely (!gstar)) return Err(INVALID_ARGUMENT); + TRY (gstar->sanitize (r)); hb_barrier (); return gstar; @@ -422,48 +430,59 @@ struct GSTAR : public OT::GSUBGPOS } } - bool sanitize (const graph_t::vertex_t& vertex) + graph_result_t sanitize (const graph_t::vertex_t& vertex) const { - size_t len = vertex.obj.tail - vertex.obj.head; - if (len < OT::GSUBGPOS::min_size) return false; + size_t len = vertex.table_size (); + if (unlikely (len < OT::GSUBGPOS::min_size)) return Err(SANITIZE_FAILURE); hb_barrier (); - return len >= get_size (); + switch (u.version.major) { + case 1: break; +#ifndef HB_NO_BEYOND_64K + case 2: break; +#endif + default: return Err(SANITIZE_FAILURE); + } + if (unlikely (len < get_size ())) return Err(SANITIZE_FAILURE); + return Ok(); } - void find_lookups (graph_t& graph, - hb_hashmap_t& lookups /* OUT */) + graph_result_t find_lookups (graph_t& graph, + hb_hashmap_t& lookups /* OUT */) const { switch (u.version.major) { - case 1: find_lookups (graph, lookups); break; + case 1: TRY(find_lookups (graph, lookups)); break; #ifndef HB_NO_BEYOND_64K - case 2: find_lookups (graph, lookups); break; + case 2: TRY(find_lookups (graph, lookups)); break; #endif } + return Ok(); } - unsigned get_lookup_list_index (graph_t& graph) + graph_result_t get_lookup_list_index (graph_t& graph) const { - return graph.index_for_offset (graph.root_idx (), - get_lookup_list_field_offset()); + const void* offset = get_lookup_list_field_offset (); + if (unlikely (!offset)) return Err(INVALID_ARGUMENT); + return graph.index_for_offset (graph.root_idx (), offset); } template - void find_lookups (graph_t& graph, - hb_hashmap_t& lookups /* OUT */) + graph_result_t find_lookups (graph_t& graph, + hb_hashmap_t& lookups /* OUT */) const { - unsigned lookup_list_idx = get_lookup_list_index (graph); + TRY_ASSIGN (unsigned lookup_list_idx, get_lookup_list_index (graph)); const LookupList* lookupList = (const LookupList*) graph.object (lookup_list_idx).head; - if (!lookupList || !lookupList->sanitize (graph.vertices_[lookup_list_idx])) - return; + if (unlikely (!lookupList)) return Err(INVALID_ARGUMENT); + TRY(lookupList->sanitize (graph.vertices_[lookup_list_idx])); for (unsigned i = 0; i < lookupList->len; i++) { - unsigned lookup_idx = graph.index_for_offset (lookup_list_idx, &(lookupList->arrayZ[i])); + TRY_ASSIGN (unsigned lookup_idx, graph.index_for_offset (lookup_list_idx, &(lookupList->arrayZ[i]))); Lookup* lookup = (Lookup*) graph.object (lookup_idx).head; - if (!lookup || !lookup->sanitize (graph.vertices_[lookup_idx])) continue; + if (!lookup || !lookup->sanitize (graph.vertices_[lookup_idx]).is_ok ()) continue; lookups.set (lookup_idx, lookup); } + return Ok(); } }; diff --git a/src/graph/ligature-graph.hh b/src/graph/ligature-graph.hh index 44f777be6..daf3fd0d9 100644 --- a/src/graph/ligature-graph.hh +++ b/src/graph/ligature-graph.hh @@ -40,85 +40,84 @@ namespace graph { struct LigatureSet : public OT::Layout::GSUB_impl::LigatureSet { - bool sanitize (const graph_t::vertex_t& vertex) const + graph_result_t sanitize (const graph_t::vertex_t& vertex) const { - size_t vertex_len = vertex.obj.tail - vertex.obj.head; - if (vertex_len < OT::Layout::GSUB_impl::LigatureSet::min_size) return false; + size_t vertex_len = vertex.table_size (); + if (unlikely (vertex_len < OT::Layout::GSUB_impl::LigatureSet::min_size)) return Err(SANITIZE_FAILURE); hb_barrier (); size_t total_len = ligature.get_size() + OT::Layout::GSUB_impl::LigatureSet::min_size - ligature.len.get_size(); - if (vertex_len < total_len) { - return false; + if (unlikely (vertex_len < total_len)) { + return Err(SANITIZE_FAILURE); } - return true; + return Ok(); } }; struct LigatureSubstFormat1 : public OT::Layout::GSUB_impl::LigatureSubstFormat1_2 { - bool sanitize (const graph_t::vertex_t& vertex) const + graph_result_t sanitize (const graph_t::vertex_t& vertex) const { - size_t vertex_len = vertex.obj.tail - vertex.obj.head; + size_t vertex_len = vertex.table_size (); unsigned min_size = OT::Layout::GSUB_impl::LigatureSubstFormat1_2::min_size; - if (vertex_len < min_size) return false; + if (unlikely (vertex_len < min_size)) return Err(SANITIZE_FAILURE); hb_barrier (); - return vertex_len >= - min_size + ligatureSet.get_size() - ligatureSet.len.get_size(); + if (unlikely (vertex_len < min_size + ligatureSet.get_size() - ligatureSet.len.get_size())) + return Err(SANITIZE_FAILURE); + return Ok(); } - hb_vector_t split_subtables (gsubgpos_graph_context_t& c, - unsigned this_index) + graph_result_t> split_subtables (gsubgpos_graph_context_t& c, + unsigned this_index) { - auto split_points = compute_split_points(c, this_index); + TRY_ASSIGN (auto split_points, compute_split_points(c, this_index)); if (!split_points) - return hb_vector_t (); + return Ok(hb_vector_t ()); + TRY_ASSIGN (unsigned total_ligas, total_number_ligas(c, this_index)); + TRY_ASSIGN (hb_vector_t counts, liga_counts(c, this_index)); split_context_t split_context { c, this, this_index, - total_number_ligas(c, this_index), - liga_counts(c, this_index), + total_ligas, + std::move (counts), }; return actuate_subtable_split (split_context, split_points); } private: - unsigned total_number_ligas(gsubgpos_graph_context_t& c, unsigned this_index) const { + graph_result_t total_number_ligas(gsubgpos_graph_context_t& c, unsigned this_index) const { unsigned total = 0; for (unsigned i = 0; i < ligatureSet.len; i++) { - auto liga_set = c.graph.as_table(this_index, &ligatureSet[i]); - if (!liga_set.table) { - return 0; - } + TRY_ASSIGN (auto liga_set, c.graph.as_table(this_index, &ligatureSet[i])); total += liga_set.table->ligature.len; } - return total; + return Ok(total); } - hb_vector_t liga_counts(gsubgpos_graph_context_t& c, unsigned this_index) const { + graph_result_t> liga_counts(gsubgpos_graph_context_t& c, unsigned this_index) const { hb_vector_t result; for (unsigned i = 0; i < ligatureSet.len; i++) { - auto liga_set = c.graph.as_table(this_index, &ligatureSet[i]); + TRY_ASSIGN (auto liga_set, c.graph.as_table(this_index, &ligatureSet[i])); result.push(!liga_set.table ? 0 : liga_set.table->ligature.len); } - return result; + return graph_result_t>::from(std::move(result), ALLOCATION_FAILURE); } template - hb_vector_t ligature_index_to_object_id(const graph_t::vertex_and_table_t& liga_set) const { + graph_result_t> ligature_index_to_object_id(const graph_t::vertex_and_table_t& liga_set) const { hb_vector_t map; - map.resize_exact(liga_set.table->ligature.len); - if (map.in_error()) return map; + if (!map.resize_exact(liga_set.table->ligature.len)) return Err(ALLOCATION_FAILURE); for (unsigned i = 0; i < map.length; i++) { - map[i] = (unsigned) -1; + map[i] = HB_GRAPH_INVALID; } - for (const auto& l : liga_set.vertex->obj.real_links) { + for (const auto& l : liga_set.vertex->obj ().real_links) { if (l.position < 2) continue; unsigned array_index = (l.position - 2) / 2; map[array_index] = l.objidx; @@ -126,8 +125,8 @@ struct LigatureSubstFormat1 : public OT::Layout::GSUB_impl::LigatureSubstFormat1 return map; } - hb_vector_t compute_split_points(gsubgpos_graph_context_t& c, - unsigned this_index) const + graph_result_t> compute_split_points(gsubgpos_graph_context_t& c, + unsigned this_index) const { // For ligature subst coverage is always packed last, and as a result is where an overflow // will happen if there is one, so we can check the estimate length of the @@ -143,21 +142,17 @@ struct LigatureSubstFormat1 : public OT::Layout::GSUB_impl::LigatureSubstFormat1 accumulated += OT::HBUINT16::static_size; // for ligature set offset accumulated += OT::Layout::GSUB_impl::LigatureSet::min_size; // for ligature set table - auto liga_set = c.graph.as_table(this_index, &ligatureSet[i]); - if (!liga_set.table) { - return hb_vector_t {}; - } + TRY_ASSIGN (auto liga_set, c.graph.as_table(this_index, &ligatureSet[i])); // Finding the object id associated with an array index is O(n) // so to avoid O(n^2), precompute the mapping by scanning through // all links - auto index_to_id = ligature_index_to_object_id(liga_set); - if (index_to_id.in_error()) return hb_vector_t(); + TRY_ASSIGN (auto index_to_id, ligature_index_to_object_id (liga_set)); for (unsigned j = 0; j < liga_set.table->ligature.len; j++) { const unsigned liga_id = index_to_id[j]; - if (liga_id == (unsigned) -1) continue; // no outgoing link, ignore + if (liga_id == HB_GRAPH_INVALID) continue; // no outgoing link, ignore const unsigned liga_size = c.graph.vertices_[liga_id].table_size (); accumulated += OT::HBUINT16::static_size; // for ligature offset @@ -194,45 +189,44 @@ struct LigatureSubstFormat1 : public OT::Layout::GSUB_impl::LigatureSubstFormat1 return original_count_; } - unsigned clone_range (unsigned start, unsigned end) + graph_result_t clone_range (unsigned start, unsigned end) { return thiz->clone_range (c, this_index, liga_counts, start, end); } - bool shrink (unsigned count) + graph_result_t shrink (unsigned count) { return thiz->shrink (c, this_index, original_count(), liga_counts, count); } }; - hb_pair_t new_liga_set(gsubgpos_graph_context_t& c, unsigned count) const { + graph_result_t> new_liga_set(gsubgpos_graph_context_t& c, unsigned count) const { unsigned prime_size = OT::Layout::GSUB_impl::LigatureSet::min_size + count * SmallTypes::size; - unsigned prime_id = c.create_node (prime_size); - if (prime_id == (unsigned) -1) return hb_pair(-1, nullptr); + TRY_ASSIGN (unsigned prime_id, c.create_node (prime_size)); LigatureSet* prime = (LigatureSet*) c.graph.object (prime_id).head; prime->ligature.len = count; - return hb_pair(prime_id, prime); + return Ok(hb_pair(prime_id, prime)); } void clear_virtual_links (gsubgpos_graph_context_t& c, unsigned node_index) const { - auto& obj = c.graph.vertices_[node_index].obj; - for (const auto& l : obj.virtual_links) + auto& v = c.graph.vertices_[node_index]; + for (const auto& l : v.obj ().virtual_links) { auto& child = c.graph.vertices_[l.objidx]; child.remove_parent(node_index); } - obj.virtual_links.clear(); + v.clear_virtual_links (); } - void add_virtual_link(gsubgpos_graph_context_t& c, unsigned from, unsigned to) const { - auto& from_obj = c.graph.vertices_[from].obj; - c.graph.vertices_[to].add_parent(from, true); - auto& link = *from_obj.virtual_links.push (); - link.objidx = to; + graph_result_t add_virtual_link(gsubgpos_graph_context_t& c, unsigned from, unsigned to) const { + if (unlikely (from >= c.graph.vertices_.length || to >= c.graph.vertices_.length)) return Err(OUT_OF_BOUNDS); + TRY(c.graph.vertices_[to].add_parent (from, true)); + TRY(c.graph.vertices_[from].add_virtual_link (to)); + return Ok(); } hb_pair_t current_liga_set_bounds (gsubgpos_graph_context_t& c, @@ -241,7 +235,7 @@ struct LigatureSubstFormat1 : public OT::Layout::GSUB_impl::LigatureSubstFormat1 { // Finds the actual liga indices present in the liga set currently. Takes // into account those that have been removed by processing. - unsigned min_index = (unsigned) -1; + unsigned min_index = HB_GRAPH_INVALID; unsigned max_index = 0; for (const auto& l : liga_set.real_links) { if (l.position < 2) continue; @@ -253,28 +247,29 @@ struct LigatureSubstFormat1 : public OT::Layout::GSUB_impl::LigatureSubstFormat1 return hb_pair(min_index, max_index + 1); } - void compact_liga_set (gsubgpos_graph_context_t& c, LigatureSet* table, hb_serialize_context_t::object_t& obj) const + void compact_liga_set (gsubgpos_graph_context_t& c, LigatureSet* table, graph_t::vertex_t* v) const { + const auto& obj = v->obj (); if (table->ligature.len <= obj.real_links.length) return; // compact the remaining linked liga offsets into a continous array and shrink the node as needed. unsigned to_remove = table->ligature.len - obj.real_links.length; unsigned new_position = SmallTypes::size; - obj.real_links.qsort(); // for this to work we need to process links in order of position. - for (auto& l : obj.real_links) + v->sort_real_links (); // for this to work we need to process links in order of position. + for (auto& l : v->real_links_writer ()) { l.position = new_position; new_position += SmallTypes::size; } table->ligature.len = obj.real_links.length; - obj.tail -= to_remove * SmallTypes::size; + v->shrink_buffer (to_remove * SmallTypes::size); } - unsigned clone_range (gsubgpos_graph_context_t& c, - unsigned this_index, - hb_vector_t liga_counts, - unsigned start, unsigned end) const + graph_result_t clone_range (gsubgpos_graph_context_t& c, + unsigned this_index, + hb_vector_t liga_counts, + unsigned start, unsigned end) const { DEBUG_MSG (SUBSET_REPACK, nullptr, " Cloning LigatureSubstFormat1 (%u) range [%u, %u).", this_index, start, end); @@ -285,8 +280,7 @@ struct LigatureSubstFormat1 : public OT::Layout::GSUB_impl::LigatureSubstFormat1 unsigned prime_size = OT::Layout::GSUB_impl::LigatureSubstFormat1_2::min_size + ligatureSet.get_size() - ligatureSet.len.get_size(); - unsigned liga_subst_prime_id = c.create_node (prime_size); - if (liga_subst_prime_id == (unsigned) -1) return -1; + TRY_ASSIGN (unsigned liga_subst_prime_id, c.create_node (prime_size)); LigatureSubstFormat1* liga_subst_prime = (LigatureSubstFormat1*) c.graph.object (liga_subst_prime_id).head; liga_subst_prime->format = this->format; @@ -294,20 +288,18 @@ struct LigatureSubstFormat1 : public OT::Layout::GSUB_impl::LigatureSubstFormat1 // Create a place holder coverage prime id since we need to add virtual links to it while // generating liga and liga sets. Afterwards it will be updated to have the correct coverage. - unsigned coverage_id = c.graph.index_for_offset (this_index, &coverage); - unsigned coverage_prime_id = c.graph.duplicate(coverage_id); + TRY_ASSIGN (unsigned coverage_id, c.graph.index_for_offset (this_index, &coverage)); + TRY_ASSIGN (unsigned coverage_prime_id, c.graph.duplicate(coverage_id)); auto& coverage_prime_vertex = c.graph.vertices_[coverage_prime_id]; - auto* coverage_prime_link = c.graph.vertices_[liga_subst_prime_id].obj.real_links.push (); - coverage_prime_link->width = SmallTypes::size; - coverage_prime_link->objidx = coverage_prime_id; - coverage_prime_link->position = 2; - coverage_prime_vertex.add_parent (liga_subst_prime_id, false); + + TRY(c.graph.vertices_[liga_subst_prime_id].add_real_link (SmallTypes::size, coverage_prime_id, 2)); + TRY(coverage_prime_vertex.add_parent (liga_subst_prime_id, false)); // Locate all liga sets with ligas between start and end. // Clone or move them as needed. unsigned count = 0; unsigned liga_set_count = 0; - unsigned liga_set_start = -1; + unsigned liga_set_start = HB_GRAPH_INVALID; unsigned liga_set_end = 0; // inclusive for (unsigned i = 0; i < liga_counts.length; i++) { @@ -322,14 +314,11 @@ struct LigatureSubstFormat1 : public OT::Layout::GSUB_impl::LigatureSubstFormat1 continue; } - auto liga_set = c.graph.as_mutable_table(this_index, &ligatureSet[i]); - if (!liga_set.table) { - return -1; - } + TRY_ASSIGN (auto liga_set, c.graph.as_mutable_table(this_index, &ligatureSet[i])); unsigned liga_set_index = liga_set.index; // Bounds may need to be adjusted if some ligas have been previously removed. - hb_pair_t liga_bounds = current_liga_set_bounds(c, liga_set_index, liga_set.vertex->obj); + hb_pair_t liga_bounds = current_liga_set_bounds(c, liga_set_index, liga_set.vertex->obj ()); current_start = hb_max(count + liga_bounds.first, current_start); current_end = hb_min(count + liga_bounds.second, current_end); @@ -339,11 +328,11 @@ struct LigatureSubstFormat1 : public OT::Layout::GSUB_impl::LigatureSubstFormat1 // We can move the entire ligaset to the new liga subset object. liga_set_end = i; if (i < liga_set_start) liga_set_start = i; - liga_set_prime_id = c.graph.move_child<> (this_index, + TRY_ASSIGN (liga_set_prime_id, c.graph.move_child<> (this_index, &ligatureSet[i], liga_subst_prime_id, - &liga_subst_prime->ligatureSet[liga_set_count++]); - compact_liga_set(c, liga_set.table, liga_set.vertex->obj); + &liga_subst_prime->ligatureSet[liga_set_count++])); + compact_liga_set (c, liga_set.table, liga_set.vertex); } else { @@ -352,66 +341,61 @@ struct LigatureSubstFormat1 : public OT::Layout::GSUB_impl::LigatureSubstFormat1 unsigned start_index = hb_max(start, current_start) - count; unsigned end_index = hb_min(end, current_end) - count; unsigned liga_count = end_index - start_index; - auto result = new_liga_set(c, liga_count); + TRY_ASSIGN (auto result, new_liga_set(c, liga_count)); liga_set_prime_id = result.first; - if (liga_set_prime_id == (unsigned) -1) return -1; - c.graph.move_children( + TRY (c.graph.move_children( liga_set_index, 2 + start_index * 2, 2 + end_index * 2, liga_set_prime_id, - 2); + 2)); liga_set_end = i; if (i < liga_set_start) liga_set_start = i; - c.graph.add_link(&liga_subst_prime->ligatureSet[liga_set_count++], liga_subst_prime_id, liga_set_prime_id); + TRY (c.graph.add_link(&liga_subst_prime->ligatureSet[liga_set_count++], liga_subst_prime_id, liga_set_prime_id)); } // The new liga and all children set needs to have a virtual link to the new coverage table: - auto& liga_set_prime = c.graph.vertices_[liga_set_prime_id].obj; + const auto& liga_set_prime = c.graph.vertices_[liga_set_prime_id].obj (); clear_virtual_links(c, liga_set_prime_id); - add_virtual_link(c, liga_set_prime_id, coverage_prime_id); + TRY(add_virtual_link(c, liga_set_prime_id, coverage_prime_id)); for (const auto& l : liga_set_prime.real_links) { clear_virtual_links(c, l.objidx); - add_virtual_link(c, l.objidx, coverage_prime_id); + TRY(add_virtual_link(c, l.objidx, coverage_prime_id)); } count += num_ligas; } - c.graph.vertices_[liga_subst_prime_id].obj.tail -= (liga_subst_prime->ligatureSet.len - liga_set_count) * SmallTypes::size; + c.graph.vertices_[liga_subst_prime_id].shrink_buffer ((liga_subst_prime->ligatureSet.len - liga_set_count) * SmallTypes::size); liga_subst_prime->ligatureSet.len = liga_set_count; - if (!Coverage::filter_coverage (c, + TRY (Coverage::filter_coverage (c, coverage_prime_id, - liga_set_start, liga_set_end + 1)) - return -1; + liga_set_start, liga_set_end + 1)); - return liga_subst_prime_id; + return Ok(liga_subst_prime_id); } - bool shrink (gsubgpos_graph_context_t& c, - unsigned this_index, - unsigned old_count, - hb_vector_t liga_counts, - unsigned count) + graph_result_t shrink (gsubgpos_graph_context_t& c, + unsigned this_index, + unsigned old_count, + hb_vector_t liga_counts, + unsigned count) { DEBUG_MSG (SUBSET_REPACK, nullptr, " Shrinking LigatureSubstFormat1 (%u) to [0, %u).", this_index, count); if (count >= old_count) - return true; + return Ok(); hb_set_t retained_indices; unsigned new_liga_set_count = 0; for (unsigned i = 0; i < liga_counts.length; i++) { - auto liga_set = c.graph.as_mutable_table(this_index, &ligatureSet[i]); - if (!liga_set.table) { - return false; - } + TRY_ASSIGN (auto liga_set, c.graph.as_mutable_table(this_index, &ligatureSet[i])); // We need the virtual links to coverage removed from all descendants on this liga subst. // If any are left when we try to mutate the coverage table later it will be unnessecarily @@ -419,12 +403,11 @@ struct LigatureSubstFormat1 : public OT::Layout::GSUB_impl::LigatureSubstFormat1 clear_virtual_links(c, liga_set.index); retained_indices.add(liga_set.index); - auto index_to_id = ligature_index_to_object_id(liga_set); - if (index_to_id.in_error()) return false; + TRY_ASSIGN (auto index_to_id, ligature_index_to_object_id (liga_set)); for (unsigned i = 0; i < liga_set.table->ligature.len; i++) { unsigned liga_index = index_to_id[i]; - if (liga_index != (unsigned) -1) { + if (liga_index != HB_GRAPH_INVALID) { clear_virtual_links(c, liga_index); retained_indices.add(liga_index); } @@ -435,7 +418,7 @@ struct LigatureSubstFormat1 : public OT::Layout::GSUB_impl::LigatureSubstFormat1 // drop the trailing liga's from this set and all subsequent liga sets unsigned num_ligas_to_remove = num_ligas - count; new_liga_set_count = i + 1; - c.graph.vertices_[liga_set.index].obj.tail -= num_ligas_to_remove * SmallTypes::size; + c.graph.vertices_[liga_set.index].shrink_buffer (num_ligas_to_remove * SmallTypes::size); liga_set.table->ligature.len = count; break; } else { @@ -445,25 +428,23 @@ struct LigatureSubstFormat1 : public OT::Layout::GSUB_impl::LigatureSubstFormat1 // Adjust liga set array auto& this_vertex = c.graph.vertices_[this_index]; - this_vertex.obj.tail -= (ligatureSet.len - new_liga_set_count) * SmallTypes::size; + this_vertex.shrink_buffer ((ligatureSet.len - new_liga_set_count) * SmallTypes::size); ligatureSet.len = new_liga_set_count; // Coverage matches the number of liga sets so rebuild as needed - unsigned coverage_idx = c.graph.index_for_offset (this_index, &this->coverage); - if (coverage_idx == (unsigned) -1) return false; + TRY_ASSIGN (unsigned coverage_idx, c.graph.index_for_offset (this_index, &this->coverage)); auto& coverage_v = c.graph.vertices_[coverage_idx]; unsigned coverage_size = coverage_v.table_size (); - Coverage* coverage_table = (Coverage*) coverage_v.obj.head; + const Coverage* coverage_table = (const Coverage*) coverage_v.obj ().head; if (coverage_v.is_shared ()) { - coverage_idx = c.graph.remap_child (this_index, coverage_idx); - if (coverage_idx == (unsigned) -1) return false; + TRY_ASSIGN (coverage_idx, c.graph.remap_child (this_index, coverage_idx)); } for (unsigned i : retained_indices.iter()) - add_virtual_link(c, i, coverage_idx); + TRY(add_virtual_link(c, i, coverage_idx)); auto new_coverage = + hb_zip (coverage_table->iter (), hb_range ()) @@ -480,8 +461,8 @@ struct LigatureSubstFormat1 : public OT::Layout::GSUB_impl::LigatureSubstFormat1 struct LigatureSubst : public OT::Layout::GSUB_impl::LigatureSubst { - hb_vector_t split_subtables (gsubgpos_graph_context_t& c, - unsigned this_index) + graph_result_t> split_subtables (gsubgpos_graph_context_t& c, + unsigned this_index) { switch (u.format.v) { case 1: @@ -492,14 +473,14 @@ struct LigatureSubst : public OT::Layout::GSUB_impl::LigatureSubst // Don't split 24bit Ligature Subs #endif default: - return hb_vector_t (); + return Ok(hb_vector_t ()); } } - bool sanitize (const graph_t::vertex_t& vertex) const + graph_result_t sanitize (const graph_t::vertex_t& vertex) const { - size_t vertex_len = vertex.obj.tail - vertex.obj.head; - if (vertex_len < u.format.v.get_size ()) return false; + size_t vertex_len = vertex.table_size (); + if (unlikely (vertex_len < u.format.v.get_size ())) return Err(SANITIZE_FAILURE); hb_barrier (); switch (u.format.v) { @@ -511,7 +492,7 @@ struct LigatureSubst : public OT::Layout::GSUB_impl::LigatureSubst #endif default: // We don't handle format 2 here. - return false; + return Err(SANITIZE_FAILURE); } } }; diff --git a/src/graph/markbasepos-graph.hh b/src/graph/markbasepos-graph.hh index e476a90b8..579668569 100644 --- a/src/graph/markbasepos-graph.hh +++ b/src/graph/markbasepos-graph.hh @@ -36,62 +36,67 @@ namespace graph { struct AnchorMatrix : public OT::Layout::GPOS_impl::AnchorMatrix { - bool sanitize (const graph_t::vertex_t& vertex, unsigned class_count) const + graph_result_t sanitize (const graph_t::vertex_t& vertex, unsigned class_count) const { - size_t vertex_len = vertex.obj.tail - vertex.obj.head; - if (vertex_len < AnchorMatrix::min_size) return false; + size_t vertex_len = vertex.table_size(); + if (unlikely (vertex_len < AnchorMatrix::min_size)) return Err(SANITIZE_FAILURE); hb_barrier (); - return vertex_len >= AnchorMatrix::min_size + - OT::Offset16::static_size * class_count * this->rows; + if (unlikely (vertex_len < AnchorMatrix::min_size + + OT::Offset16::static_size * class_count * this->rows)) + return Err(SANITIZE_FAILURE); + return Ok(); } - bool shrink (gsubgpos_graph_context_t& c, - unsigned this_index, - unsigned old_class_count, - unsigned new_class_count) + graph_result_t shrink (gsubgpos_graph_context_t& c, + unsigned this_index, + unsigned old_class_count, + unsigned new_class_count) { - if (new_class_count >= old_class_count) return false; - auto& o = c.graph.vertices_[this_index].obj; + if (unlikely (new_class_count >= old_class_count)) return Err(INVALID_ARGUMENT); + auto& v = c.graph.vertices_[this_index]; + const auto& o = v.obj (); unsigned base_count = rows; - o.tail = o.head + - AnchorMatrix::min_size + - OT::Offset16::static_size * base_count * new_class_count; + v.set_buffer (o.head, + o.head + + AnchorMatrix::min_size + + OT::Offset16::static_size * base_count * new_class_count); // Reposition links into the new indexing scheme. - for (auto& link : o.real_links.writer ()) + for (auto& link : v.real_links_writer ()) { unsigned index = (link.position - 2) / 2; unsigned base = index / old_class_count; unsigned klass = index % old_class_count; - if (klass >= new_class_count) + if (unlikely (klass >= new_class_count)) // should have already been removed - return false; + return Err(INVALID_ARGUMENT); unsigned new_index = base * new_class_count + klass; link.position = (char*) &(this->matrixZ[new_index]) - (char*) this; } - return true; + return Ok(); } - unsigned clone (gsubgpos_graph_context_t& c, - unsigned this_index, - unsigned start, - unsigned end, - unsigned class_count) + graph_result_t clone (gsubgpos_graph_context_t& c, + unsigned this_index, + unsigned start, + unsigned end, + unsigned class_count) { unsigned base_count = rows; unsigned new_class_count = end - start; unsigned size = AnchorMatrix::min_size + OT::Offset16::static_size * new_class_count * rows; - unsigned prime_id = c.create_node (size); - if (prime_id == (unsigned) -1) return -1; + TRY_ASSIGN (unsigned prime_id, c.create_node (size)); AnchorMatrix* prime = (AnchorMatrix*) c.graph.object (prime_id).head; prime->rows = base_count; - auto& o = c.graph.vertices_[this_index].obj; + auto& v = c.graph.vertices_[this_index]; + const auto& o = v.obj (); + int num_links = o.real_links.length; for (int i = 0; i < num_links; i++) { @@ -106,43 +111,48 @@ struct AnchorMatrix : public OT::Layout::GPOS_impl::AnchorMatrix unsigned child_idx = link.objidx; - c.graph.add_link (&(prime->matrixZ[new_index]), - prime_id, - child_idx); + TRY (c.graph.add_link (&(prime->matrixZ[new_index]), + prime_id, + child_idx)); auto& child = c.graph.vertices_[child_idx]; child.remove_parent (this_index); - o.real_links.remove_unordered (i); + v.remove_real_link_unordered (i); num_links--; i--; } - return prime_id; + // Restore correct ordering after the above removes, which mess up link ordering. + v.sort_real_links (); + + return Ok(prime_id); } }; struct MarkArray : public OT::Layout::GPOS_impl::MarkArray { - bool sanitize (const graph_t::vertex_t& vertex) const + graph_result_t sanitize (const graph_t::vertex_t& vertex) const { - size_t vertex_len = vertex.obj.tail - vertex.obj.head; + size_t vertex_len = vertex.table_size(); unsigned min_size = MarkArray::min_size; - if (vertex_len < min_size) return false; + if (unlikely (vertex_len < min_size)) return Err(SANITIZE_FAILURE); hb_barrier (); - return vertex_len >= get_size (); + if (unlikely (vertex_len < get_size ())) return Err(SANITIZE_FAILURE); + return Ok(); } - bool shrink (gsubgpos_graph_context_t& c, - const hb_hashmap_t& mark_array_links, - unsigned this_index, - unsigned new_class_count) + graph_result_t shrink (gsubgpos_graph_context_t& c, + const hb_hashmap_t& mark_array_links, + unsigned this_index, + unsigned new_class_count) { - auto& o = c.graph.vertices_[this_index].obj; + auto& v = c.graph.vertices_[this_index]; + const auto& o = v.obj (); for (const auto& link : o.real_links) c.graph.vertices_[link.objidx].remove_parent (this_index); - o.real_links.reset (); + v.clear_real_links (); unsigned new_index = 0; for (const auto& record : this->iter ()) @@ -159,27 +169,27 @@ struct MarkArray : public OT::Layout::GPOS_impl::MarkArray continue; } - c.graph.add_link (&(*this)[new_index].markAnchor, this_index, *objidx); + TRY (c.graph.add_link (&(*this)[new_index].markAnchor, this_index, *objidx)); new_index++; } this->len = new_index; - o.tail = o.head + MarkArray::min_size + - OT::Layout::GPOS_impl::MarkRecord::static_size * new_index; - return true; + v.set_buffer (o.head, o.head + MarkArray::min_size + + OT::Layout::GPOS_impl::MarkRecord::static_size * new_index); + + return Ok(); } - unsigned clone (gsubgpos_graph_context_t& c, - unsigned this_index, - const hb_hashmap_t& pos_to_index, - hb_set_t& marks, - unsigned start_class) + graph_result_t clone (gsubgpos_graph_context_t& c, + unsigned this_index, + const hb_hashmap_t& pos_to_index, + hb_set_t& marks, + unsigned start_class) { unsigned size = MarkArray::min_size + OT::Layout::GPOS_impl::MarkRecord::static_size * marks.get_population (); - unsigned prime_id = c.create_node (size); - if (prime_id == (unsigned) -1) return -1; + TRY_ASSIGN (unsigned prime_id, c.create_node (size)); MarkArray* prime = (MarkArray*) c.graph.object (prime_id).head; prime->len = marks.get_population (); @@ -191,45 +201,50 @@ struct MarkArray : public OT::Layout::GPOS_impl::MarkArray unsigned offset_pos = (char*) &((*this)[mark].markAnchor) - (char*) this; unsigned* anchor_index; if (pos_to_index.has (offset_pos, &anchor_index)) - c.graph.move_child (this_index, - &((*this)[mark].markAnchor), - prime_id, - &((*prime)[i].markAnchor)); + TRY (c.graph.move_child (this_index, + &((*this)[mark].markAnchor), + prime_id, + &((*prime)[i].markAnchor))); i++; } - return prime_id; + // Restore correct ordering of the vertex links which are disturbed by move_child. + c.graph.vertices_[this_index].sort_real_links (); + + return Ok(prime_id); } }; struct MarkBasePosFormat1 : public OT::Layout::GPOS_impl::MarkBasePosFormat1_2 { - bool sanitize (const graph_t::vertex_t& vertex) const + graph_result_t sanitize (const graph_t::vertex_t& vertex) const { - size_t vertex_len = vertex.obj.tail - vertex.obj.head; - return vertex_len >= MarkBasePosFormat1::static_size; + size_t vertex_len = vertex.table_size (); + if (unlikely (vertex_len < MarkBasePosFormat1::static_size)) + return Err(SANITIZE_FAILURE); + return Ok(); } - hb_vector_t split_subtables (gsubgpos_graph_context_t& c, - unsigned this_index) + graph_result_t> split_subtables (gsubgpos_graph_context_t& c, + unsigned this_index) { hb_set_t visited; - const unsigned base_coverage_id = c.graph.index_for_offset (this_index, &baseCoverage); + TRY_ASSIGN (const unsigned base_coverage_id, c.graph.index_for_offset (this_index, &baseCoverage)); + const unsigned base_size = OT::Layout::GPOS_impl::MarkBasePosFormat1_2::min_size + MarkArray::min_size + AnchorMatrix::min_size + c.graph.vertices_[base_coverage_id].table_size (); - hb_vector_t class_to_info = get_class_info (c, this_index); + TRY_ASSIGN (hb_vector_t class_to_info, get_class_info (c, this_index)); unsigned class_count = classCount; - auto base_array = c.graph.as_table (this_index, - &baseArray, - class_count); - if (!base_array) return hb_vector_t (); + TRY_ASSIGN (auto base_array, c.graph.as_table (this_index, + &baseArray, + class_count)); unsigned base_count = base_array.table->rows; unsigned partial_coverage_size = 4; @@ -245,7 +260,7 @@ struct MarkBasePosFormat1 : public OT::Layout::GPOS_impl::MarkBasePosFormat1_2= (1 << 16)) { split_points.push (klass); + TRY (graph_result_t::from (split_points, ALLOCATION_FAILURE)); accumulated = base_size + accumulated_delta; partial_coverage_size = 4 + OT::HBUINT16::static_size * info.marks.get_population (); visited.clear (); // node sharing isn't allowed between splits. @@ -260,13 +276,15 @@ struct MarkBasePosFormat1 : public OT::Layout::GPOS_impl::MarkBasePosFormat1_2 (split_context, split_points); @@ -303,30 +321,30 @@ struct MarkBasePosFormat1 : public OT::Layout::GPOS_impl::MarkBasePosFormat1_2classCount; } - unsigned clone_range (unsigned start, unsigned end) + graph_result_t clone_range (unsigned start, unsigned end) { return thiz->clone_range (*this, this->this_index, start, end); } - bool shrink (unsigned count) + graph_result_t shrink (unsigned count) { return thiz->shrink (*this, this->this_index, count); } }; - hb_vector_t get_class_info (gsubgpos_graph_context_t& c, - unsigned this_index) + graph_result_t> get_class_info (gsubgpos_graph_context_t& c, + unsigned this_index) { hb_vector_t class_to_info; unsigned class_count = classCount; if (!class_count) return class_to_info; - if (!class_to_info.resize (class_count)) - return hb_vector_t(); + if (unlikely (!class_to_info.resize (class_count))) + return Err(ALLOCATION_FAILURE); + + TRY_ASSIGN (auto mark_array, c.graph.as_table (this_index, &markArray)); - auto mark_array = c.graph.as_table (this_index, &markArray); - if (!mark_array) return hb_vector_t (); unsigned mark_count = mark_array.table->len; for (unsigned mark = 0; mark < mark_count; mark++) { @@ -335,7 +353,7 @@ struct MarkBasePosFormat1 : public OT::Layout::GPOS_impl::MarkBasePosFormat1_2obj.real_links) + for (const auto& link : mark_array.vertex->obj ().real_links) { unsigned mark = (link.position - 2) / OT::Layout::GPOS_impl::MarkRecord::static_size; @@ -344,11 +362,12 @@ struct MarkBasePosFormat1 : public OT::Layout::GPOS_impl::MarkBasePosFormat1_2 shrink (split_context_t& sc, + unsigned this_index, + unsigned count) { DEBUG_MSG (SUBSET_REPACK, nullptr, " Shrinking MarkBasePosFormat1 (%u) to [0, %u).", @@ -369,49 +388,48 @@ struct MarkBasePosFormat1 : public OT::Layout::GPOS_impl::MarkBasePosFormat1_2= old_count) - return true; + return Ok(); classCount = count; - auto mark_coverage = sc.c.graph.as_mutable_table (this_index, - &markCoverage); - if (!mark_coverage) return false; + TRY_ASSIGN (auto mark_coverage, sc.c.graph.as_mutable_table (this_index, + &markCoverage)); + hb_set_t marks = sc.marks_for (0, count); auto new_coverage = + hb_enumerate (mark_coverage.table->iter ()) | hb_filter (marks, hb_first) | hb_map_retains_sorting (hb_second) ; - if (!Coverage::make_coverage (sc.c, + new_coverage, + TRY (Coverage::make_coverage (sc.c, + new_coverage, mark_coverage.index, - 4 + 2 * marks.get_population ())) - return false; + 4 + 2 * marks.get_population ())); - auto base_array = sc.c.graph.as_mutable_table (this_index, - &baseArray, - old_count); - if (!base_array || !base_array.table->shrink (sc.c, - base_array.index, - old_count, - count)) - return false; + TRY_ASSIGN (auto base_array, sc.c.graph.as_mutable_table (this_index, + &baseArray, + old_count)); - auto mark_array = sc.c.graph.as_mutable_table (this_index, - &markArray); - if (!mark_array || !mark_array.table->shrink (sc.c, - sc.mark_array_links, - mark_array.index, - count)) - return false; + TRY (base_array.table->shrink (sc.c, + base_array.index, + old_count, + count)); - return true; + TRY_ASSIGN (auto mark_array, sc.c.graph.as_mutable_table (this_index, + &markArray)); + + TRY (mark_array.table->shrink (sc.c, + sc.mark_array_links, + mark_array.index, + count)); + + return Ok(); } // Create a new MarkBasePos that has all of the data for classes from [start, end). - unsigned clone_range (split_context_t& sc, - unsigned this_index, - unsigned start, unsigned end) const + graph_result_t clone_range (split_context_t& sc, + unsigned this_index, + unsigned start, unsigned end) const { DEBUG_MSG (SUBSET_REPACK, nullptr, " Cloning MarkBasePosFormat1 (%u) range [%u, %u).", this_index, start, end); @@ -419,64 +437,63 @@ struct MarkBasePosFormat1 : public OT::Layout::GPOS_impl::MarkBasePosFormat1_2::static_size; - unsigned prime_id = sc.c.create_node (prime_size); - if (prime_id == (unsigned) -1) return -1; + TRY_ASSIGN (unsigned prime_id, sc.c.create_node (prime_size)); MarkBasePosFormat1* prime = (MarkBasePosFormat1*) graph.object (prime_id).head; prime->format = this->format; unsigned new_class_count = end - start; prime->classCount = new_class_count; - unsigned base_coverage_id = - graph.index_for_offset (sc.this_index, &baseCoverage); - graph.add_link (&(prime->baseCoverage), prime_id, base_coverage_id); + TRY_ASSIGN (unsigned base_coverage_id, + graph.index_for_offset (sc.this_index, &baseCoverage)); + + TRY (graph.add_link (&(prime->baseCoverage), prime_id, base_coverage_id)); + + TRY_ASSIGN (auto mark_coverage, sc.c.graph.as_table (this_index, + &markCoverage)); - auto mark_coverage = sc.c.graph.as_table (this_index, - &markCoverage); - if (!mark_coverage) return false; hb_set_t marks = sc.marks_for (start, end); auto new_coverage = + hb_enumerate (mark_coverage.table->iter ()) | hb_filter (marks, hb_first) | hb_map_retains_sorting (hb_second) ; - if (!Coverage::add_coverage (sc.c, + TRY (Coverage::add_coverage (sc.c, prime_id, 2, + new_coverage, - marks.get_population () * 2 + 4)) - return -1; + marks.get_population () * 2 + 4)); - auto mark_array = - graph.as_mutable_table (sc.this_index, &markArray); - if (!mark_array) return -1; - unsigned new_mark_array = - mark_array.table->clone (sc.c, - mark_array.index, - sc.mark_array_links, - marks, - start); - graph.add_link (&(prime->markArray), prime_id, new_mark_array); + TRY_ASSIGN (auto mark_array, + graph.as_mutable_table (sc.this_index, &markArray)); + + TRY_ASSIGN (unsigned new_mark_array, + mark_array.table->clone (sc.c, + mark_array.index, + sc.mark_array_links, + marks, + start)); + TRY (graph.add_link (&(prime->markArray), prime_id, new_mark_array)); unsigned class_count = classCount; - auto base_array = - graph.as_mutable_table (sc.this_index, &baseArray, class_count); - if (!base_array) return -1; - unsigned new_base_array = - base_array.table->clone (sc.c, - base_array.index, - start, end, this->classCount); - graph.add_link (&(prime->baseArray), prime_id, new_base_array); + TRY_ASSIGN (auto base_array, + graph.as_mutable_table (sc.this_index, &baseArray, class_count)); - return prime_id; + TRY_ASSIGN (unsigned new_base_array, + base_array.table->clone (sc.c, + base_array.index, + start, end, this->classCount)); + TRY (graph.add_link (&(prime->baseArray), prime_id, new_base_array)); + + return Ok(prime_id); } }; struct MarkBasePos : public OT::Layout::GPOS_impl::MarkBasePos { - hb_vector_t split_subtables (gsubgpos_graph_context_t& c, - unsigned this_index) + graph_result_t> split_subtables (gsubgpos_graph_context_t& c, + unsigned this_index) { switch (u.format.v) { case 1: @@ -487,14 +504,14 @@ struct MarkBasePos : public OT::Layout::GPOS_impl::MarkBasePos // Don't split 24bit MarkBasePos's. #endif default: - return hb_vector_t (); + return Ok(hb_vector_t ()); } } - bool sanitize (const graph_t::vertex_t& vertex) const + graph_result_t sanitize (const graph_t::vertex_t& vertex) const { - size_t vertex_len = vertex.obj.tail - vertex.obj.head; - if (vertex_len < u.format.v.get_size ()) return false; + size_t vertex_len = vertex.table_size (); + if (unlikely (vertex_len < u.format.v.get_size ())) return Err(SANITIZE_FAILURE); hb_barrier (); switch (u.format.v) { @@ -506,7 +523,7 @@ struct MarkBasePos : public OT::Layout::GPOS_impl::MarkBasePos #endif default: // We don't handle format 3 and 4 here. - return false; + return Err(SANITIZE_FAILURE); } } }; diff --git a/src/graph/pairpos-graph.hh b/src/graph/pairpos-graph.hh index 65b170017..619735520 100644 --- a/src/graph/pairpos-graph.hh +++ b/src/graph/pairpos-graph.hh @@ -37,23 +37,24 @@ namespace graph { struct PairPosFormat1 : public OT::Layout::GPOS_impl::PairPosFormat1_3 { - bool sanitize (const graph_t::vertex_t& vertex) const + graph_result_t sanitize (const graph_t::vertex_t& vertex) const { - size_t vertex_len = vertex.obj.tail - vertex.obj.head; + size_t vertex_len = vertex.table_size (); unsigned min_size = OT::Layout::GPOS_impl::PairPosFormat1_3::min_size; - if (vertex_len < min_size) return false; + if (unlikely (vertex_len < min_size)) return Err(SANITIZE_FAILURE); hb_barrier (); - return vertex_len >= - min_size + pairSet.get_size () - pairSet.len.get_size(); + if (unlikely (vertex_len < min_size + pairSet.get_size () - pairSet.len.get_size())) + return Err(SANITIZE_FAILURE); + return Ok(); } - hb_vector_t split_subtables (gsubgpos_graph_context_t& c, - unsigned this_index) + graph_result_t> split_subtables (gsubgpos_graph_context_t& c, + unsigned this_index) { hb_set_t visited; - const unsigned coverage_id = c.graph.index_for_offset (this_index, &coverage); + TRY_ASSIGN (const unsigned coverage_id, c.graph.index_for_offset (this_index, &coverage)); const unsigned coverage_size = c.graph.vertices_[coverage_id].table_size (); const unsigned base_size = OT::Layout::GPOS_impl::PairPosFormat1_3::min_size; @@ -62,9 +63,9 @@ struct PairPosFormat1 : public OT::Layout::GPOS_impl::PairPosFormat1_3 split_points; for (unsigned i = 0; i < pairSet.len; i++) { - unsigned pair_set_index = pair_set_graph_index (c, this_index, i); + TRY_ASSIGN (unsigned pair_set_index, pair_set_graph_index (c, this_index, i)); unsigned accumulated_delta = - c.graph.find_subgraph_size (pair_set_index, visited) + + c.graph.find_subgraph_size (pair_set_index, visited).value_or (0) + SmallTypes::size; // for PairSet offset. partial_coverage_size += OT::HBUINT16::static_size; @@ -74,6 +75,7 @@ struct PairPosFormat1 : public OT::Layout::GPOS_impl::PairPosFormat1_3= (1 << 16)) { split_points.push (i); + TRY (graph_result_t::from (split_points, ALLOCATION_FAILURE)); accumulated = base_size + accumulated_delta; partial_coverage_size = 6; visited.clear (); // node sharing isn't allowed between splits. @@ -101,20 +103,20 @@ struct PairPosFormat1 : public OT::Layout::GPOS_impl::PairPosFormat1_3pairSet.len; } - unsigned clone_range (unsigned start, unsigned end) + graph_result_t clone_range (unsigned start, unsigned end) { return thiz->clone_range (this->c, this->this_index, start, end); } - bool shrink (unsigned count) + graph_result_t shrink (unsigned count) { return thiz->shrink (this->c, this->this_index, count); } }; - bool shrink (gsubgpos_graph_context_t& c, - unsigned this_index, - unsigned count) + graph_result_t shrink (gsubgpos_graph_context_t& c, + unsigned this_index, + unsigned count) { DEBUG_MSG (SUBSET_REPACK, nullptr, " Shrinking PairPosFormat1 (%u) to [0, %u).", @@ -122,13 +124,12 @@ struct PairPosFormat1 : public OT::Layout::GPOS_impl::PairPosFormat1_3= old_count) - return true; + return Ok(); pairSet.len = count; - c.graph.vertices_[this_index].obj.tail -= (old_count - count) * SmallTypes::size; + c.graph.vertices_[this_index].shrink_buffer ((old_count - count) * SmallTypes::size); - auto coverage = c.graph.as_mutable_table (this_index, &this->coverage); - if (!coverage) return false; + TRY_ASSIGN (auto coverage, c.graph.as_mutable_table (this_index, &this->coverage)); unsigned coverage_size = coverage.vertex->table_size (); auto new_coverage = @@ -144,9 +145,9 @@ struct PairPosFormat1 : public OT::Layout::GPOS_impl::PairPosFormat1_3 clone_range (gsubgpos_graph_context_t& c, + unsigned this_index, + unsigned start, unsigned end) const { DEBUG_MSG (SUBSET_REPACK, nullptr, " Cloning PairPosFormat1 (%u) range [%u, %u).", this_index, start, end); @@ -155,8 +156,7 @@ struct PairPosFormat1 : public OT::Layout::GPOS_impl::PairPosFormat1_3::min_size + num_pair_sets * SmallTypes::size; - unsigned pair_pos_prime_id = c.create_node (prime_size); - if (pair_pos_prime_id == (unsigned) -1) return -1; + TRY_ASSIGN (unsigned pair_pos_prime_id, c.create_node (prime_size)); PairPosFormat1* pair_pos_prime = (PairPosFormat1*) c.graph.object (pair_pos_prime_id).head; pair_pos_prime->format = this->format; @@ -166,26 +166,28 @@ struct PairPosFormat1 : public OT::Layout::GPOS_impl::PairPosFormat1_3 (this_index, - &pairSet[i], - pair_pos_prime_id, - &pair_pos_prime->pairSet[i - start]); + TRY (c.graph.move_child<> (this_index, + &pairSet[i], + pair_pos_prime_id, + &pair_pos_prime->pairSet[i - start])); } - unsigned coverage_id = c.graph.index_for_offset (this_index, &coverage); - if (!Coverage::clone_coverage (c, + // Restore correct ordering of the vertex links which are disturbed by move_child. + c.graph.vertices_[this_index].sort_real_links (); + + TRY_ASSIGN (unsigned coverage_id, c.graph.index_for_offset (this_index, &coverage)); + TRY (Coverage::clone_coverage (c, coverage_id, pair_pos_prime_id, 2, - start, end)) - return -1; + start, end)); - return pair_pos_prime_id; + return Ok(pair_pos_prime_id); } - unsigned pair_set_graph_index (gsubgpos_graph_context_t& c, unsigned this_index, unsigned i) const + graph_result_t pair_set_graph_index (gsubgpos_graph_context_t& c, unsigned this_index, unsigned i) const { return c.graph.index_for_offset (this_index, &pairSet[i]); } @@ -193,32 +195,33 @@ struct PairPosFormat1 : public OT::Layout::GPOS_impl::PairPosFormat1_3 { - bool sanitize (const graph_t::vertex_t& vertex) const + graph_result_t sanitize (const graph_t::vertex_t& vertex) const { size_t vertex_len = vertex.table_size (); unsigned min_size = OT::Layout::GPOS_impl::PairPosFormat2_4::min_size; - if (vertex_len < min_size) return false; + if (unlikely (vertex_len < min_size)) return Err(SANITIZE_FAILURE); hb_barrier (); const unsigned class1_count = class1Count; - return vertex_len >= - min_size + class1_count * get_class1_record_size (); + if (unlikely (vertex_len < min_size + class1_count * get_class1_record_size ())) + return Err(SANITIZE_FAILURE); + return Ok(); } - hb_vector_t split_subtables (gsubgpos_graph_context_t& c, - unsigned this_index) + graph_result_t> split_subtables (gsubgpos_graph_context_t& c, + unsigned this_index) { const unsigned base_size = OT::Layout::GPOS_impl::PairPosFormat2_4::min_size; - const unsigned class_def_2_size = size_of (c, this_index, &classDef2); - const Coverage* coverage = get_coverage (c, this_index); - const ClassDef* class_def_1 = get_class_def_1 (c, this_index); + TRY_ASSIGN (const unsigned class_def_2_size, size_of (c, this_index, &classDef2)); + TRY_ASSIGN (const Coverage* coverage, get_coverage (c, this_index)); + TRY_ASSIGN (const ClassDef* class_def_1, get_class_def_1 (c, this_index)); auto gid_and_class = + coverage->iter () | hb_map_retains_sorting ([&] (hb_codepoint_t gid) { return hb_codepoint_pair_t (gid, class_def_1->get_class (gid)); }) ; - class_def_size_estimator_t estimator (gid_and_class); + TRY_ASSIGN (class_def_size_estimator_t estimator, class_def_size_estimator_t::create (gid_and_class)); const unsigned class1_count = class1Count; const unsigned class2_count = class2Count; @@ -236,7 +239,7 @@ struct PairPosFormat2 : public OT::Layout::GPOS_impl::PairPosFormat2_4 split_points; - hb_hashmap_t device_tables = get_all_device_tables (c, this_index); + TRY_ASSIGN (auto device_tables, get_all_device_tables (c, this_index)); hb_vector_t format1_device_table_indices = valueFormat1.get_device_table_indices (); hb_vector_t format2_device_table_indices = valueFormat2.get_device_table_indices (); bool has_device_tables = bool(format1_device_table_indices) || bool(format2_device_table_indices); @@ -276,6 +279,7 @@ struct PairPosFormat2 : public OT::Layout::GPOS_impl::PairPosFormat2_4= (1 << 16)) { split_points.push (i); + TRY (graph_result_t::from (split_points, ALLOCATION_FAILURE)); // split does not include i, so add the size for i when we reset the size counters. accumulated = base_size + accumulated_delta; @@ -326,12 +330,12 @@ struct PairPosFormat2 : public OT::Layout::GPOS_impl::PairPosFormat2_4class1Count; } - unsigned clone_range (unsigned start, unsigned end) + graph_result_t clone_range (unsigned start, unsigned end) { return thiz->clone_range (*this, start, end); } - bool shrink (unsigned count) + graph_result_t shrink (unsigned count) { return thiz->shrink (*this, count); } @@ -344,8 +348,8 @@ struct PairPosFormat2 : public OT::Layout::GPOS_impl::PairPosFormat2_4 clone_range (split_context_t& split_context, + unsigned start, unsigned end) const { DEBUG_MSG (SUBSET_REPACK, nullptr, " Cloning PairPosFormat2 (%u) range [%u, %u).", split_context.this_index, start, end); @@ -356,8 +360,7 @@ struct PairPosFormat2 : public OT::Layout::GPOS_impl::PairPosFormat2_4::min_size + num_records * split_context.class1_record_size; - unsigned pair_pos_prime_id = split_context.c.create_node (prime_size); - if (pair_pos_prime_id == (unsigned) -1) return -1; + TRY_ASSIGN (unsigned pair_pos_prime_id, split_context.c.create_node (prime_size)); PairPosFormat2* pair_pos_prime = (PairPosFormat2*) graph.object (pair_pos_prime_id).head; @@ -366,24 +369,24 @@ struct PairPosFormat2 : public OT::Layout::GPOS_impl::PairPosFormat2_4valueFormat2 = this->valueFormat2; pair_pos_prime->class1Count = num_records; pair_pos_prime->class2Count = this->class2Count; - clone_class1_records (split_context, - pair_pos_prime_id, - start, - end); + TRY (clone_class1_records (split_context, + pair_pos_prime_id, + start, + end)); + + TRY_ASSIGN (unsigned coverage_id, + graph.index_for_offset (split_context.this_index, &coverage)); + TRY_ASSIGN (unsigned class_def_1_id, + graph.index_for_offset (split_context.this_index, &classDef1)); - unsigned coverage_id = - graph.index_for_offset (split_context.this_index, &coverage); - unsigned class_def_1_id = - graph.index_for_offset (split_context.this_index, &classDef1); auto& coverage_v = graph.vertices_[coverage_id]; auto& class_def_1_v = graph.vertices_[class_def_1_id]; - Coverage* coverage_table = (Coverage*) coverage_v.obj.head; - ClassDef* class_def_1_table = (ClassDef*) class_def_1_v.obj.head; - if (!coverage_table - || !coverage_table->sanitize (coverage_v) - || !class_def_1_table - || !class_def_1_table->sanitize (class_def_1_v)) - return -1; + const Coverage* coverage_table = (const Coverage*) coverage_v.obj().head; + const ClassDef* class_def_1_table = (const ClassDef*) class_def_1_v.obj().head; + if (unlikely (!coverage_table || !class_def_1_table)) + return Err(INVALID_ARGUMENT); + TRY (coverage_table->sanitize (coverage_v)); + TRY (class_def_1_table->sanitize (class_def_1_v)); auto klass_map = + coverage_table->iter () @@ -399,36 +402,32 @@ struct PairPosFormat2 : public OT::Layout::GPOS_impl::PairPosFormat2_4width = SmallTypes::size; - class_def_link->objidx = class_def_2_id; - class_def_link->position = 10; - graph.vertices_[class_def_2_id].add_parent (pair_pos_prime_id, false); + TRY_ASSIGN (unsigned class_def_2_id, + graph.index_for_offset (split_context.this_index, &classDef2)); - return pair_pos_prime_id; + TRY(graph.vertices_[pair_pos_prime_id].add_real_link (SmallTypes::size, class_def_2_id, 10)); + TRY(graph.vertices_[class_def_2_id].add_parent (pair_pos_prime_id, false)); + + return Ok(pair_pos_prime_id); } - void clone_class1_records (split_context_t& split_context, - unsigned pair_pos_prime_id, - unsigned start, unsigned end) const + graph_result_t clone_class1_records (split_context_t& split_context, + unsigned pair_pos_prime_id, + unsigned start, unsigned end) const { PairPosFormat2* pair_pos_prime = (PairPosFormat2*) split_context.c.graph.object (pair_pos_prime_id).head; @@ -442,7 +441,7 @@ struct PairPosFormat2 : public OT::Layout::GPOS_impl::PairPosFormat2_4& device_table_indices, - unsigned old_value_record_index, - unsigned new_value_record_index) const + graph_result_t transfer_device_tables (split_context_t& split_context, + unsigned pair_pos_prime_id, + const hb_vector_t& device_table_indices, + unsigned old_value_record_index, + unsigned new_value_record_index) const { PairPosFormat2* pair_pos_prime = (PairPosFormat2*) split_context.c.graph.object (pair_pos_prime_id).head; @@ -485,16 +485,21 @@ struct PairPosFormat2 : public OT::Layout::GPOS_impl::PairPosFormat2_4values[new_value_record_index + i]); + (OT::Offset16*) &pair_pos_prime->values[new_value_record_index + i])); } + + // Restore correct ordering of the vertex links which are disturbed by move_child. + split_context.c.graph.vertices_[split_context.this_index].sort_real_links (); + + return Ok(); } - bool shrink (split_context_t& split_context, - unsigned count) + graph_result_t shrink (split_context_t& split_context, + unsigned count) { DEBUG_MSG (SUBSET_REPACK, nullptr, " Shrinking PairPosFormat2 (%u) to [0, %u).", @@ -502,20 +507,18 @@ struct PairPosFormat2 : public OT::Layout::GPOS_impl::PairPosFormat2_4= old_count) - return true; + return Ok(); graph_t& graph = split_context.c.graph; class1Count = count; - graph.vertices_[split_context.this_index].obj.tail -= - (old_count - count) * split_context.class1_record_size; + graph.vertices_[split_context.this_index].shrink_buffer( + (old_count - count) * split_context.class1_record_size); - auto coverage = - graph.as_mutable_table (split_context.this_index, &this->coverage); - if (!coverage) return false; + TRY_ASSIGN (auto coverage, + graph.as_mutable_table (split_context.this_index, &this->coverage)); - auto class_def_1 = - graph.as_mutable_table (split_context.this_index, &classDef1); - if (!class_def_1) return false; + TRY_ASSIGN (auto class_def_1, + graph.as_mutable_table (split_context.this_index, &classDef1)); auto klass_map = + coverage.table->iter () @@ -528,13 +531,12 @@ struct PairPosFormat2 : public OT::Layout::GPOS_impl::PairPosFormat2_4table_size ()); } - hb_hashmap_t + graph_result_t> get_all_device_tables (gsubgpos_graph_context_t& c, unsigned this_index) const { @@ -550,27 +552,28 @@ struct PairPosFormat2 : public OT::Layout::GPOS_impl::PairPosFormat2_4 get_coverage (gsubgpos_graph_context_t& c, + unsigned this_index) const { - unsigned coverage_id = c.graph.index_for_offset (this_index, &coverage); + TRY_ASSIGN (unsigned coverage_id, c.graph.index_for_offset (this_index, &coverage)); auto& coverage_v = c.graph.vertices_[coverage_id]; - Coverage* coverage_table = (Coverage*) coverage_v.obj.head; - if (!coverage_table || !coverage_table->sanitize (coverage_v)) - return &Null(Coverage); + const Coverage* coverage_table = (const Coverage*) coverage_v.obj().head; + if (unlikely (!coverage_table)) return Err(INVALID_ARGUMENT); + TRY(coverage_table->sanitize (coverage_v)); + return coverage_table; } - const ClassDef* get_class_def_1 (gsubgpos_graph_context_t& c, - unsigned this_index) const + graph_result_t get_class_def_1 (gsubgpos_graph_context_t& c, + unsigned this_index) const { - unsigned class_def_1_id = c.graph.index_for_offset (this_index, &classDef1); + TRY_ASSIGN (unsigned class_def_1_id, c.graph.index_for_offset (this_index, &classDef1)); auto& class_def_1_v = c.graph.vertices_[class_def_1_id]; - ClassDef* class_def_1_table = (ClassDef*) class_def_1_v.obj.head; - if (!class_def_1_table || !class_def_1_table->sanitize (class_def_1_v)) - return &Null(ClassDef); + const ClassDef* class_def_1_table = (const ClassDef*) class_def_1_v.obj().head; + if (unlikely (!class_def_1_table)) return Err(INVALID_ARGUMENT); + TRY(class_def_1_table->sanitize (class_def_1_v)); return class_def_1_table; } @@ -587,24 +590,24 @@ struct PairPosFormat2 : public OT::Layout::GPOS_impl::PairPosFormat2_4 size_of (gsubgpos_graph_context_t& c, + unsigned this_index, + const void* offset) const { - const unsigned id = c.graph.index_for_offset (this_index, offset); - return c.graph.vertices_[id].table_size (); + TRY_ASSIGN (const unsigned id, c.graph.index_for_offset (this_index, offset)); + return Ok(c.graph.vertices_[id].table_size ()); } }; struct PairPos : public OT::Layout::GPOS_impl::PairPos { - hb_vector_t split_subtables (gsubgpos_graph_context_t& c, - unsigned this_index) + graph_result_t> split_subtables (gsubgpos_graph_context_t& c, + unsigned this_index) { switch (u.format.v) { case 1: @@ -619,14 +622,14 @@ struct PairPos : public OT::Layout::GPOS_impl::PairPos // Don't split 24bit PairPos's. #endif default: - return hb_vector_t (); + return Ok(hb_vector_t ()); } } - bool sanitize (const graph_t::vertex_t& vertex) const + graph_result_t sanitize (const graph_t::vertex_t& vertex) const { - size_t vertex_len = vertex.obj.tail - vertex.obj.head; - if (vertex_len < u.format.v.get_size ()) return false; + size_t vertex_len = vertex.table_size(); + if (unlikely (vertex_len < u.format.v.get_size ())) return Err(SANITIZE_FAILURE); hb_barrier (); switch (u.format.v) { @@ -642,7 +645,7 @@ struct PairPos : public OT::Layout::GPOS_impl::PairPos #endif default: // We don't handle format 3 and 4 here. - return false; + return Err(SANITIZE_FAILURE); } } }; diff --git a/src/graph/serialize.hh b/src/graph/serialize.hh index 4ad4b0b06..d33b736ad 100644 --- a/src/graph/serialize.hh +++ b/src/graph/serialize.hh @@ -27,6 +27,8 @@ #ifndef GRAPH_SERIALIZE_HH #define GRAPH_SERIALIZE_HH +#include "graph-result.hh" + namespace graph { struct overflow_record_t @@ -104,38 +106,41 @@ bool is_valid_offset (int64_t offset, /* * Will any offsets overflow on graph when it's serialized? */ -inline bool +inline graph_result_t will_overflow (graph_t& graph, hb_vector_t* overflows = nullptr) { if (overflows) overflows->clear (); graph.update_positions (); - hb_hashmap_t record_set; + hb_hashmap_t record_set; const auto& vertices = graph.vertices_; for (unsigned parent_idx : graph.ordering_) { // Don't need to check virtual links for overflow - for (const auto& link : vertices.arrayZ[parent_idx].obj.real_links) + for (const auto& link : vertices.arrayZ[parent_idx].obj ().real_links) { int64_t offset = compute_offset (graph, parent_idx, link); if (likely (is_valid_offset (offset, link))) continue; - if (!overflows) return true; + if (!overflows) return Ok(true); overflow_record_t r; r.parent = parent_idx; r.child = link.objidx; - if (record_set.has(&r)) continue; // don't keep duplicate overflows. + if (record_set.has(r)) continue; // don't keep duplicate overflows. overflows->push (r); - record_set.set(&r, true); + record_set.set (r, true); } } - if (!overflows) return false; - return overflows->length; + TRY (graph_result_t::from (record_set, ALLOCATION_FAILURE)); + if (overflows) + TRY (graph_result_t::from (*overflows, ALLOCATION_FAILURE)); + + return Ok((bool) (overflows && overflows->length)); } inline @@ -144,7 +149,13 @@ void print_overflows (graph_t& graph, { if (!DEBUG_ENABLED(SUBSET_REPACK)) return; - graph.update_parents (); + auto r = graph.update_parents (); + if (r.is_err()) { + DEBUG_MSG (SUBSET_REPACK, nullptr, "Unable to print overflows due to error updating parent links: %s", + to_string(r.error())); + return; + } + int limit = 10; for (const auto& o : overflows) { @@ -157,11 +168,11 @@ void print_overflows (graph_t& graph, "%4u (%4u in, %4u out, space %2u)", o.parent, parent.incoming_edges (), - parent.obj.real_links.length + parent.obj.virtual_links.length, + parent.obj ().real_links.length + parent.obj ().virtual_links.length, graph.space_for (o.parent), o.child, child.incoming_edges (), - child.obj.real_links.length + child.obj.virtual_links.length, + child.obj ().real_links.length + child.obj ().virtual_links.length, graph.space_for (o.child)); } if (overflows.length > 10) { @@ -231,16 +242,16 @@ void serialize_link (const hb_serialize_context_t::object_t::link_t& link, /* * serialize graph into the provided serialization buffer. */ -inline hb_blob_t* serialize (const graph_t& graph) +inline graph_result_t serialize (const graph_t& graph) { hb_vector_t buffer; size_t size = graph.total_size_in_bytes (); - if (!size) return hb_blob_get_empty (); + if (!size) return Ok(hb_blob_get_empty ()); - if (!buffer.alloc (size)) { + if (unlikely (!buffer.alloc (size))) { DEBUG_MSG (SUBSET_REPACK, nullptr, "Unable to allocate output buffer."); - return nullptr; + return Err(ALLOCATION_FAILURE); } hb_serialize_context_t c((void *) buffer, size); @@ -252,25 +263,29 @@ inline hb_blob_t* serialize (const graph_t& graph) // Maps from our obj id's to the id's used during this serialization. hb_vector_t id_map; - id_map.resize(graph.ordering_.length); + if (unlikely (!id_map.resize(graph.ordering_.length))) { + DEBUG_MSG (SUBSET_REPACK, nullptr, "Unable to allocate id_map buffer."); + return Err(ALLOCATION_FAILURE); + } + for (int pos = graph.ordering_.length - 1; pos >= 0; pos--) { unsigned i = graph.ordering_[pos]; c.push (); auto& v = vertices[i]; - size_t size = v.obj.tail - v.obj.head; + size_t size = v.table_size (); char* start = c.allocate_size (size); - if (!start) { + if (unlikely (!start)) { DEBUG_MSG (SUBSET_REPACK, nullptr, "Buffer out of space."); - return nullptr; + return Err(ALLOCATION_FAILURE); } - hb_memcpy (start, v.obj.head, size); + hb_memcpy (start, v.obj ().head, size); // Only real links needs to be serialized. - for (const auto& link : v.obj.real_links) + for (const auto& link : v.obj ().real_links) serialize_link (link, start, size, id_map, &c); // All duplications are already encoded in the graph, so don't @@ -279,13 +294,17 @@ inline hb_blob_t* serialize (const graph_t& graph) } c.end_serialize (); - if (c.in_error ()) { + if (unlikely (c.in_error ())) { DEBUG_MSG (SUBSET_REPACK, nullptr, "Error during serialization. Err flag: %d", c.errors); - return nullptr; + if (c.errors & HB_SERIALIZE_ERROR_OFFSET_OVERFLOW) + return Err(OVERFLOW_RESOLUTION_FAILED); + return Err(ALLOCATION_FAILURE); } - return c.copy_blob (); + auto* blob = c.copy_blob (); + if (unlikely (!blob)) return Err(ALLOCATION_FAILURE); + return Ok(blob); } } // namespace graph diff --git a/src/graph/split-helpers.hh b/src/graph/split-helpers.hh index f1f86e332..b10e9d3a8 100644 --- a/src/graph/split-helpers.hh +++ b/src/graph/split-helpers.hh @@ -27,16 +27,18 @@ #ifndef GRAPH_SPLIT_HELPERS_HH #define GRAPH_SPLIT_HELPERS_HH +#include "graph-result.hh" + namespace graph { template HB_INTERNAL -hb_vector_t actuate_subtable_split (Context& split_context, - const hb_vector_t& split_points) +graph_result_t> actuate_subtable_split (Context& split_context, + const hb_vector_t& split_points) { hb_vector_t new_objects; if (!split_points) - return new_objects; + return Ok(new_objects); for (unsigned i = 0; i < split_points.length; i++) { @@ -44,24 +46,14 @@ hb_vector_t actuate_subtable_split (Context& split_context, unsigned end = (i < split_points.length - 1) ? split_points[i + 1] : split_context.original_count (); - unsigned id = split_context.clone_range (start, end); - - if (id == (unsigned) -1) - { - new_objects.reset (); - new_objects.ensure_error (); - return new_objects; - } + TRY_ASSIGN (unsigned id, split_context.clone_range (start, end)); new_objects.push (id); + TRY (graph_result_t::from (new_objects, ALLOCATION_FAILURE)); } - if (!split_context.shrink (split_points[0])) - { - new_objects.reset (); - new_objects.ensure_error (); - } + TRY (split_context.shrink (split_points[0])); - return new_objects; + return Ok(new_objects); } } diff --git a/src/graph/test-classdef-graph.cc b/src/graph/test-classdef-graph.cc index d3e8d892b..bc198d304 100644 --- a/src/graph/test-classdef-graph.cc +++ b/src/graph/test-classdef-graph.cc @@ -117,7 +117,7 @@ static HB_UNUSED bool check_add_class_def_size(graph::class_def_size_estimator_t static HB_UNUSED bool check_add_class_def_size (const gid_and_class_list_t& list, unsigned klass) { - graph::class_def_size_estimator_t estimator (list.iter ()); + graph::class_def_size_estimator_t estimator = *graph::class_def_size_estimator_t::create (list.iter ()); unsigned result = estimator.add_class_def_size (klass); auto filtered_it = @@ -228,7 +228,7 @@ static void test_running_class_and_coverage_size_estimates () { {12, 3}, }; - graph::class_def_size_estimator_t estimator1(consecutive_map.iter()); + graph::class_def_size_estimator_t estimator1 = *graph::class_def_size_estimator_t::create (consecutive_map.iter()); hb_always_assert(check_add_class_def_size(estimator1, consecutive_map, 1, {1})); hb_always_assert(check_add_class_def_size(estimator1, consecutive_map, 2, {1, 2})); hb_always_assert(check_add_class_def_size(estimator1, consecutive_map, 2, {1, 2})); // check that adding the same class again works @@ -260,7 +260,7 @@ static void test_running_class_and_coverage_size_estimates () { {15, 3}, }; - graph::class_def_size_estimator_t estimator2(non_consecutive_map.iter()); + graph::class_def_size_estimator_t estimator2 = *graph::class_def_size_estimator_t::create (non_consecutive_map.iter()); hb_always_assert(check_add_class_def_size(estimator2, non_consecutive_map, 1, {1})); hb_always_assert(check_add_class_def_size(estimator2, non_consecutive_map, 2, {1, 2})); hb_always_assert(check_add_class_def_size(estimator2, non_consecutive_map, 3, {1, 2, 3})); @@ -277,7 +277,7 @@ static void test_running_class_size_estimates_with_locally_consecutive_glyphs () {7, 3}, }; - graph::class_def_size_estimator_t estimator(map.iter()); + graph::class_def_size_estimator_t estimator = *graph::class_def_size_estimator_t::create (map.iter()); hb_always_assert(check_add_class_def_size(estimator, map, 1, {1})); hb_always_assert(check_add_class_def_size(estimator, map, 2, {1, 2})); hb_always_assert(check_add_class_def_size(estimator, map, 3, {1, 2, 3})); diff --git a/src/hb-bit-set.hh b/src/hb-bit-set.hh index edf8add28..6ff49083d 100644 --- a/src/hb-bit-set.hh +++ b/src/hb-bit-set.hh @@ -31,7 +31,6 @@ #include "hb.hh" #include "hb-bit-page.hh" - struct hb_bit_set_t { hb_bit_set_t () = default; @@ -827,13 +826,62 @@ struct hb_bit_set_t return false; } - /* TODO Speed up. */ *last = *first = i; - while (next (&i) && i == *last + 1) - (*last)++; - return true; + const auto* page_map_array = page_map.arrayZ; + const auto* pages_array = pages.arrayZ; + unsigned int major = get_major (*last); + unsigned int p_index = last_page_lookup; + + if (unlikely (p_index >= page_map.length || page_map_array[p_index].major != major)) + { + page_map.bfind (major, &p_index, HB_NOT_FOUND_STORE_CLOSEST); + // The above next() call gaurantees the page we're looking for exists. + assert(p_index < page_map.length && page_map_array[p_index].major == major); + last_page_lookup = p_index; + } + + unsigned int rem = page_remainder (*last); + unsigned int elt = rem / page_t::ELT_BITS; + unsigned int bit = rem & page_t::ELT_MASK; + + const page_t *page = &pages_array[page_map_array[p_index].index]; + unsigned int run = hb_ctz (~(page->v[elt] >> bit)); + *last += run - 1; + if (run < page_t::ELT_BITS - bit) + return true; + + elt++; + + while (true) + { + for (; elt < page_t::len (); elt++) + { + uint64_t w = page->v[elt]; + if (w == (uint64_t) -1) + { + *last += page_t::ELT_BITS; + continue; + } + uint64_t inv = ~w; + *last += hb_ctz (inv); + return true; + } + + p_index++; + + + if (p_index >= page_map.length || page_map_array[p_index].major != major + 1) + return true; + + const auto& entry = page_map_array[p_index]; + major = entry.major; + last_page_lookup = p_index; + page = &pages_array[entry.index]; + elt = 0; + } } + bool previous_range (hb_codepoint_t *first, hb_codepoint_t *last) const { hb_codepoint_t i; @@ -845,12 +893,62 @@ struct hb_bit_set_t return false; } - /* TODO Speed up. */ *last = *first = i; - while (previous (&i) && i == *first - 1) - (*first)--; - return true; + const auto* page_map_array = page_map.arrayZ; + const auto* pages_array = pages.arrayZ; + unsigned int major = get_major (*first); + unsigned int p_index = last_page_lookup; + + if (unlikely (p_index >= page_map.length || page_map_array[p_index].major != major)) + { + page_map.bfind (major, &p_index, HB_NOT_FOUND_STORE_CLOSEST); + // The above previous() call gaurantees the page we're looking for exists. + assert(p_index < page_map.length && page_map_array[p_index].major == major); + last_page_lookup = p_index; + } + + unsigned int rem = page_remainder (*first); + int elt = rem / page_t::ELT_BITS; + unsigned int bit = rem & page_t::ELT_MASK; + + const page_t *page = &pages_array[page_map_array[p_index].index]; + uint64_t inv = ~(page->v[elt] << (63 - bit)); + unsigned int run = hb_bit_storage (inv) ? (page_t::ELT_BITS - hb_bit_storage (inv)) : page_t::ELT_BITS; + *first -= run - 1; + if (run < bit + 1) + return true; + + elt--; + + while (true) + { + for (; elt >= 0; elt--) + { + uint64_t w = page->v[elt]; + if (w == (uint64_t) -1) + { + *first -= page_t::ELT_BITS; + continue; + } + uint64_t inv = ~w; + unsigned int zeros = hb_bit_storage (inv) ? (page_t::ELT_BITS - hb_bit_storage (inv)) : page_t::ELT_BITS; + *first -= zeros; + return true; + } + + + if (p_index == 0 || page_map_array[p_index - 1].major != major - 1) + return true; + + p_index--; + const auto& entry = page_map_array[p_index]; + + major = entry.major; + last_page_lookup = p_index; + page = &pages_array[entry.index]; + elt = page_t::len () - 1; + } } unsigned int next_many (hb_codepoint_t codepoint, diff --git a/src/hb-buffer.hh b/src/hb-buffer.hh index 770beeee3..1de700170 100644 --- a/src/hb-buffer.hh +++ b/src/hb-buffer.hh @@ -385,11 +385,6 @@ struct hb_buffer_t } /* Advance idx without copying to output. */ void skip_glyph () { idx++; } - void reset_masks (hb_mask_t mask) - { - for (unsigned int j = 0; j < len; j++) - info[j].mask = mask; - } void add_masks (hb_mask_t mask) { for (unsigned int j = 0; j < len; j++) diff --git a/src/hb-cairo-utils.hh b/src/hb-cairo-utils.hh index c9e380120..2db172047 100644 --- a/src/hb-cairo-utils.hh +++ b/src/hb-cairo-utils.hh @@ -31,12 +31,68 @@ #include "hb-cairo.h" -typedef struct +struct hb_cairo_budget_t { + /* Cairo serializes glyph-cache population for a scaled font. Keeping the + * owner there lets recursive color-glyph callbacks share one session. */ + int64_t budget = HB_BUDGET_DEFAULT; + int64_t budget_remaining = HB_BUDGET_GLYPH; + unsigned int active = 0; + + void enter () + { + if (!active++) + recharge (); + } + + void leave () + { + assert (active); + active--; + } + + void recharge () + { + budget_remaining = budget == HB_BUDGET_DEFAULT ? + HB_BUDGET_GLYPH : budget; + } +}; + +struct hb_cairo_context_t +{ + hb_cairo_context_t (cairo_scaled_font_t *scaled_font_, + cairo_t *cr_, + hb_map_t *color_cache_, + hb_cairo_budget_t *budget_) : + scaled_font (scaled_font_), cr (cr_), color_cache (color_cache_), + budget (budget_) + { + budget->enter (); + } + + ~hb_cairo_context_t () + { + budget->leave (); + } + + bool set_budget (int64_t value) + { + budget->budget = value; + budget->recharge (); + return true; + } + + int64_t get_budget () const { return budget->budget; } + int64_t *get_budget_remaining () { return &budget->budget_remaining; } + + bool spend (unsigned int cost, unsigned int mult = 1) + { return hb_budget_spend (budget->budget_remaining, cost, mult); } + cairo_scaled_font_t *scaled_font; cairo_t *cr; hb_map_t *color_cache; -} hb_cairo_context_t; + hb_cairo_budget_t *budget; +}; static inline cairo_operator_t _hb_paint_composite_mode_to_cairo (hb_paint_composite_mode_t mode) diff --git a/src/hb-cairo.cc b/src/hb-cairo.cc index 04440c19a..e1579fdf4 100644 --- a/src/hb-cairo.cc +++ b/src/hb-cairo.cc @@ -54,9 +54,11 @@ hb_cairo_move_to (hb_draw_funcs_t *dfuncs HB_UNUSED, float to_x, float to_y, void *user_data HB_UNUSED) { - cairo_t *cr = (cairo_t *) draw_data; + hb_cairo_context_t *c = (hb_cairo_context_t *) draw_data; + if (unlikely (!c->spend (HB_BUDGET_1))) + return; - cairo_move_to (cr, (double) to_x, (double) to_y); + cairo_move_to (c->cr, (double) to_x, (double) to_y); } static void @@ -66,9 +68,11 @@ hb_cairo_line_to (hb_draw_funcs_t *dfuncs HB_UNUSED, float to_x, float to_y, void *user_data HB_UNUSED) { - cairo_t *cr = (cairo_t *) draw_data; + hb_cairo_context_t *c = (hb_cairo_context_t *) draw_data; + if (unlikely (!c->spend (HB_BUDGET_1))) + return; - cairo_line_to (cr, (double) to_x, (double) to_y); + cairo_line_to (c->cr, (double) to_x, (double) to_y); } static void @@ -80,9 +84,11 @@ hb_cairo_cubic_to (hb_draw_funcs_t *dfuncs HB_UNUSED, float to_x, float to_y, void *user_data HB_UNUSED) { - cairo_t *cr = (cairo_t *) draw_data; + hb_cairo_context_t *c = (hb_cairo_context_t *) draw_data; + if (unlikely (!c->spend (HB_BUDGET_1))) + return; - cairo_curve_to (cr, + cairo_curve_to (c->cr, (double) control1_x, (double) control1_y, (double) control2_x, (double) control2_y, (double) to_x, (double) to_y); @@ -94,9 +100,36 @@ hb_cairo_close_path (hb_draw_funcs_t *dfuncs HB_UNUSED, hb_draw_state_t *st HB_UNUSED, void *user_data HB_UNUSED) { - cairo_t *cr = (cairo_t *) draw_data; + hb_cairo_context_t *c = (hb_cairo_context_t *) draw_data; + if (unlikely (!c->spend (HB_BUDGET_1))) + return; - cairo_close_path (cr); + cairo_close_path (c->cr); +} + +static hb_bool_t +hb_cairo_draw_set_budget (hb_draw_funcs_t *dfuncs HB_UNUSED, + void *draw_data, + int64_t budget, + void *user_data HB_UNUSED) +{ + return ((hb_cairo_context_t *) draw_data)->set_budget (budget); +} + +static int64_t +hb_cairo_draw_get_budget (hb_draw_funcs_t *dfuncs HB_UNUSED, + void *draw_data, + void *user_data HB_UNUSED) +{ + return ((hb_cairo_context_t *) draw_data)->get_budget (); +} + +static int64_t * +hb_cairo_draw_get_budget_remaining (hb_draw_funcs_t *dfuncs HB_UNUSED, + void *draw_data, + void *user_data HB_UNUSED) +{ + return ((hb_cairo_context_t *) draw_data)->get_budget_remaining (); } static inline void free_static_cairo_draw_funcs (); @@ -111,6 +144,9 @@ static struct hb_cairo_draw_funcs_lazy_loader_t : hb_draw_funcs_lazy_loader_tcr; + if (unlikely (!c->spend (HB_BUDGET_1))) + return true; + cairo_save (cr); hb_position_t x_scale, y_scale; @@ -228,7 +267,7 @@ hb_cairo_push_clip_glyph (hb_paint_funcs_t *pfuncs HB_UNUSED, cairo_save (cr); cairo_new_path (cr); - hb_font_draw_glyph (font, glyph, hb_cairo_draw_get_funcs (), cr); + hb_font_draw_glyph (font, glyph, hb_cairo_draw_get_funcs (), c); cairo_close_path (cr); cairo_clip (cr); @@ -261,7 +300,7 @@ hb_cairo_push_clip_path_start (hb_paint_funcs_t *pfuncs HB_UNUSED, cairo_save (cr); cairo_new_path (cr); - *draw_data = cr; + *draw_data = c; return hb_cairo_draw_get_funcs (); } @@ -449,6 +488,31 @@ hb_cairo_paint_custom_palette_color (hb_paint_funcs_t *funcs, return false; } +static hb_bool_t +hb_cairo_paint_set_budget (hb_paint_funcs_t *pfuncs HB_UNUSED, + void *paint_data, + int64_t budget, + void *user_data HB_UNUSED) +{ + return ((hb_cairo_context_t *) paint_data)->set_budget (budget); +} + +static int64_t +hb_cairo_paint_get_budget (hb_paint_funcs_t *pfuncs HB_UNUSED, + void *paint_data, + void *user_data HB_UNUSED) +{ + return ((hb_cairo_context_t *) paint_data)->get_budget (); +} + +static int64_t * +hb_cairo_paint_get_budget_remaining (hb_paint_funcs_t *pfuncs HB_UNUSED, + void *paint_data, + void *user_data HB_UNUSED) +{ + return ((hb_cairo_context_t *) paint_data)->get_budget_remaining (); +} + static inline void free_static_cairo_paint_funcs (); static struct hb_cairo_paint_funcs_lazy_loader_t : hb_paint_funcs_lazy_loader_t @@ -474,6 +538,9 @@ static struct hb_cairo_paint_funcs_lazy_loader_t : hb_paint_funcs_lazy_loader_t< hb_paint_funcs_set_radial_gradient_func (funcs, hb_cairo_paint_radial_gradient, nullptr, nullptr); hb_paint_funcs_set_sweep_gradient_func (funcs, hb_cairo_paint_sweep_gradient, nullptr, nullptr); hb_paint_funcs_set_custom_palette_color_func (funcs, hb_cairo_paint_custom_palette_color, nullptr, nullptr); + hb_paint_funcs_set_set_budget_func (funcs, hb_cairo_paint_set_budget, nullptr, nullptr); + hb_paint_funcs_set_get_budget_func (funcs, hb_cairo_paint_get_budget, nullptr, nullptr); + hb_paint_funcs_set_get_budget_remaining_func (funcs, hb_cairo_paint_get_budget_remaining, nullptr, nullptr); hb_paint_funcs_make_immutable (funcs); @@ -501,9 +568,17 @@ static const cairo_user_data_key_t hb_cairo_font_user_data_key = {0}; static const cairo_user_data_key_t hb_cairo_font_init_func_user_data_key = {0}; static const cairo_user_data_key_t hb_cairo_font_init_user_data_user_data_key = {0}; static const cairo_user_data_key_t hb_cairo_scale_factor_user_data_key = {0}; +static const cairo_user_data_key_t hb_cairo_budget_user_data_key = {0}; static void hb_cairo_face_destroy (void *p) { hb_face_destroy ((hb_face_t *) p); } static void hb_cairo_font_destroy (void *p) { hb_font_destroy ((hb_font_t *) p); } +static void +hb_cairo_budget_destroy (void *p) +{ + hb_cairo_budget_t *budget = (hb_cairo_budget_t *) p; + budget->~hb_cairo_budget_t (); + hb_free (budget); +} static cairo_status_t hb_cairo_init_scaled_font (cairo_scaled_font_t *scaled_font, @@ -571,6 +646,20 @@ hb_cairo_init_scaled_font (cairo_scaled_font_t *scaled_font, (void *) hb_font_reference (font), hb_cairo_font_destroy); + hb_cairo_budget_t *budget = (hb_cairo_budget_t *) hb_malloc (sizeof (hb_cairo_budget_t)); + if (unlikely (!budget)) + return CAIRO_STATUS_NO_MEMORY; + new (budget) hb_cairo_budget_t (); + cairo_status_t status = cairo_scaled_font_set_user_data (scaled_font, + &hb_cairo_budget_user_data_key, + budget, + hb_cairo_budget_destroy); + if (unlikely (status != CAIRO_STATUS_SUCCESS)) + { + hb_cairo_budget_destroy (budget); + return status; + } + hb_position_t x_scale, y_scale; hb_font_get_scale (font, &x_scale, &y_scale); @@ -636,6 +725,11 @@ hb_cairo_render_glyph (cairo_scaled_font_t *scaled_font, { hb_font_t *font = (hb_font_t *) cairo_scaled_font_get_user_data (scaled_font, &hb_cairo_font_user_data_key); + hb_cairo_budget_t *budget = (hb_cairo_budget_t *) cairo_scaled_font_get_user_data (scaled_font, + &hb_cairo_budget_user_data_key); + if (unlikely (!budget)) + return CAIRO_STATUS_NO_MEMORY; + hb_cairo_context_t c {scaled_font, cr, nullptr, budget}; hb_position_t x_scale, y_scale; hb_font_get_scale (font, &x_scale, &y_scale); @@ -643,7 +737,7 @@ hb_cairo_render_glyph (cairo_scaled_font_t *scaled_font, cairo_scale (cr, +1. / (x_scale ? x_scale : 1), -1. / (y_scale ? y_scale : 1)); - if (hb_font_draw_glyph_or_fail (font, glyph, hb_cairo_draw_get_funcs (), cr)) + if (hb_font_draw_glyph_or_fail (font, glyph, hb_cairo_draw_get_funcs (), &c)) cairo_fill (cr); // If draw fails, we still return SUCCESS, as we want empty drawing, not @@ -661,6 +755,10 @@ hb_cairo_render_color_glyph (cairo_scaled_font_t *scaled_font, { hb_font_t *font = (hb_font_t *) cairo_scaled_font_get_user_data (scaled_font, &hb_cairo_font_user_data_key); + hb_cairo_budget_t *budget = (hb_cairo_budget_t *) cairo_scaled_font_get_user_data (scaled_font, + &hb_cairo_budget_user_data_key); + if (unlikely (!budget)) + return CAIRO_STATUS_NO_MEMORY; unsigned int palette = 0; #ifdef CAIRO_COLOR_PALETTE_DEFAULT @@ -677,10 +775,10 @@ hb_cairo_render_color_glyph (cairo_scaled_font_t *scaled_font, +1. / (x_scale ? x_scale : 1), -1. / (y_scale ? y_scale : 1)); - hb_cairo_context_t c; - c.scaled_font = scaled_font; - c.cr = cr; - c.color_cache = (hb_map_t *) cairo_scaled_font_get_user_data (scaled_font, &color_cache_key); + hb_cairo_context_t c {scaled_font, + cr, + (hb_map_t *) cairo_scaled_font_get_user_data (scaled_font, &color_cache_key), + budget}; /* Synthesizing variant: mono glyphs render here too via the * fill_glyph foreground fallback inside hb_font_paint_glyph. diff --git a/src/hb-cff-interp-cs-common.hh b/src/hb-cff-interp-cs-common.hh index 66884d4a6..625519f07 100644 --- a/src/hb-cff-interp-cs-common.hh +++ b/src/hb-cff-interp-cs-common.hh @@ -121,6 +121,7 @@ struct cs_interp_env_t : interp_env_t hstem_count = 0; vstem_count = 0; hintmask_size = 0; + budget = nullptr; pt.set_int (0, 0); globalSubrs.init (globalSubrs_); localSubrs.init (localSubrs_); @@ -186,6 +187,11 @@ struct cs_interp_env_t : interp_env_t void set_endchar (bool endchar_flag_) { endchar_flag = endchar_flag_; } bool is_endchar () const { return endchar_flag; } + void set_budget (int64_t *budget_) { budget = budget_; } + int64_t *get_budget () const { return budget; } + bool spend_budget (unsigned int cost, unsigned int mult = 1) + { return !budget || hb_budget_spend (*budget, cost, mult); } + const number_t &get_x () const { return pt.x; } const number_t &get_y () const { return pt.y; } const point_t &get_pt () const { return pt; } @@ -201,6 +207,7 @@ struct cs_interp_env_t : interp_env_t unsigned int hstem_count; unsigned int vstem_count; unsigned int hintmask_size; + int64_t *budget; call_stack_t callStack; biased_subrs_t globalSubrs; biased_subrs_t localSubrs; @@ -880,22 +887,39 @@ struct cs_interpreter_t : interpreter_t bool interpret (PARAM& param, int64_t *budget = nullptr) { SUPER::env.set_endchar (false); + SUPER::env.set_budget (budget); + + /* Cap the operator count by the caller's remaining budget so the single + * max_ops counter enforces both the structural limit and the live work + * budget, with no budget check in the hot loop. The consumed operators + * are charged back after the loop, and since the cap never exceeds the + * remaining budget the charstring cannot overshoot it. CFF2 blend + * charges its proportional work separately, in place. */ + int64_t remaining = budget ? *budget : (int64_t) HB_CFF_MAX_OPS; + unsigned max_ops = (unsigned) hb_clamp (remaining, (int64_t) 0, (int64_t) HB_CFF_MAX_OPS); + unsigned start_ops = max_ops; bool ret = true; - unsigned max_ops = HB_CFF_MAX_OPS; - for (;;) { - OPSET::process_op (SUPER::env.fetch_op (), SUPER::env, param); - if (unlikely (SUPER::env.in_error () || !--max_ops)) - { - SUPER::env.set_error (); - ret = false; - break; + if (likely (max_ops)) + for (;;) { + OPSET::process_op (SUPER::env.fetch_op (), SUPER::env, param); + if (unlikely (SUPER::env.in_error () || !--max_ops)) + { + SUPER::env.set_error (); + ret = false; + break; + } + if (SUPER::env.is_endchar ()) + break; } - if (SUPER::env.is_endchar ()) - break; + else + { + SUPER::env.set_error (); + ret = false; } - if (budget) *budget -= (int64_t) (HB_CFF_MAX_OPS - max_ops); + if (budget) *budget -= (int64_t) (start_ops - max_ops); + return ret; } diff --git a/src/hb-cff2-interp-cs.hh b/src/hb-cff2-interp-cs.hh index 770a4ae36..af810c362 100644 --- a/src/hb-cff2-interp-cs.hh +++ b/src/hb-cff2-interp-cs.hh @@ -305,6 +305,11 @@ struct cff2_cs_opset_t : cs_opset_t, PAR env.set_error (); return; } + if (unlikely (!env.spend_budget (HB_BUDGET_1, total - n))) + { + env.set_error (); + return; + } unsigned int start = count - total; for (unsigned int i = 0; i < n; i++) { diff --git a/src/hb-common.cc b/src/hb-common.cc index fe357e130..26a2aba77 100644 --- a/src/hb-common.cc +++ b/src/hb-common.cc @@ -433,14 +433,8 @@ hb_script_from_iso15924_tag (hb_tag_t tag) /* Be lenient, adjust case (one capital letter followed by three small letters) */ tag = (tag & 0xDFDFDFDFu) | 0x00202020u; - switch (tag) { - - /* These graduated from the 'Q' private-area codes, but - * the old code is still aliased by Unicode, and the Qaai - * one in use by ICU. */ - case HB_TAG('Q','a','a','i'): return HB_SCRIPT_INHERITED; - case HB_TAG('Q','a','a','c'): return HB_SCRIPT_COPTIC; - + switch (tag) + { /* Script variants from https://unicode.org/iso15924/ */ case HB_TAG('A','r','a','n'): return HB_SCRIPT_ARABIC; case HB_TAG('C','y','r','s'): return HB_SCRIPT_CYRILLIC; diff --git a/src/hb-common.h b/src/hb-common.h index 49d4294d0..6105c558b 100644 --- a/src/hb-common.h +++ b/src/hb-common.h @@ -94,6 +94,25 @@ HB_BEGIN_DECLS **/ typedef int hb_bool_t; +/** + * HB_BUDGET_DEFAULT: + * + * Use the implementation's finite default work budget. + * + * XSince: REPLACEME + **/ +#define HB_BUDGET_DEFAULT ((int64_t) (-0x7FFFFFFFFFFFFFFF - 1)) + +/** + * HB_BUDGET_UNLIMITED: + * + * Use an effectively unlimited work budget. Structural safety limits remain + * active. + * + * XSince: REPLACEME + **/ +#define HB_BUDGET_UNLIMITED ((int64_t) 0x7FFFFFFFFFFFFFFF) + /** * hb_codepoint_t: * diff --git a/src/hb-draw.cc b/src/hb-draw.cc index 11f4e9a1f..fc0d8117e 100644 --- a/src/hb-draw.cc +++ b/src/hb-draw.cc @@ -96,6 +96,19 @@ hb_draw_close_path_nil (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data HB_UN hb_draw_state_t *st HB_UNUSED, void *user_data HB_UNUSED) {} +static hb_bool_t +hb_draw_set_budget_nil (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data HB_UNUSED, + int64_t budget HB_UNUSED, + void *user_data HB_UNUSED) { return false; } + +static int64_t +hb_draw_get_budget_nil (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data HB_UNUSED, + void *user_data HB_UNUSED) { return HB_BUDGET_DEFAULT; } + +static int64_t * +hb_draw_get_budget_remaining_nil (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data HB_UNUSED, + void *user_data HB_UNUSED) { return nullptr; } + static bool _hb_draw_funcs_set_preamble (hb_draw_funcs_t *dfuncs, @@ -355,6 +368,67 @@ hb_draw_funcs_is_immutable (hb_draw_funcs_t *dfuncs) return hb_object_is_immutable (dfuncs); } +/** + * hb_draw_set_budget: + * @dfuncs: draw functions object + * @draw_data: associated draw data + * @budget: the new work-budget policy + * + * Sets the work-budget policy and recharges the live work budget. Negative + * values other than #HB_BUDGET_DEFAULT are clamped to zero. + * + * Return value: `true` if the draw functions support work budgets + * + * XSince: REPLACEME + **/ +hb_bool_t +hb_draw_set_budget (hb_draw_funcs_t *dfuncs, void *draw_data, int64_t budget) +{ + return dfuncs->set_budget (draw_data, budget); +} + +/** + * hb_draw_get_budget: + * @dfuncs: draw functions object + * @draw_data: associated draw data + * + * Fetches the configured work-budget policy. + * + * Return value: the configured policy, or #HB_BUDGET_DEFAULT if unsupported + * + * XSince: REPLACEME + **/ +int64_t +hb_draw_get_budget (hb_draw_funcs_t *dfuncs, void *draw_data) +{ + return dfuncs->get_budget (draw_data); +} + +/** + * hb_draw_get_budget_remaining: + * @dfuncs: draw functions object + * @draw_data: associated draw data + * + * Fetches the live work budget. A negative value means the budget was + * exhausted. Zero means the preceding work fit exactly, but no positive-cost + * work can start. + * + * Return value: the live work budget; if it is not tracked, the concrete + * configured policy or #HB_BUDGET_UNLIMITED + * + * XSince: REPLACEME + **/ +int64_t +hb_draw_get_budget_remaining (hb_draw_funcs_t *dfuncs, void *draw_data) +{ + int64_t *remaining = dfuncs->get_budget_remaining_ptr (draw_data); + if (remaining) + return *remaining; + + int64_t budget = dfuncs->get_budget (draw_data); + return budget == HB_BUDGET_DEFAULT ? HB_BUDGET_UNLIMITED : budget; +} + /** * hb_draw_move_to: diff --git a/src/hb-draw.h b/src/hb-draw.h index fe5a5c861..c66130ad7 100644 --- a/src/hb-draw.h +++ b/src/hb-draw.h @@ -195,6 +195,61 @@ typedef void (*hb_draw_close_path_func_t) (hb_draw_funcs_t *dfuncs, void *draw_d hb_draw_state_t *st, void *user_data); +/** + * hb_draw_set_budget_func_t: + * @dfuncs: draw functions object + * @draw_data: The data accompanying the draw functions + * @budget: the new work-budget policy + * @user_data: User data pointer passed to hb_draw_funcs_set_set_budget_func() + * + * Sets the work-budget policy and recharges the live work budget. @budget is + * #HB_BUDGET_DEFAULT, #HB_BUDGET_UNLIMITED, or a non-negative concrete value. + * + * Return value: `true` if the budget was set, `false` if unsupported + * + * XSince: REPLACEME + **/ +typedef hb_bool_t (*hb_draw_set_budget_func_t) (hb_draw_funcs_t *dfuncs, + void *draw_data, + int64_t budget, + void *user_data); + +/** + * hb_draw_get_budget_func_t: + * @dfuncs: draw functions object + * @draw_data: The data accompanying the draw functions + * @user_data: User data pointer passed to hb_draw_funcs_set_get_budget_func() + * + * Fetches the configured work-budget policy. + * + * Return value: the configured work-budget policy + * + * XSince: REPLACEME + **/ +typedef int64_t (*hb_draw_get_budget_func_t) (hb_draw_funcs_t *dfuncs, + void *draw_data, + void *user_data); + +/** + * hb_draw_get_budget_remaining_func_t: + * @dfuncs: draw functions object + * @draw_data: The data accompanying the draw functions + * @user_data: User data pointer passed to + * hb_draw_funcs_set_get_budget_remaining_func() + * + * Fetches the address of the live work budget. The returned address must stay + * valid while @draw_data is used with @dfuncs. The live value must be concrete; + * it must not contain #HB_BUDGET_DEFAULT. + * + * Return value: (nullable) (transfer none): the live work budget, or `NULL` if + * live budget accounting is unsupported + * + * XSince: REPLACEME + **/ +typedef int64_t *(*hb_draw_get_budget_remaining_func_t) (hb_draw_funcs_t *dfuncs, + void *draw_data, + void *user_data); + /** * hb_draw_funcs_set_move_to_func: * @dfuncs: draw functions object @@ -275,6 +330,54 @@ hb_draw_funcs_set_close_path_func (hb_draw_funcs_t *dfuncs, hb_draw_close_path_func_t func, void *user_data, hb_destroy_func_t destroy); +/** + * hb_draw_funcs_set_set_budget_func: + * @dfuncs: draw functions object + * @func: (closure user_data) (destroy destroy) (scope notified): budget setter + * @user_data: Data to pass to @func + * @destroy: (nullable): callback to destroy @user_data + * + * Sets the budget setter callback. + * + * XSince: REPLACEME + **/ +HB_EXTERN void +hb_draw_funcs_set_set_budget_func (hb_draw_funcs_t *dfuncs, + hb_draw_set_budget_func_t func, + void *user_data, hb_destroy_func_t destroy); + +/** + * hb_draw_funcs_set_get_budget_func: + * @dfuncs: draw functions object + * @func: (closure user_data) (destroy destroy) (scope notified): budget getter + * @user_data: Data to pass to @func + * @destroy: (nullable): callback to destroy @user_data + * + * Sets the budget-policy getter callback. + * + * XSince: REPLACEME + **/ +HB_EXTERN void +hb_draw_funcs_set_get_budget_func (hb_draw_funcs_t *dfuncs, + hb_draw_get_budget_func_t func, + void *user_data, hb_destroy_func_t destroy); + +/** + * hb_draw_funcs_set_get_budget_remaining_func: + * @dfuncs: draw functions object + * @func: (closure user_data) (destroy destroy) (scope notified): live-budget getter + * @user_data: Data to pass to @func + * @destroy: (nullable): callback to destroy @user_data + * + * Sets the live-budget getter callback. + * + * XSince: REPLACEME + **/ +HB_EXTERN void +hb_draw_funcs_set_get_budget_remaining_func (hb_draw_funcs_t *dfuncs, + hb_draw_get_budget_remaining_func_t func, + void *user_data, hb_destroy_func_t destroy); + HB_EXTERN hb_draw_funcs_t * hb_draw_funcs_create (void); @@ -306,6 +409,16 @@ hb_draw_funcs_make_immutable (hb_draw_funcs_t *dfuncs); HB_EXTERN hb_bool_t hb_draw_funcs_is_immutable (hb_draw_funcs_t *dfuncs); +HB_EXTERN hb_bool_t +hb_draw_set_budget (hb_draw_funcs_t *dfuncs, void *draw_data, + int64_t budget); + +HB_EXTERN int64_t +hb_draw_get_budget (hb_draw_funcs_t *dfuncs, void *draw_data); + +HB_EXTERN int64_t +hb_draw_get_budget_remaining (hb_draw_funcs_t *dfuncs, void *draw_data); + HB_EXTERN void hb_draw_move_to (hb_draw_funcs_t *dfuncs, void *draw_data, diff --git a/src/hb-draw.hh b/src/hb-draw.hh index 201f2202e..dbefc87de 100644 --- a/src/hb-draw.hh +++ b/src/hb-draw.hh @@ -38,6 +38,9 @@ HB_DRAW_FUNC_IMPLEMENT (quadratic_to) \ HB_DRAW_FUNC_IMPLEMENT (cubic_to) \ HB_DRAW_FUNC_IMPLEMENT (close_path) \ + HB_DRAW_FUNC_IMPLEMENT (set_budget) \ + HB_DRAW_FUNC_IMPLEMENT (get_budget) \ + HB_DRAW_FUNC_IMPLEMENT (get_budget_remaining) \ /* ^--- Add new callbacks here */ struct hb_draw_funcs_t @@ -92,6 +95,20 @@ struct hb_draw_funcs_t { func.close_path (this, draw_data, &st, !user_data ? nullptr : user_data->close_path); } + bool set_budget (void *draw_data, int64_t budget) + { + if (budget < 0 && budget != HB_BUDGET_DEFAULT) + budget = 0; + return func.set_budget (this, draw_data, budget, + !user_data ? nullptr : user_data->set_budget); + } + int64_t get_budget (void *draw_data) + { return func.get_budget (this, draw_data, + !user_data ? nullptr : user_data->get_budget); } + int64_t *get_budget_remaining_ptr (void *draw_data) + { return func.get_budget_remaining (this, draw_data, + !user_data ? nullptr : user_data->get_budget_remaining); } + void HB_ALWAYS_INLINE @@ -176,8 +193,12 @@ DECLARE_NULL_INSTANCE (hb_draw_funcs_t); struct hb_draw_session_t { hb_draw_session_t (hb_draw_funcs_t *funcs_, void *draw_data_) - : funcs {funcs_}, draw_data {draw_data_}, st HB_DRAW_STATE_DEFAULT - {} + : funcs {funcs_}, draw_data {draw_data_}, st HB_DRAW_STATE_DEFAULT, + local_budget {HB_BUDGET_GLYPH}, budget {funcs->get_budget_remaining_ptr (draw_data)} + { + if (!budget) + budget = &local_budget; + } ~hb_draw_session_t () { close_path (); } @@ -219,10 +240,14 @@ struct hb_draw_session_t funcs->close_path (draw_data, st); } + int64_t &get_budget () { return *budget; } + public: hb_draw_funcs_t *funcs; void *draw_data; hb_draw_state_t st; + int64_t local_budget; + int64_t *budget; }; diff --git a/src/hb-font.cc b/src/hb-font.cc index ecb148361..0430f1253 100644 --- a/src/hb-font.cc +++ b/src/hb-font.cc @@ -731,6 +731,31 @@ hb_draw_close_path_default (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data, adaptor->draw_funcs->emit_close_path (adaptor->draw_data, *st); } +static hb_bool_t +hb_draw_set_budget_default (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data, + int64_t budget, + void *user_data HB_UNUSED) +{ + hb_font_draw_glyph_default_adaptor_t *adaptor = (hb_font_draw_glyph_default_adaptor_t *) draw_data; + return adaptor->draw_funcs->set_budget (adaptor->draw_data, budget); +} + +static int64_t +hb_draw_get_budget_default (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data, + void *user_data HB_UNUSED) +{ + hb_font_draw_glyph_default_adaptor_t *adaptor = (hb_font_draw_glyph_default_adaptor_t *) draw_data; + return adaptor->draw_funcs->get_budget (adaptor->draw_data); +} + +static int64_t * +hb_draw_get_budget_remaining_default (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data, + void *user_data HB_UNUSED) +{ + hb_font_draw_glyph_default_adaptor_t *adaptor = (hb_font_draw_glyph_default_adaptor_t *) draw_data; + return adaptor->draw_funcs->get_budget_remaining_ptr (adaptor->draw_data); +} + static const hb_draw_funcs_t _hb_draw_funcs_default = { HB_OBJECT_HEADER_STATIC, diff --git a/src/hb-font.hh b/src/hb-font.hh index e6a9b2ed9..30b2d27e2 100644 --- a/src/hb-font.hh +++ b/src/hb-font.hh @@ -710,6 +710,7 @@ struct hb_font_t #ifndef HB_NO_OUTLINE hb_outline_t outline; + outline.budget_remaining = draw_funcs->get_budget_remaining_ptr (draw_data); if (!klass->get.f.draw_glyph_or_fail (this, user_data, glyph, hb_outline_recording_pen_get_funcs (), &outline, diff --git a/src/hb-ft.cc b/src/hb-ft.cc index ce66f1145..dd371b45d 100644 --- a/src/hb-ft.cc +++ b/src/hb-ft.cc @@ -88,12 +88,15 @@ using hb_ft_advance_cache_t = hb_cache_t<16, 24, 8, false>; +static void _hb_ft_face_destroy_static (void *data); + struct hb_ft_font_t { int load_flags; bool symbol; /* Whether selected cmap is symbol cmap. */ bool unref; /* Whether to destroy ft_face when done. */ bool transform; /* Whether to apply FT_Face's transform. */ + bool static_library; /* Whether ft_face uses static_ft_library. */ mutable hb_mutex_t lock; /* Protects members below. */ FT_Face ft_face; @@ -102,7 +105,7 @@ struct hb_ft_font_t }; static hb_ft_font_t * -_hb_ft_font_create (FT_Face ft_face, bool symbol, bool unref) +_hb_ft_font_create (FT_Face ft_face, bool symbol, bool unref, bool static_library) { hb_ft_font_t *ft_font = (hb_ft_font_t *) hb_calloc (1, sizeof (hb_ft_font_t)); if (unlikely (!ft_font)) return nullptr; @@ -111,6 +114,7 @@ _hb_ft_font_create (FT_Face ft_face, bool symbol, bool unref) ft_font->ft_face = ft_face; ft_font->symbol = symbol; ft_font->unref = unref; + ft_font->static_library = static_library; ft_font->load_flags = FT_LOAD_DEFAULT | FT_LOAD_NO_HINTING; @@ -132,7 +136,12 @@ _hb_ft_font_destroy (void *data) hb_ft_font_t *ft_font = (hb_ft_font_t *) data; if (ft_font->unref) - _hb_ft_face_destroy (ft_font->ft_face); + { + if (ft_font->static_library) + _hb_ft_face_destroy_static (ft_font->ft_face); + else + _hb_ft_face_destroy (ft_font->ft_face); + } ft_font->lock.fini (); @@ -1097,11 +1106,12 @@ _hb_ft_get_font_funcs () } static void -_hb_ft_font_set_funcs (hb_font_t *font, FT_Face ft_face, bool unref) +_hb_ft_font_set_funcs (hb_font_t *font, FT_Face ft_face, bool unref, + bool static_library = false) { bool symbol = ft_face->charmap && ft_face->charmap->encoding == FT_ENCODING_MS_SYMBOL; - hb_ft_font_t *ft_font = _hb_ft_font_create (ft_face, symbol, unref); + hb_ft_font_t *ft_font = _hb_ft_font_create (ft_face, symbol, unref, static_library); if (unlikely (!ft_font)) return; hb_font_set_funcs (font, @@ -1501,6 +1511,31 @@ static FT_MemoryRec_ m = }; static inline void free_static_ft_library (); +static inline void free_static_ft_library_mutex (); + +static struct hb_ft_library_mutex_lazy_loader_t : hb_lazy_loader_t +{ + static hb_mutex_t *create () + { + hb_mutex_t *lock = (hb_mutex_t *) hb_calloc (1, sizeof (hb_mutex_t)); + if (unlikely (!lock)) + return nullptr; + + lock = new (lock) hb_mutex_t; + hb_atexit (free_static_ft_library_mutex); + return lock; + } + static void destroy (hb_mutex_t *lock) + { + lock->~hb_mutex_t (); + hb_free (lock); + } + static hb_mutex_t *get_null () + { + return nullptr; + } +} static_ft_library_mutex; static struct hb_ft_library_lazy_loader_t : hb_lazy_loader_t, hb_ft_library_lazy_loader_t> @@ -1528,15 +1563,26 @@ static struct hb_ft_library_lazy_loader_t : hb_lazy_loader_tgeneric.data = ft_library; ft_face->generic.finalizer = finalize_ft_library; @@ -1649,15 +1725,16 @@ hb_ft_face_create_from_blob_or_fail (hb_blob_t *blob, const char *blob_data = hb_blob_get_data (blob, &blob_size); FT_Face ft_face; - if (unlikely (FT_New_Memory_Face (ft_library, + if (unlikely (new_ft_memory_face (ft_library, (const FT_Byte *) blob_data, blob_size, index, &ft_face))) return nullptr; - hb_face_t *face = hb_ft_face_create_referenced (ft_face); - FT_Done_Face (ft_face); + FT_Reference_Face (ft_face); + hb_face_t *face = hb_ft_face_create (ft_face, _hb_ft_face_destroy_static); + _hb_ft_face_destroy_static (ft_face); ft_face->generic.data = ft_library; ft_face->generic.finalizer = finalize_ft_library; @@ -1740,7 +1817,7 @@ hb_ft_font_set_funcs (hb_font_t *font) } FT_Face ft_face = nullptr; - if (unlikely (FT_New_Memory_Face (ft_library, + if (unlikely (new_ft_memory_face (ft_library, (const FT_Byte *) blob_data, blob_length, hb_face_get_index (font->face), @@ -1762,11 +1839,11 @@ hb_ft_font_set_funcs (hb_font_t *font) if (unlikely (!hb_blob_set_user_data (blob, &ft_library_key, ft_library, destroy_ft_library, true))) { DEBUG_MSG (FT, font, "hb_blob_set_user_data() failed"); - FT_Done_Face (ft_face); + _hb_ft_face_destroy_static (ft_face); return; } - _hb_ft_font_set_funcs (font, ft_face, true); + _hb_ft_font_set_funcs (font, ft_face, true, true); hb_ft_font_set_load_flags (font, load_flags); _hb_ft_hb_font_changed (font, ft_face); diff --git a/src/hb-gpu-draw.cc b/src/hb-gpu-draw.cc index 41652640e..9a998f949 100644 --- a/src/hb-gpu-draw.cc +++ b/src/hb-gpu-draw.cc @@ -51,6 +51,10 @@ acc_emit (hb_gpu_draw_t *g, double p2x, double p2y, double p3x, double p3y) { + int64_t *budget = g->get_budget_remaining (); + if (unlikely (!hb_budget_spend (*budget, HB_BUDGET_1))) + return; + if (unlikely (g->num_curves >= HB_GPU_DRAW_MAX_CURVES)) { g->success = false; @@ -235,6 +239,28 @@ hb_gpu_draw_close_path (hb_draw_funcs_t *dfuncs HB_UNUSED, g->acc_close_path (); } +static hb_bool_t +hb_gpu_draw_set_budget (hb_draw_funcs_t *, void *draw_data, + int64_t budget, void *) +{ + auto *draw = (hb_gpu_draw_t *) draw_data; + draw->budget = budget; + draw->recharge_budget (); + return true; +} + +static int64_t +hb_gpu_draw_get_budget (hb_draw_funcs_t *, void *draw_data, void *) +{ + return ((hb_gpu_draw_t *) draw_data)->budget; +} + +static int64_t * +hb_gpu_draw_get_budget_remaining (hb_draw_funcs_t *, void *draw_data, void *) +{ + return ((hb_gpu_draw_t *) draw_data)->get_budget_remaining (); +} + static inline void free_static_gpu_draw_funcs (); static struct hb_gpu_draw_funcs_lazy_loader_t : hb_draw_funcs_lazy_loader_t @@ -248,6 +274,9 @@ static struct hb_gpu_draw_funcs_lazy_loader_t : hb_draw_funcs_lazy_loader_text_min_y = HUGE_VAL; draw->ext_max_x = -HUGE_VAL; draw->ext_max_y = -HUGE_VAL; + + draw->recharge_budget (); } /** @@ -1114,6 +1145,7 @@ hb_gpu_draw_reset (hb_gpu_draw_t *draw) { draw->x_scale = 0; draw->y_scale = 0; + draw->budget = HB_BUDGET_DEFAULT; hb_gpu_draw_clear (draw); } diff --git a/src/hb-gpu-draw.hh b/src/hb-gpu-draw.hh index df67647df..f2d717019 100644 --- a/src/hb-gpu-draw.hh +++ b/src/hb-gpu-draw.hh @@ -110,6 +110,22 @@ struct hb_gpu_draw_t int x_scale = 0; int y_scale = 0; + /* Work budget for outline traversal and generated curves. A paint + * backend seeds this through the public draw-budget API before drawing + * and reads the remainder back afterwards, so a whole paint session + * shares one budget without reaching into this object. */ + int64_t budget = HB_BUDGET_DEFAULT; + int64_t budget_remaining = HB_BUDGET_GLYPH; + + void recharge_budget () + { + budget_remaining = budget == HB_BUDGET_DEFAULT ? + HB_BUDGET_GLYPH : budget; + } + + int64_t *get_budget_remaining () + { return &budget_remaining; } + /* Encode scratch (reused across calls) */ hb_gpu_encode_scratch_t scratch; diff --git a/src/hb-gpu-paint.cc b/src/hb-gpu-paint.cc index 9885a8a2a..eeeec1e55 100644 --- a/src/hb-gpu-paint.cc +++ b/src/hb-gpu-paint.cc @@ -136,6 +136,10 @@ hb_gpu_paint_push_clip_path_start (hb_paint_funcs_t *funcs HB_UNUSED, } hb_gpu_draw_clear (c->scratch_draw); + /* Seed the scratch encoder's budget from the session's remainder; it is + * read back in push_clip_path_end after the caller has drawn the path. */ + hb_draw_set_budget (hb_gpu_draw_get_funcs (c->scratch_draw), c->scratch_draw, + c->budget_remaining); hb_gpu_draw_set_scale (c->scratch_draw, c->x_scale, c->y_scale); c->pending_clip_path_transform = c->cur_transform; @@ -156,7 +160,9 @@ hb_gpu_paint_push_clip_path_end (hb_paint_funcs_t *funcs HB_UNUSED, return; c->pending_clip_path = false; - c->work_left -= 1 + (int64_t) c->scratch_draw->num_curves; + /* Pull back the outline budget the caller's path draw consumed. */ + c->budget_remaining = hb_draw_get_budget_remaining (hb_gpu_draw_get_funcs (c->scratch_draw), + c->scratch_draw); hb_glyph_extents_t ext; hb_blob_t *blob = hb_gpu_draw_encode (c->scratch_draw, &ext); @@ -327,6 +333,7 @@ struct hb_gpu_paint_pen_t hb_draw_funcs_t *dfuncs; void *data; hb_draw_state_t down_st; + int64_t *budget_remaining; }; static void @@ -388,6 +395,12 @@ hb_gpu_paint_pen_close_path (hb_draw_funcs_t *dfuncs HB_UNUSED, c->dfuncs->close_path (c->data, c->down_st); } +static int64_t * +hb_gpu_paint_pen_get_budget_remaining (hb_draw_funcs_t *, void *draw_data, void *) +{ + return ((hb_gpu_paint_pen_t *) draw_data)->budget_remaining; +} + static inline void free_static_gpu_paint_pen_funcs (); static struct hb_gpu_paint_pen_funcs_lazy_loader_t @@ -401,6 +414,7 @@ static struct hb_gpu_paint_pen_funcs_lazy_loader_t hb_draw_funcs_set_quadratic_to_func (funcs, hb_gpu_paint_pen_quadratic_to, nullptr, nullptr); hb_draw_funcs_set_cubic_to_func (funcs, hb_gpu_paint_pen_cubic_to, nullptr, nullptr); hb_draw_funcs_set_close_path_func (funcs, hb_gpu_paint_pen_close_path, nullptr, nullptr); + hb_draw_funcs_set_get_budget_remaining_func (funcs, hb_gpu_paint_pen_get_budget_remaining, nullptr, nullptr); hb_draw_funcs_make_immutable (funcs); hb_atexit (free_static_gpu_paint_pen_funcs); return funcs; @@ -451,7 +465,7 @@ emit_clip_sub_blob (hb_gpu_paint_t *c, /* Out of budget: skip the glyph-outline extraction entirely, so * per-glyph outline limits cannot multiply with the caller's * paint-graph traversal limits. */ - if (unlikely (c->work_left <= 0)) + if (unlikely (c->budget_remaining < 0)) { c->unsupported = true; return -1; @@ -467,6 +481,11 @@ emit_clip_sub_blob (hb_gpu_paint_t *c, } } hb_gpu_draw_clear (c->scratch_draw); + /* Seed the scratch encoder's budget from the session's remainder and + * read it back after the glyph is drawn, so the whole paint walk shares + * one budget through the public draw-budget API. */ + hb_draw_set_budget (hb_gpu_draw_get_funcs (c->scratch_draw), c->scratch_draw, + c->budget_remaining); bool ok; if (clip.transform.is_identity ()) @@ -490,6 +509,7 @@ emit_clip_sub_blob (hb_gpu_paint_t *c, pen.dfuncs = hb_gpu_draw_get_funcs (c->scratch_draw); pen.data = c->scratch_draw; pen.down_st = HB_DRAW_STATE_DEFAULT; + pen.budget_remaining = &c->scratch_draw->budget_remaining; ok = hb_font_draw_glyph_or_fail (clip.font, clip.glyph, static_gpu_paint_pen_funcs.get_unconst (), &pen); @@ -497,7 +517,8 @@ emit_clip_sub_blob (hb_gpu_paint_t *c, * hb_font_draw_glyph_or_fail only closes via our pen's state. */ pen.dfuncs->close_path (pen.data, pen.down_st); } - c->work_left -= 1 + (int64_t) c->scratch_draw->num_curves; + c->budget_remaining = hb_draw_get_budget_remaining (hb_gpu_draw_get_funcs (c->scratch_draw), + c->scratch_draw); if (!ok) return -1; /* Clip glyph has no outline -- skip. */ @@ -1001,6 +1022,28 @@ hb_gpu_paint_image (hb_paint_funcs_t *funcs HB_UNUSED, return false; } +static hb_bool_t +hb_gpu_paint_set_budget (hb_paint_funcs_t *, void *paint_data, + int64_t budget, void *) +{ + auto *paint = (hb_gpu_paint_t *) paint_data; + paint->budget = budget; + paint->recharge_budget (); + return true; +} + +static int64_t +hb_gpu_paint_get_budget (hb_paint_funcs_t *, void *paint_data, void *) +{ + return ((hb_gpu_paint_t *) paint_data)->budget; +} + +static int64_t * +hb_gpu_paint_get_budget_remaining (hb_paint_funcs_t *, void *paint_data, void *) +{ + return &((hb_gpu_paint_t *) paint_data)->budget_remaining; +} + static inline void free_static_gpu_paint_funcs (); static struct hb_gpu_paint_funcs_lazy_loader_t @@ -1025,6 +1068,9 @@ static struct hb_gpu_paint_funcs_lazy_loader_t hb_paint_funcs_set_custom_palette_color_func (funcs, hb_gpu_paint_custom_palette_color, nullptr, nullptr); /* PaintImage can't be represented by our slug+gradient encoder. */ hb_paint_funcs_set_image_func (funcs, hb_gpu_paint_image, nullptr, nullptr); + hb_paint_funcs_set_set_budget_func (funcs, hb_gpu_paint_set_budget, nullptr, nullptr); + hb_paint_funcs_set_get_budget_func (funcs, hb_gpu_paint_get_budget, nullptr, nullptr); + hb_paint_funcs_set_get_budget_remaining_func (funcs, hb_gpu_paint_get_budget_remaining, nullptr, nullptr); hb_paint_funcs_make_immutable (funcs); @@ -1563,7 +1609,7 @@ hb_gpu_paint_clear (hb_gpu_paint_t *paint) paint->clip_depth = 0; paint->pending_clip_path = false; paint->unsupported = false; - paint->work_left = HB_GPU_PAINT_MAX_WORK; + paint->recharge_budget (); paint->cur_transform = {1, 0, 0, 1, 0, 0}; paint->transform_stack.reset (); paint->ext_min_x = 0x7fffffff; @@ -1587,6 +1633,7 @@ hb_gpu_paint_reset (hb_gpu_paint_t *paint) paint->x_scale = 0; paint->y_scale = 0; paint->palette = 0; + paint->budget = HB_BUDGET_DEFAULT; hb_map_destroy (paint->custom_palette); paint->custom_palette = nullptr; hb_gpu_paint_clear (paint); diff --git a/src/hb-gpu-paint.hh b/src/hb-gpu-paint.hh index 6d722ad09..27148817a 100644 --- a/src/hb-gpu-paint.hh +++ b/src/hb-gpu-paint.hh @@ -273,12 +273,20 @@ struct hb_gpu_paint_t * which matches HB_GPU_PAINT_GROUP_DEPTH in the fragment shader. */ unsigned group_depth = 0; - /* Cumulative work budget for the current paint walk; reset by - * hb_gpu_paint_clear(). Charged with the curves consumed by each - * clip-glyph encode, so per-glyph outline limits cannot multiply - * with the paint-graph traversal limits of the font tables - * driving us (e.g. COLR). */ - int64_t work_left = HB_GPU_PAINT_MAX_WORK; + /* Work budget for the current paint session; reset by + * hb_gpu_paint_clear(). All the session's work is outline-derived + * (outline traversal and the curves generated from it -- the GPU + * backend never rasterizes), so a single counter suffices. It is the + * public draw/paint budget: seeded into the scratch encoder through the + * public draw-budget API before each glyph and read back afterwards. */ + int64_t budget = HB_BUDGET_DEFAULT; + int64_t budget_remaining = HB_BUDGET_GLYPH; + + void recharge_budget () + { + budget_remaining = budget == HB_BUDGET_DEFAULT ? + HB_BUDGET_GLYPH : budget; + } /* Stack of pending clips. Each color/gradient op consumes the * current state of this stack: the layer is rendered where ALL diff --git a/src/hb-limits.hh b/src/hb-limits.hh index dcc624e88..ea6163494 100644 --- a/src/hb-limits.hh +++ b/src/hb-limits.hh @@ -133,6 +133,16 @@ #define HB_SVG_MAX_DOCUMENT_SIZE ((size_t) 16 << 20) #endif +/* Maximum size of one serialized vector document (SVG or PDF) produced by + * the vector backends. Bounds output that is not outline-derived -- most + * of a path, but especially sweep-gradient meshes and embedded bitmaps -- + * which the outline work budget cannot see. vector is one glyph per + * context, so a flat cap suffices. Unsigned (not size_t like the SVG-table + * limit above) to match hb_vector_buf_t's unsigned length arithmetic. */ +#ifndef HB_VECTOR_MAX_DOCUMENT_SIZE +#define HB_VECTOR_MAX_DOCUMENT_SIZE ((unsigned) 16 << 20) +#endif + #ifndef HB_RASTER_MAX_BUFFER_SIZE #define HB_RASTER_MAX_BUFFER_SIZE ((size_t) 1 << 30) #endif @@ -159,55 +169,42 @@ * is skipped best-effort. */ -/* One VARC glyph (draw or extents), shared by all leaf glyphs loaded - * from glyf/CFF/CFF2, in units of glyf points / CFF charstring ops. */ -#ifndef HB_VARC_MAX_WORK -#define HB_VARC_MAX_WORK ((int64_t) 1 << 20) +/* Fixed relative weights. Keep the value in the name so charge sites are + * easy to audit; tune the common session cap, not these values. */ +#define HB_BUDGET_1 1u +#define HB_BUDGET_2 2u +#define HB_BUDGET_4 4u +#define HB_BUDGET_8 8u +#define HB_BUDGET_16 16u +#define HB_BUDGET_32 32u +#define HB_BUDGET_64 64u +#define HB_BUDGET_128 128u +#define HB_BUDGET_256 256u +#define HB_BUDGET_512 512u +#define HB_BUDGET_1024 1024u + +/* The common finite default for one top-level glyph rendering session. + * Nested outline and paint work shares the same live counter. */ +#ifndef HB_BUDGET_GLYPH +#define HB_BUDGET_GLYPH ((int64_t) 1 << 26) #endif -/* One paint-extents session, in outline points consumed by - * clip-glyph draws. */ -#ifndef HB_PAINT_EXTENTS_MAX_WORK -#define HB_PAINT_EXTENTS_MAX_WORK ((int64_t) 1 << 20) -#endif - -/* One GPU paint walk, in curves consumed by clip encodes. */ -#ifndef HB_GPU_PAINT_MAX_WORK -#define HB_GPU_PAINT_MAX_WORK ((int64_t) 1 << 20) -#endif - -/* One vector (SVG/PDF) draw session, in bytes of generated outline - * path data. */ -#ifndef HB_VECTOR_MAX_DRAW_WORK -#define HB_VECTOR_MAX_DRAW_WORK ((int64_t) 16 << 20) -#endif - -/* One vector (SVG/PDF) paint session, in bytes of generated outline - * path and sweep-gradient patch data. */ -#ifndef HB_VECTOR_MAX_PAINT_WORK -#define HB_VECTOR_MAX_PAINT_WORK ((int64_t) 16 << 20) -#endif +/* Precharge COST * MULT. Callers bound COST and MULT structurally, and live + * budgets are concrete non-negative values when a session starts. */ +static HB_ALWAYS_INLINE bool +hb_budget_spend (int64_t &budget, unsigned int cost, unsigned int mult = 1) +{ + budget -= (int64_t) cost * mult; + return budget >= 0; +} /* One raster paint session (everything painted between two * render/clear calls), in pixel-op units; pixel loops charge their - * area, consumed outline segments are charged with a fixed weight. - * The session budget is the larger of this flat value and - * HB_RASTER_MAX_PAINT_WORK_PASSES full-surface passes, so very large - * surfaces still get a few full-surface operations. */ -#ifndef HB_RASTER_MAX_PAINT_WORK -#define HB_RASTER_MAX_PAINT_WORK ((int64_t) 1 << 26) -#endif - -#ifndef HB_RASTER_MAX_PAINT_WORK_PASSES -#define HB_RASTER_MAX_PAINT_WORK_PASSES 4 -#endif - -/* One raster draw session (everything drawn between two render/clear - * calls) through the standalone hb-raster-draw API, in Bézier - * subdivision steps. When driven by raster-paint, the paint session - * budget above is charged instead. */ -#ifndef HB_RASTER_MAX_DRAW_WORK -#define HB_RASTER_MAX_DRAW_WORK ((int64_t) 1 << 24) + * area, consumed outline segments are charged with a fixed weight. Its + * default is the larger of HB_BUDGET_GLYPH and this many full-surface + * passes, so very large surfaces still get a few full-surface operations. */ +#ifndef HB_BUDGET_RASTER_PAINT_PASSES +#define HB_BUDGET_RASTER_PAINT_PASSES 4 #endif /* One raster draw session, in accumulated non-horizontal edges. */ diff --git a/src/hb-ot-cff1-table.cc b/src/hb-ot-cff1-table.cc index 25f71cb34..61d223600 100644 --- a/src/hb-ot-cff1-table.cc +++ b/src/hb-ot-cff1-table.cc @@ -379,8 +379,8 @@ struct cff1_cs_opset_extents_t : cff1_cs_opset_tstd_code_to_glyph (env.argStack[n-1].to_int ()); if (unlikely (!(!env.in_seac && base && accent - && _get_path (param.cff, param.font, base, *param.draw_session, true) - && _get_path (param.cff, param.font, accent, *param.draw_session, true, &delta)))) + && _get_path (param.cff, param.font, base, *param.draw_session, true, nullptr, env.get_budget ()) + && _get_path (param.cff, param.font, accent, *param.draw_session, true, &delta, env.get_budget ())))) env.set_error (); } }; @@ -568,6 +571,9 @@ bool OT::cff1::accelerator_t::get_path (hb_font_t *font, hb_codepoint_t glyph, h return true; #endif + int64_t stack_budget = HB_BUDGET_GLYPH; + if (!budget) budget = &stack_budget; + return _get_path (this, font, glyph, draw_session, false, nullptr, budget); } diff --git a/src/hb-ot-cff2-table.cc b/src/hb-ot-cff2-table.cc index e3c4af9fc..c1d08007e 100644 --- a/src/hb-ot-cff2-table.cc +++ b/src/hb-ot-cff2-table.cc @@ -123,6 +123,9 @@ bool OT::cff2::accelerator_t::get_extents_at (hb_font_t *font, if (unlikely (!is_valid () || (glyph >= num_glyphs))) return false; + int64_t stack_budget = HB_BUDGET_GLYPH; + if (!budget) budget = &stack_budget; + unsigned int fd = fdSelect->get_fd (glyph); const hb_ubytes_t str = (*charStrings)[glyph]; cff2_cs_interp_env_t env (str, *this, fd, coords.arrayZ, coords.length); @@ -207,13 +210,19 @@ struct cff2_path_procs_path_t : path_procs_t {}; -bool OT::cff2::accelerator_t::get_path (hb_font_t *font, hb_codepoint_t glyph, hb_draw_session_t &draw_session) const +bool OT::cff2::accelerator_t::get_path (hb_font_t *font, hb_codepoint_t glyph, + hb_draw_session_t &draw_session, + int64_t *budget) const { + int64_t stack_budget = HB_BUDGET_GLYPH; + if (!budget) budget = &stack_budget; + return get_path_at (font, glyph, draw_session, hb_array (font->coords, - font->has_nonzero_coords ? font->num_coords : 0)); + font->has_nonzero_coords ? font->num_coords : 0), + budget); } bool OT::cff2::accelerator_t::get_path_at (hb_font_t *font, hb_codepoint_t glyph, hb_draw_session_t &draw_session, hb_array_t coords, int64_t *budget) const @@ -225,6 +234,9 @@ bool OT::cff2::accelerator_t::get_path_at (hb_font_t *font, hb_codepoint_t glyph if (unlikely (!is_valid () || (glyph >= num_glyphs))) return false; + int64_t stack_budget = HB_BUDGET_GLYPH; + if (!budget) budget = &stack_budget; + unsigned int fd = fdSelect->get_fd (glyph); const hb_ubytes_t str = (*charStrings)[glyph]; cff2_cs_interp_env_t env (str, *this, fd, coords.arrayZ, coords.length); diff --git a/src/hb-ot-cff2-table.hh b/src/hb-ot-cff2-table.hh index ddbf66b4f..375e5271d 100644 --- a/src/hb-ot-cff2-table.hh +++ b/src/hb-ot-cff2-table.hh @@ -539,7 +539,7 @@ struct cff2 hb_glyph_extents_t *extents, hb_array_t coords, int64_t *budget = nullptr) const; - HB_INTERNAL bool get_path (hb_font_t *font, hb_codepoint_t glyph, hb_draw_session_t &draw_session) const; + HB_INTERNAL bool get_path (hb_font_t *font, hb_codepoint_t glyph, hb_draw_session_t &draw_session, int64_t *budget = nullptr) const; HB_INTERNAL bool get_path_at (hb_font_t *font, hb_codepoint_t glyph, hb_draw_session_t &draw_session, hb_array_t coords, int64_t *budget = nullptr) const; }; diff --git a/src/hb-ot-font.cc b/src/hb-ot-font.cc index d91ee7af2..def97c5a4 100644 --- a/src/hb-ot-font.cc +++ b/src/hb-ot-font.cc @@ -782,7 +782,8 @@ hb_ot_get_glyph_v_origins (hb_font_t *font, { hb_glyph_extents_t extents = {0}; if (likely (font->get_glyph_extents (*first_glyph, &extents))) - origin = extents.y_bearing + ((font_advance - -extents.height) >> 1); + origin = hb_clamp_to ((int64_t) extents.y_bearing + + (((int64_t) font_advance + extents.height) >> 1)); else origin = font_extents.ascender; @@ -914,11 +915,14 @@ hb_ot_draw_glyph_or_fail (hb_font_t *font, if (font->face->table.VARC->get_path (font, glyph, draw_session)) return true; #endif // Keep the following in synch with VARC::get_path_at() - if (font->face->table.glyf->get_path (font, glyph, draw_session, gvar_cache)) return true; + if (font->face->table.glyf->get_path (font, glyph, draw_session, gvar_cache, + &draw_session.get_budget ())) return true; #ifndef HB_NO_CFF - if (font->face->table.cff2->get_path (font, glyph, draw_session)) return true; - if (font->face->table.cff1->get_path (font, glyph, draw_session)) return true; + if (font->face->table.cff2->get_path (font, glyph, draw_session, + &draw_session.get_budget ())) return true; + if (font->face->table.cff1->get_path (font, glyph, draw_session, + &draw_session.get_budget ())) return true; #endif return false; diff --git a/src/hb-ot-layout-base-table.hh b/src/hb-ot-layout-base-table.hh index 370656446..b26ce0ffa 100644 --- a/src/hb-ot-layout-base-table.hh +++ b/src/hb-ot-layout-base-table.hh @@ -790,10 +790,10 @@ struct BASE if (unlikely (!out || !c->serializer->extend_min (out))) return_trace (false); out->version = version; - if (has_var_store () && !subset_varstore (c, out)) - return_trace (false); + bool ret = false; + if (version.to_int () >= 0x00010001u) ret |= subset_varstore (c, out); - bool ret = out->hAxis.serialize_subset (c, hAxis, this); + ret |= out->hAxis.serialize_subset (c, hAxis, this); ret |= out->vAxis.serialize_subset (c, vAxis, this); return_trace (ret); diff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh index 254901c2d..73af70f06 100644 --- a/src/hb-ot-layout-gsubgpos.hh +++ b/src/hb-ot-layout-gsubgpos.hh @@ -1129,7 +1129,6 @@ struct hb_ot_apply_context_t : recurse_func_t recurse_func = nullptr; const GDEF &gdef; const GDEF::accelerator_t &gdef_accel; - const hb_ot_layout_lookup_accelerator_t *lookup_accel = nullptr; const ItemVariationStore &var_store; hb_scalar_cache_t *var_store_cache; @@ -1378,6 +1377,16 @@ enum class hb_ot_subtable_cache_op_t struct hb_accelerate_subtables_context_t : hb_dispatch_context_t { + template + static inline auto collect_second_glyphs_ (const T &obj, + hb_set_digest_t *digest, + hb_priority<1>) HB_RETURN (void, obj.collect_second_glyphs (digest) ) + template + static inline void collect_second_glyphs_ (const T &obj HB_UNUSED, + hb_set_digest_t *digest, + hb_priority<0>) + { *digest = hb_set_digest_t::full (); } + template static inline auto apply_ (const T *obj, hb_ot_apply_context_t *c, void *external_cache, hb_priority<1>) HB_RETURN (bool, obj->apply (c, external_cache) ) template @@ -1512,6 +1521,8 @@ struct hb_accelerate_subtables_context_t : template return_t dispatch (const T &obj) { + collect_second_glyphs_ (obj, &digest_second, hb_prioritize); + #ifndef HB_NO_OT_LAYOUT_LOOKUP_CACHE void *external_cache = nullptr; if (i < 8) @@ -1555,6 +1566,7 @@ struct hb_accelerate_subtables_context_t : hb_applicable_t *array; unsigned i = 0; + hb_set_digest_t digest_second; #ifndef HB_NO_OT_LAYOUT_LOOKUP_CACHE unsigned subtable_cache_user_idx = (unsigned) -1; @@ -1567,6 +1579,19 @@ typedef bool (*intersects_func_t) (const hb_set_t *glyphs, unsigned value, const typedef void (*intersected_glyphs_func_t) (const hb_set_t *glyphs, const void *data, unsigned value, hb_set_t *intersected_glyphs, void *cache); typedef void (*collect_glyphs_func_t) (hb_set_t *glyphs, unsigned value, const void *data); typedef bool (*match_func_t) (hb_glyph_info_t &info, unsigned value, const void *data); +typedef unsigned (*get_value_func_t) (hb_glyph_info_t &info, const void *data); + +/* One word per RuleSet, summarizing the classes accepted at the first + * input position after the current glyph. Collisions only cause extra work. */ +struct hb_ot_layout_ruleset_digest_t +{ + void init () { mask = 0; } + void set_full () { mask = (uint64_t) -1; } + void add (unsigned value) { mask |= (uint64_t) 1 << (value & 63); } + bool may_have (unsigned value) const { return mask & ((uint64_t) 1 << (value & 63)); } + + uint64_t mask; +}; struct ContextClosureFuncs { @@ -1770,6 +1795,26 @@ static inline bool match_class (hb_glyph_info_t &info, unsigned value, const voi const ClassDef &class_def = *reinterpret_cast(data); return class_def.get_class (info.codepoint) == value; } +static inline unsigned get_class_value (hb_glyph_info_t &info, const void *data) +{ + const ClassDef &class_def = *reinterpret_cast (data); + return class_def.get_class (info.codepoint); +} +struct match_class_cache_data_t +{ + const ClassDef *class_def; + hb_ot_layout_mapping_cache_t *cache; +}; +static inline bool match_class_cache (hb_glyph_info_t &info, unsigned value, const void *data) +{ + const auto &cache_data = *reinterpret_cast (data); + return cache_data.class_def->get_class (info.codepoint, cache_data.cache) == value; +} +static inline unsigned get_class_cache_value (hb_glyph_info_t &info, const void *data) +{ + const auto &cache_data = *reinterpret_cast (data); + return cache_data.class_def->get_class (info.codepoint, cache_data.cache); +} static inline unsigned get_class_cached (const ClassDef &class_def, hb_glyph_info_t &info) { unsigned klass = info.syllable(); @@ -1785,6 +1830,11 @@ static inline bool match_class_cached (hb_glyph_info_t &info, unsigned value, co const ClassDef &class_def = *reinterpret_cast(data); return get_class_cached (class_def, info) == value; } +static inline unsigned get_class_cached_value (hb_glyph_info_t &info, const void *data) +{ + const ClassDef &class_def = *reinterpret_cast (data); + return get_class_cached (class_def, info); +} static inline unsigned get_class_cached1 (const ClassDef &class_def, hb_glyph_info_t &info) { unsigned klass = info.syllable() & 0x0F; @@ -1815,6 +1865,11 @@ static inline bool match_class_cached2 (hb_glyph_info_t &info, unsigned value, c const ClassDef &class_def = *reinterpret_cast(data); return get_class_cached2 (class_def, info) == value; } +static inline unsigned get_class_cached2_value (hb_glyph_info_t &info, const void *data) +{ + const ClassDef &class_def = *reinterpret_cast (data); + return get_class_cached2 (class_def, info); +} static inline bool match_coverage (hb_glyph_info_t &info, unsigned value, const void *data) { Offset16To coverage; @@ -2804,6 +2859,7 @@ struct ContextApplyLookupContext { ContextApplyFuncs funcs; const void *match_data; + get_value_func_t get_value; }; template @@ -2892,7 +2948,7 @@ static inline void context_depend_lookup (hb_depend_context_t *c, } /* Positions 1+ (Input array) */ - for (unsigned i = 0; i < inputCount - 1; i++) + for (unsigned i = 0; i + 1 < inputCount; i++) { const hb_set_t *pos_glyphs = depend_position_glyphs ( c, lookup_context.context_format, lookup_context.intersects_data, @@ -3065,6 +3121,24 @@ struct Rule lookup_context); } + void collect_second_glyphs (hb_set_digest_t *digest, + const ClassDef *class_def = nullptr) const + { + if (inputCount <= 1) + { + *digest = hb_set_digest_t::full (); + return; + } + + unsigned second = inputZ.arrayZ[0]; + if (!class_def) + digest->add (second); + else if (!second) + *digest = hb_set_digest_t::full (); + else + class_def->collect_class (digest, second); + } + bool would_apply (hb_would_apply_context_t *c, const ContextApplyLookupContext &lookup_context) const { @@ -3164,6 +3238,21 @@ struct RuleSet ; } + void collect_first_input_classes (hb_ot_layout_ruleset_digest_t *digest) const + { + digest->init (); + for (unsigned i = 0; i < rule.len; i++) + { + const Rule &r = this+rule.arrayZ[i]; + if (r.inputCount <= 1) + { + digest->set_full (); + return; + } + digest->add (r.inputZ.arrayZ[0]); + } + } + void depend (hb_depend_context_t *c, unsigned value, ContextDependLookupContext &lookup_context) const { + hb_iter (rule) @@ -3204,6 +3293,15 @@ struct RuleSet ; } + void collect_second_glyphs (hb_set_digest_t *digest, + const ClassDef *class_def = nullptr) const + { + + hb_iter (rule) + | hb_map (hb_add (this)) + | hb_apply ([=] (const Rule &_) { _.collect_second_glyphs (digest, class_def); }) + ; + } + bool would_apply (hb_would_apply_context_t *c, const ContextApplyLookupContext &lookup_context) const { @@ -3216,7 +3314,8 @@ struct RuleSet } bool apply (hb_ot_apply_context_t *c, - const ContextApplyLookupContext &lookup_context) const + const ContextApplyLookupContext &lookup_context, + const hb_ot_layout_ruleset_digest_t *digest = nullptr) const { TRACE_APPLY (this); @@ -3252,7 +3351,7 @@ struct RuleSet skippy_iter.set_glyph_data ((HBUINT16 *) nullptr); unsigned unsafe_to = (unsigned) -1, unsafe_to1, unsafe_to2 = 0; hb_glyph_info_t *first = nullptr, *second = nullptr; - bool matched = skippy_iter.next (); + bool matched = skippy_iter.next (&unsafe_to1); if (likely (matched)) { if (skippy_iter.may_skip (c->buffer->info[skippy_iter.idx])) @@ -3264,19 +3363,32 @@ struct RuleSet first = &c->buffer->info[skippy_iter.idx]; unsafe_to1 = skippy_iter.idx + 1; + + if (digest && lookup_context.get_value && + !digest->may_have (lookup_context.get_value (*first, lookup_context.match_data))) + { + c->buffer->unsafe_to_concat (c->buffer->idx, unsafe_to1); + return_trace (false); + } } else { - /* Failed to match a next glyph. Only try applying rules that have - * no further input. */ - return_trace ( + bool unsafe_to_concat = false; + bool ret = + hb_iter (rule) | hb_map (hb_add (this)) - | hb_filter ([&] (const Rule &_) { return _.inputCount <= 1; }) + | hb_filter ([&] (const Rule &_) + { + if (_.inputCount <= 1) return true; + unsafe_to_concat = true; + return false; + }) | hb_map ([&] (const Rule &_) { return _.apply (c, lookup_context); }) | hb_any - ) ; + if (unsafe_to_concat) + c->buffer->unsafe_to_concat (c->buffer->idx, unsafe_to1); + return_trace (ret); } matched = skippy_iter.next (); if (likely (matched)) @@ -3493,6 +3605,14 @@ struct ContextFormat1_4 ; } + void collect_second_glyphs (hb_set_digest_t *digest) const + { + + hb_iter (ruleSet) + | hb_map (hb_add (this)) + | hb_apply ([digest] (const RuleSet &_) { _.collect_second_glyphs (digest); }) + ; + } + bool would_apply (hb_would_apply_context_t *c) const { const RuleSet &rule_set = this+ruleSet[(this+coverage).get_coverage (c->glyphs[0])]; @@ -3719,6 +3839,15 @@ struct ContextFormat2_5 ; } + void collect_second_glyphs (hb_set_digest_t *digest) const + { + const ClassDef &class_def = this+classDef; + + hb_iter (ruleSet) + | hb_map (hb_add (this)) + | hb_apply ([=, &class_def] (const RuleSet &_) { _.collect_second_glyphs (digest, &class_def); }) + ; + } + bool would_apply (hb_would_apply_context_t *c) const { const ClassDef &class_def = this+classDef; @@ -3745,13 +3874,20 @@ struct ContextFormat2_5 struct external_cache_t { hb_ot_layout_binary_cache_t coverage; + hb_ot_layout_ruleset_digest_t rule_sets[HB_VAR_ARRAY]; }; void *external_cache_create () const { - external_cache_t *cache = (external_cache_t *) hb_malloc (sizeof (external_cache_t)); + unsigned count = ruleSet.len; + unsigned size = sizeof (external_cache_t) - + HB_VAR_ARRAY * sizeof (hb_ot_layout_ruleset_digest_t) + + count * sizeof (hb_ot_layout_ruleset_digest_t); + external_cache_t *cache = (external_cache_t *) hb_malloc (size); if (likely (cache)) { cache->coverage.clear (); + for (unsigned i = 0; i < count; i++) + (this+ruleSet[i]).collect_first_input_classes (&cache->rule_sets[i]); } return cache; } @@ -3772,12 +3908,18 @@ struct ContextFormat2_5 struct ContextApplyLookupContext lookup_context = { {cached ? match_class_cached : match_class}, - &class_def + &class_def, + cached ? get_class_cached_value : get_class_value }; index = cached ? get_class_cached (class_def, c->buffer->cur()) : class_def.get_class (c->buffer->cur().codepoint); const RuleSet &rule_set = this+ruleSet[index]; - return_trace (rule_set.apply (c, lookup_context)); +#ifndef HB_NO_OT_LAYOUT_LOOKUP_CACHE + const hb_ot_layout_ruleset_digest_t *digest = cache && index < ruleSet.len ? &cache->rule_sets[index] : nullptr; +#else + const hb_ot_layout_ruleset_digest_t *digest = nullptr; +#endif + return_trace (rule_set.apply (c, lookup_context, digest)); } bool subset (hb_subset_context_t *c) const @@ -3956,6 +4098,14 @@ struct ContextFormat3 lookup_context); } + void collect_second_glyphs (hb_set_digest_t *digest) const + { + if (glyphCount <= 1) + *digest = hb_set_digest_t::full (); + else + (this+coverageZ[1]).collect_coverage (digest); + } + bool would_apply (hb_would_apply_context_t *c) const { const LookupRecord *lookupRecord = &StructAfter (coverageZ.as_array (glyphCount)); @@ -4097,6 +4247,7 @@ struct ChainContextApplyLookupContext { ChainContextApplyFuncs funcs; const void *match_data[3]; + get_value_func_t get_input_value; }; template @@ -4300,7 +4451,7 @@ static inline void chain_context_depend_lookup (hb_depend_context_t *c, } /* Positions 1+ (Input array) */ - for (unsigned i = 0; i < inputCount - 1; i++) + for (unsigned i = 0; i + 1 < inputCount; i++) { const hb_set_t *pos_glyphs = depend_position_glyphs ( c, lookup_context.context_format, lookup_context.intersects_data[1], @@ -4496,6 +4647,39 @@ struct ChainRule lookup_context); } + void collect_second_glyphs (hb_set_digest_t *digest, + const ClassDef *input_class_def = nullptr, + const ClassDef *lookahead_class_def = nullptr) const + { + const auto &input = StructAfter (backtrack); + const auto &lookahead = StructAfter (input); + + unsigned second; + const ClassDef *class_def; + if (input.lenP1 > 1) + { + second = input.arrayZ[0]; + class_def = input_class_def; + } + else if (lookahead.len) + { + second = lookahead.arrayZ[0]; + class_def = lookahead_class_def; + } + else + { + *digest = hb_set_digest_t::full (); + return; + } + + if (!class_def) + digest->add (second); + else if (!second) + *digest = hb_set_digest_t::full (); + else + class_def->collect_class (digest, second); + } + bool would_apply (hb_would_apply_context_t *c, const ChainContextApplyLookupContext &lookup_context) const { @@ -4647,6 +4831,22 @@ struct ChainRuleSet | hb_any ; } + + void collect_first_input_classes (hb_ot_layout_ruleset_digest_t *digest) const + { + digest->init (); + for (unsigned i = 0; i < rule.len; i++) + { + const ChainRule &r = this+rule.arrayZ[i]; + const auto &input = StructAfter (r.backtrack); + if (input.lenP1 <= 1) + { + digest->set_full (); + return; + } + digest->add (input.arrayZ[0]); + } + } void depend (hb_depend_context_t *c, unsigned value, ChainContextDependLookupContext &lookup_context) const { + hb_iter (rule) @@ -4685,6 +4885,17 @@ struct ChainRuleSet ; } + void collect_second_glyphs (hb_set_digest_t *digest, + const ClassDef *input_class_def = nullptr, + const ClassDef *lookahead_class_def = nullptr) const + { + + hb_iter (rule) + | hb_map (hb_add (this)) + | hb_apply ([=] (const ChainRule &_) + { _.collect_second_glyphs (digest, input_class_def, lookahead_class_def); }) + ; + } + bool would_apply (hb_would_apply_context_t *c, const ChainContextApplyLookupContext &lookup_context) const { @@ -4697,7 +4908,8 @@ struct ChainRuleSet } bool apply (hb_ot_apply_context_t *c, - const ChainContextApplyLookupContext &lookup_context) const + const ChainContextApplyLookupContext &lookup_context, + const hb_ot_layout_ruleset_digest_t *digest = nullptr) const { TRACE_APPLY (this); @@ -4733,7 +4945,7 @@ struct ChainRuleSet skippy_iter.set_glyph_data ((HBUINT16 *) nullptr); unsigned unsafe_to = (unsigned) -1, unsafe_to1, unsafe_to2 = 0; hb_glyph_info_t *first = nullptr, *second = nullptr; - bool matched = skippy_iter.next (); + bool matched = skippy_iter.next (&unsafe_to1); if (likely (matched)) { if (skippy_iter.may_skip (c->buffer->info[skippy_iter.idx])) @@ -4745,24 +4957,34 @@ struct ChainRuleSet first = &c->buffer->info[skippy_iter.idx]; unsafe_to1 = skippy_iter.idx + 1; + + if (digest && lookup_context.get_input_value && + !digest->may_have (lookup_context.get_input_value (*first, lookup_context.match_data[1]))) + { + c->buffer->unsafe_to_concat (c->buffer->idx, unsafe_to1); + return_trace (false); + } } else { - /* Failed to match a next glyph. Only try applying rules that have - * no further input and lookahead. */ - return_trace ( + bool unsafe_to_concat = false; + bool ret = + hb_iter (rule) | hb_map (hb_add (this)) | hb_filter ([&] (const ChainRule &_) { const auto &input = StructAfter (_.backtrack); const auto &lookahead = StructAfter (input); - return input.lenP1 <= 1 && lookahead.len == 0; + if (input.lenP1 <= 1 && lookahead.len == 0) return true; + unsafe_to_concat = true; + return false; }) | hb_map ([&] (const ChainRule &_) { return _.apply (c, lookup_context); }) | hb_any - ) ; + if (unsafe_to_concat) + c->buffer->unsafe_to_concat (c->buffer->idx, unsafe_to1); + return_trace (ret); } matched = skippy_iter.next (); if (likely (matched)) @@ -4998,6 +5220,14 @@ struct ChainContextFormat1_4 ; } + void collect_second_glyphs (hb_set_digest_t *digest) const + { + + hb_iter (ruleSet) + | hb_map (hb_add (this)) + | hb_apply ([digest] (const ChainRuleSet &_) { _.collect_second_glyphs (digest); }) + ; + } + bool would_apply (hb_would_apply_context_t *c) const { const ChainRuleSet &rule_set = this+ruleSet[(this+coverage).get_coverage (c->glyphs[0])]; @@ -5243,6 +5473,17 @@ struct ChainContextFormat2_5 ; } + void collect_second_glyphs (hb_set_digest_t *digest) const + { + const ClassDef &input_class_def = this+inputClassDef; + const ClassDef &lookahead_class_def = this+lookaheadClassDef; + + hb_iter (ruleSet) + | hb_map (hb_add (this)) + | hb_apply ([digest, &input_class_def, &lookahead_class_def] (const ChainRuleSet &_) + { _.collect_second_glyphs (digest, &input_class_def, &lookahead_class_def); }) + ; + } + bool would_apply (hb_would_apply_context_t *c) const { const ClassDef &backtrack_class_def = this+backtrackClassDef; @@ -5274,13 +5515,24 @@ struct ChainContextFormat2_5 struct external_cache_t { hb_ot_layout_binary_cache_t coverage; + hb_ot_layout_mapping_cache_t input_class; + hb_ot_layout_mapping_cache_t lookahead_class; + hb_ot_layout_ruleset_digest_t rule_sets[HB_VAR_ARRAY]; }; void *external_cache_create () const { - external_cache_t *cache = (external_cache_t *) hb_malloc (sizeof (external_cache_t)); + unsigned count = ruleSet.len; + unsigned size = sizeof (external_cache_t) - + HB_VAR_ARRAY * sizeof (hb_ot_layout_ruleset_digest_t) + + count * sizeof (hb_ot_layout_ruleset_digest_t); + external_cache_t *cache = (external_cache_t *) hb_malloc (size); if (likely (cache)) { cache->coverage.clear (); + cache->input_class.clear (); + cache->lookahead_class.clear (); + for (unsigned i = 0; i < count; i++) + (this+ruleSet[i]).collect_first_input_classes (&cache->rule_sets[i]); } return cache; } @@ -5301,22 +5553,67 @@ struct ChainContextFormat2_5 const ClassDef &input_class_def = this+inputClassDef; const ClassDef &lookahead_class_def = this+lookaheadClassDef; +#ifndef HB_NO_OT_LAYOUT_LOOKUP_CACHE + match_class_cache_data_t input_cache_data = { + &input_class_def, + cache ? &cache->input_class : nullptr + }; + match_class_cache_data_t lookahead_cache_data = { + &lookahead_class_def, + cache ? &cache->lookahead_class : nullptr + }; + const void *input_match_data = cached + ? static_cast (&input_class_def) + : static_cast (&input_cache_data); + const void *lookahead_match_data = cached + ? static_cast (&lookahead_class_def) + : static_cast (&lookahead_cache_data); + bool backtrack_uses_lookahead_cache = + !cached && &backtrack_class_def == &lookahead_class_def; + const void *backtrack_match_data = backtrack_uses_lookahead_cache + ? static_cast (&lookahead_cache_data) + : static_cast (&backtrack_class_def); +#endif + /* match_class_caches1 is slightly faster. Use it for lookahead, * which is typically longer. */ struct ChainContextApplyLookupContext lookup_context = { +#ifndef HB_NO_OT_LAYOUT_LOOKUP_CACHE + {{cached && &backtrack_class_def == &lookahead_class_def ? match_class_cached1 : + backtrack_uses_lookahead_cache ? match_class_cache : match_class, + cached ? match_class_cached2 : match_class_cache, + cached ? match_class_cached1 : match_class_cache}}, + {backtrack_match_data, + input_match_data, + lookahead_match_data}, + cached ? get_class_cached2_value : get_class_cache_value +#else {{cached && &backtrack_class_def == &lookahead_class_def ? match_class_cached1 : match_class, cached ? match_class_cached2 : match_class, cached ? match_class_cached1 : match_class}}, {&backtrack_class_def, &input_class_def, - &lookahead_class_def} + &lookahead_class_def}, + cached ? get_class_cached2_value : get_class_value +#endif }; +#ifndef HB_NO_OT_LAYOUT_LOOKUP_CACHE + index = cached + ? get_class_cached2 (input_class_def, c->buffer->cur()) + : input_class_def.get_class (c->buffer->cur().codepoint, input_cache_data.cache); +#else index = cached ? get_class_cached2 (input_class_def, c->buffer->cur()) : input_class_def.get_class (c->buffer->cur().codepoint); +#endif const ChainRuleSet &rule_set = this+ruleSet[index]; - return_trace (rule_set.apply (c, lookup_context)); +#ifndef HB_NO_OT_LAYOUT_LOOKUP_CACHE + const hb_ot_layout_ruleset_digest_t *digest = cache && index < ruleSet.len ? &cache->rule_sets[index] : nullptr; +#else + const hb_ot_layout_ruleset_digest_t *digest = nullptr; +#endif + return_trace (rule_set.apply (c, lookup_context, digest)); } bool subset (hb_subset_context_t *c) const @@ -5543,6 +5840,18 @@ struct ChainContextFormat3 lookup_context); } + void collect_second_glyphs (hb_set_digest_t *digest) const + { + const auto &input = StructAfter (backtrack); + const auto &lookahead = StructAfter (input); + if (input.len > 1) + (this+input[1]).collect_coverage (digest); + else if (lookahead.len) + (this+lookahead[0]).collect_coverage (digest); + else + *digest = hb_set_digest_t::full (); + } + bool would_apply (hb_would_apply_context_t *c) const { const auto &input = StructAfter (backtrack); @@ -5846,6 +6155,7 @@ struct hb_ot_layout_lookup_accelerator_t thiz->digest.init (); for (auto& subtable : hb_iter (thiz->subtables, count)) thiz->digest.union_ (subtable.digest); + thiz->digest_second = c_accelerate_subtables.digest_second; thiz->count = count; @@ -5876,7 +6186,6 @@ struct hb_ot_layout_lookup_accelerator_t #endif bool apply (hb_ot_apply_context_t *c, bool use_cache) const { - c->lookup_accel = this; if (count == 1) { /* The accelerator digest is the union of the subtable digests, so @@ -5929,6 +6238,7 @@ struct hb_ot_layout_lookup_accelerator_t hb_set_digest_t digest; + hb_set_digest_t digest_second; private: unsigned count = 0; /* Number of subtables in the array. */ #ifndef HB_NO_OT_LAYOUT_LOOKUP_CACHE diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index d1a4ee3e3..96e1ca0f4 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -265,6 +265,7 @@ OT::GDEF::is_blocklisted (hb_blob_t *blob, return false; } +template static void _hb_ot_layout_set_glyph_props (hb_font_t *font, hb_buffer_t *buffer) @@ -276,6 +277,8 @@ _hb_ot_layout_set_glyph_props (hb_font_t *font, hb_glyph_info_t *info = buffer->info; for (unsigned int i = 0; i < count; i++) { + if (SetDigest) + buffer->digest.add (info[i].codepoint); _hb_glyph_info_set_glyph_props (&info[i], gdef.get_glyph_props (info[i].codepoint)); _hb_glyph_info_clear_lig_props (&info[i]); } @@ -1573,7 +1576,15 @@ void hb_ot_layout_substitute_start (hb_font_t *font, hb_buffer_t *buffer) { - _hb_ot_layout_set_glyph_props (font, buffer); + _hb_ot_layout_set_glyph_props (font, buffer); +} + +void +hb_ot_layout_substitute_start_with_digest (hb_font_t *font, + hb_buffer_t *buffer) +{ + buffer->digest = hb_set_digest_t (); + _hb_ot_layout_set_glyph_props (font, buffer); } /** @@ -2037,7 +2048,9 @@ inline void hb_ot_map_t::apply (const Proxy &proxy, !buffer->message (font, "start lookup %u feature '%c%c%c%c'", lookup_index, HB_UNTAG (lookup.feature_tag))) continue; /* Only try applying the lookup if there is any overlap. */ - if (accel->digest.may_intersect (buffer->digest)) + if (accel->digest.may_intersect (buffer->digest) && + ((buffer->flags & HB_BUFFER_FLAG_PRODUCE_UNSAFE_TO_CONCAT) || + accel->digest_second.may_intersect (buffer->digest))) { c.set_lookup_index (lookup_index); c.set_lookup_mask (lookup.mask, false); diff --git a/src/hb-ot-layout.hh b/src/hb-ot-layout.hh index e3eaf13cb..c72c157e7 100644 --- a/src/hb-ot-layout.hh +++ b/src/hb-ot-layout.hh @@ -102,6 +102,10 @@ HB_INTERNAL void hb_ot_layout_substitute_start (hb_font_t *font, hb_buffer_t *buffer); +HB_INTERNAL void +hb_ot_layout_substitute_start_with_digest (hb_font_t *font, + hb_buffer_t *buffer); + namespace OT { struct hb_ot_apply_context_t; struct hb_ot_layout_lookup_accelerator_t; diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc index 691642402..e76e2af20 100644 --- a/src/hb-ot-shape.cc +++ b/src/hb-ot-shape.cc @@ -468,7 +468,8 @@ struct hb_ot_shape_context_t /* Prepare */ static void -hb_set_unicode_props (hb_buffer_t *buffer) +hb_set_unicode_props (hb_buffer_t *buffer, + hb_mask_t global_mask) { /* Implement enough of Unicode Graphemes here that shaping * in reverse-direction wouldn't break graphemes. Namely, @@ -482,6 +483,7 @@ hb_set_unicode_props (hb_buffer_t *buffer) hb_glyph_info_t *info = buffer->info; for (unsigned int i = 0; i < count; i++) { + info[i].mask = global_mask; _hb_glyph_info_set_unicode_props (&info[i], buffer); if (info[i].codepoint < 0x80) @@ -519,6 +521,7 @@ hb_set_unicode_props (hb_buffer_t *buffer) _hb_unicode_is_emoji_Extended_Pictographic (info[i + 1].codepoint)) { i++; + info[i].mask = global_mask; _hb_glyph_info_set_unicode_props (&info[i], buffer); _hb_glyph_info_set_continuation (&info[i], buffer); } @@ -743,16 +746,6 @@ hb_ot_shape_setup_masks_fraction (const hb_ot_shape_context_t *c) } } -static inline void -hb_ot_shape_initialize_masks (const hb_ot_shape_context_t *c) -{ - hb_ot_map_t *map = &c->plan->map; - hb_buffer_t *buffer = c->buffer; - - hb_mask_t global_mask = map->get_global_mask (); - buffer->reset_masks (global_mask); -} - static inline void hb_ot_shape_setup_masks (const hb_ot_shape_context_t *c) { @@ -912,14 +905,14 @@ hb_ot_substitute_plan (const hb_ot_shape_context_t *c) { hb_buffer_t *buffer = c->buffer; - hb_ot_layout_substitute_start (c->font, buffer); - - if (c->plan->fallback_glyph_classes) - hb_synthesize_glyph_classes (c->buffer); - #ifndef HB_NO_AAT_SHAPE if (unlikely (c->plan->apply_morx)) { + hb_ot_layout_substitute_start (c->font, buffer); + + if (c->plan->fallback_glyph_classes) + hb_synthesize_glyph_classes (buffer); + hb_aat_layout_substitute (c->plan, c->font, c->buffer, c->user_features, c->num_user_features); /* The buffer digest is only used by the OT lookup-apply loop; @@ -930,7 +923,11 @@ hb_ot_substitute_plan (const hb_ot_shape_context_t *c) else #endif { - c->buffer->update_digest (); + hb_ot_layout_substitute_start_with_digest (c->font, buffer); + + if (c->plan->fallback_glyph_classes) + hb_synthesize_glyph_classes (buffer); + c->plan->substitute (c->font, buffer); } } @@ -1178,8 +1175,7 @@ hb_ot_shape_internal (hb_ot_shape_context_t *c) _hb_buffer_allocate_unicode_vars (c->buffer); - hb_ot_shape_initialize_masks (c); - hb_set_unicode_props (c->buffer); + hb_set_unicode_props (c->buffer, c->plan->map.get_global_mask ()); hb_insert_dotted_circle (c->buffer, c->font); hb_form_clusters (c->buffer); diff --git a/src/hb-ot-shaper-use-table.hh b/src/hb-ot-shaper-use-table.hh index dad4fc8ae..08b5f7098 100644 --- a/src/hb-ot-shaper-use-table.hh +++ b/src/hb-ot-shaper-use-table.hh @@ -28,6 +28,8 @@ * # Updated for Unicode 15.0 by Andrew Glass 2022-09-16 * # Updated for Unicode 15.1 by Andrew Glass 2023-09-14 * # Updated for Unicode 16.0 by Andrew Glass 2024-09-11 + * # Updated for Unicode 17.0 by Andrew Glass 2025-09-15 + * # Updated for Unicode 18.0 by Andrew Glass 2026-09-04 * # Override values For Indic_Positional_Category * # Not derivable * # Initial version based on Unicode 7.0 by Andrew Glass 2014-03-17 @@ -40,6 +42,8 @@ * # Updated for Unicode 15.0 by Andrew Glass 2022-09-16 * # Updated for Unicode 15.1 by Andrew Glass 2023-09-14 * # Updated for Unicode 16.0 by Andrew Glass 2024-09-11 + * # Updated for Unicode 17.0 by Andrew Glass 2025-09-15 + * # Updated for Unicode 18.0 by Andrew Glass 2026-09-04 * UnicodeData.txt does not have a header. */ diff --git a/src/hb-ot-var-gvar-table.hh b/src/hb-ot-var-gvar-table.hh index ec1de51df..f5ba7c9aa 100644 --- a/src/hb-ot-var-gvar-table.hh +++ b/src/hb-ot-var-gvar-table.hh @@ -757,7 +757,8 @@ struct gvar_GVAR const hb_array_t points, hb_glyf_scratch_t &scratch, hb_scalar_cache_t *gvar_cache = nullptr, - bool phantom_only = false) const + bool phantom_only = false, + int64_t *budget = nullptr) const { if (unlikely (glyph >= glyphCount)) return true; hb_scalar_cache_t *scalar_cache = gvar_cache ? @@ -806,6 +807,11 @@ struct gvar_GVAR if (scalar == 0.f) continue; + if (budget && + unlikely (!hb_budget_spend (*budget, HB_BUDGET_1, + phantom_only && count >= 4 ? 4 : count))) + return false; + if (!private_points_checked) { auto scan = iterator; diff --git a/src/hb-outline.cc b/src/hb-outline.cc index 75ee3041a..b0b4f9d8d 100644 --- a/src/hb-outline.cc +++ b/src/hb-outline.cc @@ -298,6 +298,16 @@ hb_outline_recording_pen_close_path (hb_draw_funcs_t *dfuncs HB_UNUSED, c->contours.push (c->points.length); } +static int64_t * +hb_outline_recording_pen_get_budget_remaining (hb_draw_funcs_t *dfuncs HB_UNUSED, + void *data, + void *user_data HB_UNUSED) +{ + hb_outline_t *c = (hb_outline_t *) data; + + return c->budget_remaining; +} + static inline void free_static_outline_recording_pen_funcs (); static struct hb_outline_recording_pen_funcs_lazy_loader_t : hb_draw_funcs_lazy_loader_t @@ -311,6 +321,7 @@ static struct hb_outline_recording_pen_funcs_lazy_loader_t : hb_draw_funcs_lazy_ hb_draw_funcs_set_quadratic_to_func (funcs, hb_outline_recording_pen_quadratic_to, nullptr, nullptr); hb_draw_funcs_set_cubic_to_func (funcs, hb_outline_recording_pen_cubic_to, nullptr, nullptr); hb_draw_funcs_set_close_path_func (funcs, hb_outline_recording_pen_close_path, nullptr, nullptr); + hb_draw_funcs_set_get_budget_remaining_func (funcs, hb_outline_recording_pen_get_budget_remaining, nullptr, nullptr); hb_draw_funcs_make_immutable (funcs); diff --git a/src/hb-outline.hh b/src/hb-outline.hh index 9734583bf..c09db50b0 100644 --- a/src/hb-outline.hh +++ b/src/hb-outline.hh @@ -76,6 +76,7 @@ struct hb_outline_t hb_vector_t points; hb_vector_t contours; + int64_t *budget_remaining = nullptr; }; HB_INTERNAL hb_draw_funcs_t * diff --git a/src/hb-paint-extents.cc b/src/hb-paint-extents.cc index 7244612c7..274669ba1 100644 --- a/src/hb-paint-extents.cc +++ b/src/hb-paint-extents.cc @@ -62,13 +62,17 @@ hb_paint_extents_pop_transform (hb_paint_funcs_t *funcs HB_UNUSED, c->pop_transform (); } -/* Like the hb_draw_extents_get_funcs() sink, but also counts the - * consumed segments so they can be charged against the session work - * budget. */ -struct hb_paint_extents_counting_sink_t +/* Like the hb_draw_extents_get_funcs() sink, but tied to the paint + * session's live work budget. */ +struct hb_paint_extents_sink_t { hb_extents_t<> extents; - int64_t count = 0; + int64_t *budget_remaining; + + bool consume_segment () + { + return hb_budget_spend (*budget_remaining, HB_BUDGET_1); + } }; static void @@ -77,8 +81,8 @@ hb_paint_extents_count_move_to (hb_draw_funcs_t *dfuncs HB_UNUSED, void *data, float to_x, float to_y, void *user_data HB_UNUSED) { - hb_paint_extents_counting_sink_t *sink = (hb_paint_extents_counting_sink_t *) data; - sink->count++; + hb_paint_extents_sink_t *sink = (hb_paint_extents_sink_t *) data; + if (unlikely (!sink->consume_segment ())) return; sink->extents.add_point (to_x, to_y); } @@ -88,8 +92,8 @@ hb_paint_extents_count_line_to (hb_draw_funcs_t *dfuncs HB_UNUSED, void *data, float to_x, float to_y, void *user_data HB_UNUSED) { - hb_paint_extents_counting_sink_t *sink = (hb_paint_extents_counting_sink_t *) data; - sink->count++; + hb_paint_extents_sink_t *sink = (hb_paint_extents_sink_t *) data; + if (unlikely (!sink->consume_segment ())) return; sink->extents.add_point (to_x, to_y); } @@ -100,8 +104,8 @@ hb_paint_extents_count_quadratic_to (hb_draw_funcs_t *dfuncs HB_UNUSED, void *da float to_x, float to_y, void *user_data HB_UNUSED) { - hb_paint_extents_counting_sink_t *sink = (hb_paint_extents_counting_sink_t *) data; - sink->count++; + hb_paint_extents_sink_t *sink = (hb_paint_extents_sink_t *) data; + if (unlikely (!sink->consume_segment ())) return; sink->extents.add_point (control_x, control_y); sink->extents.add_point (to_x, to_y); } @@ -114,13 +118,19 @@ hb_paint_extents_count_cubic_to (hb_draw_funcs_t *dfuncs HB_UNUSED, void *data, float to_x, float to_y, void *user_data HB_UNUSED) { - hb_paint_extents_counting_sink_t *sink = (hb_paint_extents_counting_sink_t *) data; - sink->count++; + hb_paint_extents_sink_t *sink = (hb_paint_extents_sink_t *) data; + if (unlikely (!sink->consume_segment ())) return; sink->extents.add_point (control1_x, control1_y); sink->extents.add_point (control2_x, control2_y); sink->extents.add_point (to_x, to_y); } +static int64_t * +hb_paint_extents_get_budget_remaining (hb_draw_funcs_t *, void *draw_data, void *) +{ + return ((hb_paint_extents_sink_t *) draw_data)->budget_remaining; +} + static inline void free_static_paint_extents_draw_funcs (); static struct hb_paint_extents_draw_funcs_lazy_loader_t : hb_draw_funcs_lazy_loader_t @@ -133,6 +143,7 @@ static struct hb_paint_extents_draw_funcs_lazy_loader_t : hb_draw_funcs_lazy_loa hb_draw_funcs_set_line_to_func (funcs, hb_paint_extents_count_line_to, nullptr, nullptr); hb_draw_funcs_set_quadratic_to_func (funcs, hb_paint_extents_count_quadratic_to, nullptr, nullptr); hb_draw_funcs_set_cubic_to_func (funcs, hb_paint_extents_count_cubic_to, nullptr, nullptr); + hb_draw_funcs_set_get_budget_remaining_func (funcs, hb_paint_extents_get_budget_remaining, nullptr, nullptr); hb_draw_funcs_make_immutable (funcs); @@ -157,14 +168,11 @@ hb_paint_extents_push_clip_glyph (hb_paint_funcs_t *funcs HB_UNUSED, { hb_paint_extents_context_t *c = (hb_paint_extents_context_t *) paint_data; - hb_paint_extents_counting_sink_t sink; + hb_paint_extents_sink_t sink {{}, &c->budget_remaining}; /* Skip the outline extraction when the session work budget is * spent; an empty clip clips everything out. */ - if (likely (c->work_left > 0)) - { + if (likely (c->budget_remaining >= 0)) hb_font_draw_glyph (font, glyph, static_paint_extents_draw_funcs.get_unconst (), &sink); - c->work_left -= 1 + sink.count; - } c->push_clip (sink.extents); } @@ -291,6 +299,29 @@ hb_paint_extents_paint_sweep_gradient (hb_paint_funcs_t *funcs HB_UNUSED, c->paint (); } +static hb_bool_t +hb_paint_extents_set_budget (hb_paint_funcs_t *, void *paint_data, + int64_t budget, void *) +{ + auto *context = (hb_paint_extents_context_t *) paint_data; + context->budget = budget; + context->budget_initialized = true; + context->recharge_budget (); + return true; +} + +static int64_t +hb_paint_extents_get_budget (hb_paint_funcs_t *, void *paint_data, void *) +{ + return ((hb_paint_extents_context_t *) paint_data)->budget; +} + +static int64_t * +hb_paint_extents_get_budget_remaining (hb_paint_funcs_t *, void *paint_data, void *) +{ + return &((hb_paint_extents_context_t *) paint_data)->budget_remaining; +} + static inline void free_static_paint_extents_funcs (); static struct hb_paint_extents_funcs_lazy_loader_t : hb_paint_funcs_lazy_loader_t @@ -311,6 +342,9 @@ static struct hb_paint_extents_funcs_lazy_loader_t : hb_paint_funcs_lazy_loader_ hb_paint_funcs_set_linear_gradient_func (funcs, hb_paint_extents_paint_linear_gradient, nullptr, nullptr); hb_paint_funcs_set_radial_gradient_func (funcs, hb_paint_extents_paint_radial_gradient, nullptr, nullptr); hb_paint_funcs_set_sweep_gradient_func (funcs, hb_paint_extents_paint_sweep_gradient, nullptr, nullptr); + hb_paint_funcs_set_set_budget_func (funcs, hb_paint_extents_set_budget, nullptr, nullptr); + hb_paint_funcs_set_get_budget_func (funcs, hb_paint_extents_get_budget, nullptr, nullptr); + hb_paint_funcs_set_get_budget_remaining_func (funcs, hb_paint_extents_get_budget_remaining, nullptr, nullptr); hb_paint_funcs_make_immutable (funcs); diff --git a/src/hb-paint-extents.hh b/src/hb-paint-extents.hh index 102af2b7f..62ecc2db2 100644 --- a/src/hb-paint-extents.hh +++ b/src/hb-paint-extents.hh @@ -40,7 +40,15 @@ struct hb_paint_extents_context_t transforms.clear (); clips.clear (); groups.clear (); - work_left = HB_PAINT_EXTENTS_MAX_WORK; + /* COLR scratch storage is zero-allocated and reused without running + * constructors. Distinguish that state from an explicitly requested + * zero budget. */ + if (unlikely (!budget_initialized)) + { + budget = HB_BUDGET_DEFAULT; + budget_initialized = true; + } + recharge_budget (); transforms.push (hb_transform_t<>{}); clips.push (hb_bounds_t<>{hb_bounds_t<>::UNBOUNDED}); @@ -133,10 +141,17 @@ struct hb_paint_extents_context_t } /* Cumulative work budget for the current session; reset by clear(). - * Charged with the outline points consumed by each clip-glyph draw, - * so per-glyph outline limits cannot multiply with the paint-graph - * traversal limits of the font tables driving us (e.g. COLR). */ - int64_t work_left = HB_PAINT_EXTENTS_MAX_WORK; + * Outline traversal and consumed segments charge the same live + * counter. */ + int64_t budget = HB_BUDGET_DEFAULT; + bool budget_initialized = true; + int64_t budget_remaining = HB_BUDGET_GLYPH; + + void recharge_budget () + { + budget_remaining = budget == HB_BUDGET_DEFAULT ? + HB_BUDGET_GLYPH : budget; + } protected: hb_vector_t> transforms; diff --git a/src/hb-paint.cc b/src/hb-paint.cc index 08b00accc..5bfc5e4a5 100644 --- a/src/hb-paint.cc +++ b/src/hb-paint.cc @@ -160,6 +160,19 @@ hb_paint_custom_palette_color_nil (hb_paint_funcs_t *funcs, void *paint_data, hb_color_t *color, void *user_data) { return false; } +static hb_bool_t +hb_paint_set_budget_nil (hb_paint_funcs_t *funcs HB_UNUSED, void *paint_data HB_UNUSED, + int64_t budget HB_UNUSED, + void *user_data HB_UNUSED) { return false; } + +static int64_t +hb_paint_get_budget_nil (hb_paint_funcs_t *funcs HB_UNUSED, void *paint_data HB_UNUSED, + void *user_data HB_UNUSED) { return HB_BUDGET_DEFAULT; } + +static int64_t * +hb_paint_get_budget_remaining_nil (hb_paint_funcs_t *funcs HB_UNUSED, void *paint_data HB_UNUSED, + void *user_data HB_UNUSED) { return nullptr; } + static bool _hb_paint_funcs_set_preamble (hb_paint_funcs_t *funcs, bool func_is_null, @@ -420,6 +433,67 @@ hb_paint_funcs_is_immutable (hb_paint_funcs_t *funcs) return hb_object_is_immutable (funcs); } +/** + * hb_paint_set_budget: + * @funcs: paint functions object + * @paint_data: associated paint data + * @budget: the new work-budget policy + * + * Sets the work-budget policy and recharges the live work budget. Negative + * values other than #HB_BUDGET_DEFAULT are clamped to zero. + * + * Return value: `true` if the paint functions support work budgets + * + * XSince: REPLACEME + **/ +hb_bool_t +hb_paint_set_budget (hb_paint_funcs_t *funcs, void *paint_data, int64_t budget) +{ + return funcs->set_budget (paint_data, budget); +} + +/** + * hb_paint_get_budget: + * @funcs: paint functions object + * @paint_data: associated paint data + * + * Fetches the configured work-budget policy. + * + * Return value: the configured policy, or #HB_BUDGET_DEFAULT if unsupported + * + * XSince: REPLACEME + **/ +int64_t +hb_paint_get_budget (hb_paint_funcs_t *funcs, void *paint_data) +{ + return funcs->get_budget (paint_data); +} + +/** + * hb_paint_get_budget_remaining: + * @funcs: paint functions object + * @paint_data: associated paint data + * + * Fetches the live work budget. A negative value means the budget was + * exhausted. Zero means the preceding work fit exactly, but no positive-cost + * work can start. + * + * Return value: the live work budget; if it is not tracked, the concrete + * configured policy or #HB_BUDGET_UNLIMITED + * + * XSince: REPLACEME + **/ +int64_t +hb_paint_get_budget_remaining (hb_paint_funcs_t *funcs, void *paint_data) +{ + int64_t *remaining = funcs->get_budget_remaining_ptr (paint_data); + if (remaining) + return *remaining; + + int64_t budget = funcs->get_budget (paint_data); + return budget == HB_BUDGET_DEFAULT ? HB_BUDGET_UNLIMITED : budget; +} + /** * hb_color_line_get_color_stops: diff --git a/src/hb-paint.h b/src/hb-paint.h index 7064b3456..41eab791f 100644 --- a/src/hb-paint.h +++ b/src/hb-paint.h @@ -63,6 +63,109 @@ HB_BEGIN_DECLS **/ typedef struct hb_paint_funcs_t hb_paint_funcs_t; +/** + * hb_paint_set_budget_func_t: + * @funcs: paint functions object + * @paint_data: The data accompanying the paint functions + * @budget: the new work-budget policy + * @user_data: User data pointer passed to hb_paint_funcs_set_set_budget_func() + * + * Sets the work-budget policy and recharges the live work budget. @budget is + * #HB_BUDGET_DEFAULT, #HB_BUDGET_UNLIMITED, or a non-negative concrete value. + * + * Return value: `true` if the budget was set, `false` if unsupported + * + * XSince: REPLACEME + **/ +typedef hb_bool_t (*hb_paint_set_budget_func_t) (hb_paint_funcs_t *funcs, + void *paint_data, + int64_t budget, + void *user_data); + +/** + * hb_paint_get_budget_func_t: + * @funcs: paint functions object + * @paint_data: The data accompanying the paint functions + * @user_data: User data pointer passed to hb_paint_funcs_set_get_budget_func() + * + * Fetches the configured work-budget policy. + * + * Return value: the configured work-budget policy + * + * XSince: REPLACEME + **/ +typedef int64_t (*hb_paint_get_budget_func_t) (hb_paint_funcs_t *funcs, + void *paint_data, + void *user_data); + +/** + * hb_paint_get_budget_remaining_func_t: + * @funcs: paint functions object + * @paint_data: The data accompanying the paint functions + * @user_data: User data pointer passed to + * hb_paint_funcs_set_get_budget_remaining_func() + * + * Fetches the address of the live work budget. The returned address must stay + * valid while @paint_data is used with @funcs. The live value must be concrete; + * it must not contain #HB_BUDGET_DEFAULT. + * + * Return value: (nullable) (transfer none): the live work budget, or `NULL` if + * live budget accounting is unsupported + * + * XSince: REPLACEME + **/ +typedef int64_t *(*hb_paint_get_budget_remaining_func_t) (hb_paint_funcs_t *funcs, + void *paint_data, + void *user_data); + +/** + * hb_paint_funcs_set_set_budget_func: + * @funcs: paint functions object + * @func: (closure user_data) (destroy destroy) (scope notified): budget setter + * @user_data: Data to pass to @func + * @destroy: (nullable): callback to destroy @user_data + * + * Sets the budget setter callback. + * + * XSince: REPLACEME + **/ +HB_EXTERN void +hb_paint_funcs_set_set_budget_func (hb_paint_funcs_t *funcs, + hb_paint_set_budget_func_t func, + void *user_data, hb_destroy_func_t destroy); + +/** + * hb_paint_funcs_set_get_budget_func: + * @funcs: paint functions object + * @func: (closure user_data) (destroy destroy) (scope notified): budget getter + * @user_data: Data to pass to @func + * @destroy: (nullable): callback to destroy @user_data + * + * Sets the budget-policy getter callback. + * + * XSince: REPLACEME + **/ +HB_EXTERN void +hb_paint_funcs_set_get_budget_func (hb_paint_funcs_t *funcs, + hb_paint_get_budget_func_t func, + void *user_data, hb_destroy_func_t destroy); + +/** + * hb_paint_funcs_set_get_budget_remaining_func: + * @funcs: paint functions object + * @func: (closure user_data) (destroy destroy) (scope notified): live-budget getter + * @user_data: Data to pass to @func + * @destroy: (nullable): callback to destroy @user_data + * + * Sets the live-budget getter callback. + * + * XSince: REPLACEME + **/ +HB_EXTERN void +hb_paint_funcs_set_get_budget_remaining_func (hb_paint_funcs_t *funcs, + hb_paint_get_budget_remaining_func_t func, + void *user_data, hb_destroy_func_t destroy); + HB_EXTERN hb_paint_funcs_t * hb_paint_funcs_create (void); @@ -93,6 +196,16 @@ hb_paint_funcs_make_immutable (hb_paint_funcs_t *funcs); HB_EXTERN hb_bool_t hb_paint_funcs_is_immutable (hb_paint_funcs_t *funcs); +HB_EXTERN hb_bool_t +hb_paint_set_budget (hb_paint_funcs_t *funcs, void *paint_data, + int64_t budget); + +HB_EXTERN int64_t +hb_paint_get_budget (hb_paint_funcs_t *funcs, void *paint_data); + +HB_EXTERN int64_t +hb_paint_get_budget_remaining (hb_paint_funcs_t *funcs, void *paint_data); + /** * hb_paint_push_transform_func_t: * @funcs: paint functions object diff --git a/src/hb-paint.hh b/src/hb-paint.hh index 39135a536..24e0fc313 100644 --- a/src/hb-paint.hh +++ b/src/hb-paint.hh @@ -49,6 +49,9 @@ HB_PAINT_FUNC_IMPLEMENT (pop_group) \ HB_PAINT_FUNC_IMPLEMENT (custom_palette_color) \ HB_PAINT_FUNC_IMPLEMENT (fill_glyph) \ + HB_PAINT_FUNC_IMPLEMENT (set_budget) \ + HB_PAINT_FUNC_IMPLEMENT (get_budget) \ + HB_PAINT_FUNC_IMPLEMENT (get_budget_remaining) \ /* ^--- Add new callbacks here */ struct hb_paint_funcs_t @@ -183,6 +186,19 @@ struct hb_paint_funcs_t color_index, color, !user_data ? nullptr : user_data->custom_palette_color); } + bool set_budget (void *paint_data, int64_t budget) + { + if (budget < 0 && budget != HB_BUDGET_DEFAULT) + budget = 0; + return func.set_budget (this, paint_data, budget, + !user_data ? nullptr : user_data->set_budget); + } + int64_t get_budget (void *paint_data) + { return func.get_budget (this, paint_data, + !user_data ? nullptr : user_data->get_budget); } + int64_t *get_budget_remaining_ptr (void *paint_data) + { return func.get_budget_remaining (this, paint_data, + !user_data ? nullptr : user_data->get_budget_remaining); } /* Internal specializations. */ diff --git a/src/hb-raster-draw.cc b/src/hb-raster-draw.cc index b20ce0ddc..e567c10f6 100644 --- a/src/hb-raster-draw.cc +++ b/src/hb-raster-draw.cc @@ -83,11 +83,21 @@ struct hb_raster_draw_t float flatten_clip_x0 = 0.f, flatten_clip_y0 = 0.f; float flatten_clip_x1 = 0.f, flatten_clip_y1 = 0.f; - /* Curve-flattening work, charged one unit per Bézier subdivision. - When external_work is set (by raster-paint), that session budget - is charged instead of the standalone per-session one. */ - int64_t flatten_work_left = HB_RASTER_MAX_DRAW_WORK; - int64_t *external_work = nullptr; + /* Work budget for outline traversal and curve flattening. A paint + backend seeds this through the public draw-budget API before drawing + and reads the remainder back afterwards, so a whole paint session + shares one budget without reaching into this object. */ + int64_t budget = HB_BUDGET_DEFAULT; + int64_t budget_remaining = HB_BUDGET_GLYPH; + + void recharge_budget () + { + budget_remaining = budget == HB_BUDGET_DEFAULT ? + HB_BUDGET_GLYPH : budget; + } + + int64_t *get_budget_remaining () + { return &budget_remaining; } /* Accumulated geometry */ int64_t edges_left = HB_RASTER_MAX_DRAW_EDGES; @@ -478,8 +488,7 @@ hb_raster_draw_clear (hb_raster_draw_t *draw) draw->has_extents = false; draw->has_clip_box = false; draw->flatten_clip_active = false; - draw->flatten_work_left = HB_RASTER_MAX_DRAW_WORK; - draw->external_work = nullptr; + draw->recharge_budget (); draw->edges_left = HB_RASTER_MAX_DRAW_EDGES; draw->edges.clear (); draw->active_edges.clear (); @@ -501,6 +510,7 @@ hb_raster_draw_reset (hb_raster_draw_t *draw) draw->transform = {1, 0, 0, 1, 0, 0}; draw->x_scale_factor = 1.f; draw->y_scale_factor = 1.f; + draw->budget = HB_BUDGET_DEFAULT; hb_raster_draw_clear (draw); } @@ -517,23 +527,6 @@ hb_raster_draw_set_clip_box (hb_raster_draw_t *draw, hb_raster_draw_update_flatten_clip (draw); } -void -hb_raster_draw_set_external_work (hb_raster_draw_t *draw, - int64_t *work_left) -{ - draw->external_work = work_left; -} - -int64_t -hb_raster_draw_get_edge_work (hb_raster_draw_t *draw, unsigned max_rows) -{ - int64_t work = 0; - for (const auto &e : draw->edges) - work += 1 + hb_min (((int64_t) e.yH - (int64_t) e.yL) >> HB_RASTER_PIXEL_BITS, - (int64_t) max_rows); - return work; -} - /** * hb_raster_draw_recycle_image: * @draw: a rasterizer @@ -619,7 +612,7 @@ flatten_quadratic_recursive (hb_raster_draw_t *draw, unsigned top = 0; bool check_clip = draw->flatten_clip_active; - int64_t *work = draw->external_work ? draw->external_work : &draw->flatten_work_left; + int64_t *work = draw->get_budget_remaining (); int64_t work_left = *work; while (true) @@ -829,7 +822,7 @@ flatten_cubic_recursive (hb_raster_draw_t *draw, unsigned top = 0; bool check_clip = draw->flatten_clip_active; - int64_t *work = draw->external_work ? draw->external_work : &draw->flatten_work_left; + int64_t *work = draw->get_budget_remaining (); int64_t work_left = *work; while (true) @@ -1091,6 +1084,28 @@ hb_raster_close_path (hb_draw_funcs_t *dfuncs HB_UNUSED, /* no-op: hb_draw_funcs_t already emits closing line_to before us */ } +static hb_bool_t +hb_raster_draw_set_budget (hb_draw_funcs_t *, void *draw_data, + int64_t budget, void *) +{ + auto *draw = (hb_raster_draw_t *) draw_data; + draw->budget = budget; + draw->recharge_budget (); + return true; +} + +static int64_t +hb_raster_draw_get_budget (hb_draw_funcs_t *, void *draw_data, void *) +{ + return ((hb_raster_draw_t *) draw_data)->budget; +} + +static int64_t * +hb_raster_draw_get_budget_remaining (hb_draw_funcs_t *, void *draw_data, void *) +{ + return ((hb_raster_draw_t *) draw_data)->get_budget_remaining (); +} + /* Lazy-loader singleton for draw funcs */ @@ -1107,6 +1122,9 @@ static struct hb_raster_draw_funcs_lazy_loader_t : hb_draw_funcs_lazy_loader_twork_left = hb_max ((int64_t) HB_RASTER_MAX_PAINT_WORK, - (int64_t) HB_RASTER_MAX_PAINT_WORK_PASSES * - c->fixed_extents.width * c->fixed_extents.height); + /* Resolve the surface-sized pixel budget now that the surface size is + * known. An unlimited policy disables the pixel budget, so leave it. + * The outline budget is re-resolved to the same value it already holds + * (nothing has been drawn yet). */ + if (c->budget != HB_BUDGET_UNLIMITED) + c->recharge_budget (); /* Initial clip: full coverage rectangle */ hb_raster_clip_t clip; @@ -204,10 +205,11 @@ hb_raster_paint_color_glyph (hb_paint_funcs_t *pfuncs HB_UNUSED, typedef void (*hb_raster_paint_clip_mask_emit_t) (hb_raster_draw_t *rdr, void *user_data); -/* Attach the surface box and the session work budget to @rdr before +/* Attach the surface box to @rdr and seed its outline budget before * outlines are drawn into it: curves outside the surface collapse to - * their chord, and flattening work is charged as it happens instead - * of only after the whole outline has been emitted. */ + * their chord, and outline traversal and curve flattening charge the + * seeded budget. hb_raster_paint_readback_budget() pulls the remainder + * back into the session afterwards. */ static void hb_raster_paint_attach_clip_rdr (hb_raster_paint_t *c, hb_raster_draw_t *rdr, @@ -218,7 +220,16 @@ hb_raster_paint_attach_clip_rdr (hb_raster_paint_t *c, (float) surf->extents.y_origin, (float) surf->extents.x_origin + (float) surf->extents.width, (float) surf->extents.y_origin + (float) surf->extents.height); - hb_raster_draw_set_external_work (rdr, &c->work_left); + hb_draw_set_budget (hb_raster_draw_get_funcs (rdr), rdr, c->budget_remaining); +} + +/* Pull the outline budget the rasterizer has consumed back into the + * session, so it aggregates across every glyph in the paint walk. */ +static void +hb_raster_paint_readback_budget (hb_raster_paint_t *c, + hb_raster_draw_t *rdr) +{ + c->budget_remaining = hb_draw_get_budget_remaining (hb_raster_draw_get_funcs (rdr), rdr); } static void @@ -273,10 +284,6 @@ hb_raster_paint_finalize_path_clip (hb_raster_paint_t *c, hb_raster_image_t *surf, unsigned w, unsigned h) { - /* Charge the scanline work of the accumulated outline before - * rendering it. */ - c->work_left -= hb_raster_draw_get_edge_work (rdr, h); - hb_raster_image_t *mask_img = hb_raster_draw_render (rdr); if (unlikely (!mask_img)) @@ -416,7 +423,7 @@ hb_raster_paint_push_clip_from_emitter (hb_raster_paint_t *c, /* Out of budget: skip the glyph-outline extraction entirely, so * per-glyph outline limits cannot multiply with the caller's * paint-graph traversal limits. */ - if (unlikely (c->work_left <= 0)) + if (unlikely (c->budget_remaining < 0)) { hb_raster_paint_push_empty_clip (c, w, h); return; @@ -427,6 +434,7 @@ hb_raster_paint_push_clip_from_emitter (hb_raster_paint_t *c, hb_raster_draw_set_transform (rdr, t.xx, t.yx, t.xy, t.yy, t.x0, t.y0); hb_raster_paint_attach_clip_rdr (c, rdr, surf); emit (rdr, emit_data); + hb_raster_paint_readback_budget (c, rdr); hb_raster_paint_finalize_path_clip (c, rdr, surf, w, h); } @@ -744,7 +752,8 @@ hb_raster_paint_push_clip_path_end (hb_paint_funcs_t *pfuncs HB_UNUSED, unsigned w = surf->extents.width; unsigned h = surf->extents.height; - if (unlikely (c->work_left <= 0)) + hb_raster_paint_readback_budget (c, c->clip_rdr); + if (unlikely (c->budget_remaining < 0)) { hb_raster_draw_clear (c->clip_rdr); hb_raster_paint_push_empty_clip (c, w, h); @@ -927,7 +936,7 @@ hb_raster_paint_fill_glyph (hb_paint_funcs_t *pfuncs HB_UNUSED, if (unlikely (!surf)) return; /* Out of budget: skip the glyph-outline extraction entirely. */ - if (unlikely (c->work_left <= 0)) return; + if (unlikely (c->budget_remaining < 0)) return; hb_raster_draw_t *rdr = c->clip_rdr; hb_transform_t<> t = c->current_effective_transform (); @@ -936,10 +945,7 @@ hb_raster_paint_fill_glyph (hb_paint_funcs_t *pfuncs HB_UNUSED, hb_raster_paint_glyph_clip_data_t data = {glyph, font}; hb_raster_paint_emit_clip_glyph_mask (rdr, &data); - - /* Charge the scanline work of the accumulated outline before - * rendering it. */ - c->work_left -= hb_raster_draw_get_edge_work (rdr, surf->extents.height); + hb_raster_paint_readback_budget (c, rdr); hb_raster_image_t *mask_img = hb_raster_draw_render (rdr); if (unlikely (!mask_img)) return; @@ -967,8 +973,9 @@ hb_raster_paint_image (hb_paint_funcs_t *pfuncs HB_UNUSED, ensure_initialized (c); - /* Out of budget: skip, including the image decode below. */ - if (unlikely (c->work_left <= 0)) return false; + /* Out of pixel budget: skip, including the image decode below. Image + * compositing is pixel work and does no outline traversal. */ + if (unlikely (c->pixel_remaining < 0)) return false; unsigned src_width = width; unsigned src_height = height; @@ -1847,6 +1854,28 @@ hb_raster_paint_custom_palette_color (hb_paint_funcs_t *funcs HB_UNUSED, return false; } +static hb_bool_t +hb_raster_paint_set_budget (hb_paint_funcs_t *, void *paint_data, + int64_t budget, void *) +{ + auto *paint = (hb_raster_paint_t *) paint_data; + paint->budget = budget; + paint->recharge_budget (); + return true; +} + +static int64_t +hb_raster_paint_get_budget (hb_paint_funcs_t *, void *paint_data, void *) +{ + return ((hb_raster_paint_t *) paint_data)->budget; +} + +static int64_t * +hb_raster_paint_get_budget_remaining (hb_paint_funcs_t *, void *paint_data, void *) +{ + return &((hb_raster_paint_t *) paint_data)->budget_remaining; +} + /* * Lazy-loader singleton for paint funcs @@ -1877,6 +1906,9 @@ static struct hb_raster_paint_funcs_lazy_loader_t : hb_paint_funcs_lazy_loader_t hb_paint_funcs_set_radial_gradient_func (funcs, hb_raster_paint_radial_gradient, nullptr, nullptr); hb_paint_funcs_set_sweep_gradient_func (funcs, hb_raster_paint_sweep_gradient, nullptr, nullptr); hb_paint_funcs_set_custom_palette_color_func (funcs, hb_raster_paint_custom_palette_color, nullptr, nullptr); + hb_paint_funcs_set_set_budget_func (funcs, hb_raster_paint_set_budget, nullptr, nullptr); + hb_paint_funcs_set_get_budget_func (funcs, hb_raster_paint_get_budget, nullptr, nullptr); + hb_paint_funcs_set_get_budget_remaining_func (funcs, hb_raster_paint_get_budget_remaining, nullptr, nullptr); hb_paint_funcs_make_immutable (funcs); @@ -2549,12 +2581,12 @@ hb_raster_paint_clear (hb_raster_paint_t *paint) { paint->fixed_extents = {}; paint->has_extents = false; - paint->work_left = HB_RASTER_MAX_PAINT_WORK; paint->transform_stack.clear (); paint->release_all_clips (); for (auto *s : paint->surface_stack) paint->release_surface (s); paint->surface_stack.clear (); + paint->recharge_budget (); hb_raster_draw_reset (paint->clip_rdr); } @@ -2574,6 +2606,7 @@ hb_raster_paint_reset (hb_raster_paint_t *paint) paint->x_scale_factor = 1.f; paint->y_scale_factor = 1.f; paint->foreground = HB_COLOR (0, 0, 0, 255); + paint->budget = HB_BUDGET_DEFAULT; hb_raster_paint_clear_custom_palette_colors (paint); hb_raster_paint_clear (paint); } diff --git a/src/hb-raster-paint.hh b/src/hb-raster-paint.hh index 6f7ebdce8..cae0af0a2 100644 --- a/src/hb-raster-paint.hh +++ b/src/hb-raster-paint.hh @@ -128,20 +128,48 @@ struct hb_raster_paint_t /* Internal rasterizer for clip-to-glyph */ hb_raster_draw_t *clip_rdr = nullptr; - /* Cumulative work budget for the current paint session; reset by - * hb_raster_paint_clear(). Bounds total pixel and outline work so - * that per-node costs cannot multiply with the paint-graph traversal - * limits of the font tables driving us (e.g. COLR). */ - int64_t work_left = HB_RASTER_MAX_PAINT_WORK; + /* Two work budgets for the current paint session, both reset by + * hb_raster_paint_clear(), so per-node costs cannot multiply with the + * paint-graph traversal limits of the font tables driving us (e.g. + * COLR). They bound different resources and must not share a counter: + * + * - The outline budget (policy + live) bounds glyph outline traversal + * and curve flattening. It is the public draw/paint budget, seeded + * into the clip rasterizer through the public draw-budget API and + * read back after each glyph. Default HB_BUDGET_GLYPH. + * + * - The pixel budget bounds scanline/fill work, which scales with + * surface area rather than outline complexity. It is sized from the + * surface once known and is internal (not exposed through the API); + * an unlimited outline policy disables it too. */ + int64_t budget = HB_BUDGET_DEFAULT; + int64_t budget_remaining = HB_BUDGET_GLYPH; + int64_t pixel_remaining = HB_BUDGET_GLYPH; /* Helpers */ - /* Returns whether the operation should proceed. Allows a single + int64_t get_default_pixel_budget () const + { + return hb_max ((int64_t) HB_BUDGET_GLYPH, + (int64_t) HB_BUDGET_RASTER_PAINT_PASSES * + fixed_extents.width * fixed_extents.height); + } + + void recharge_budget () + { + budget_remaining = budget == HB_BUDGET_DEFAULT ? + (int64_t) HB_BUDGET_GLYPH : budget; + pixel_remaining = budget == HB_BUDGET_UNLIMITED ? budget : + (surface_stack.length ? get_default_pixel_budget () : + (int64_t) HB_BUDGET_GLYPH); + } + + /* Returns whether the pixel operation should proceed. Allows a single * overshoot past zero; callers skip work once the budget is spent. */ bool charge_work (int64_t work) { - if (unlikely (work_left <= 0)) return false; - work_left -= work; + if (unlikely (pixel_remaining < 0)) return false; + pixel_remaining -= work; return true; } diff --git a/src/hb-raster.hh b/src/hb-raster.hh index a0c08a516..1b794fc8d 100644 --- a/src/hb-raster.hh +++ b/src/hb-raster.hh @@ -31,15 +31,6 @@ #include "hb-raster.h" -/* Scanline work of the edges accumulated in @draw since the last - * render/clear: one unit per edge plus its span in rows, clamped to - * @max_rows per edge. This is what rasterizing the edges costs, as - * each edge is walked once per row it crosses. Used by the paint - * layer to charge consumed outline work against its session work - * budget. */ -HB_INTERNAL int64_t -hb_raster_draw_get_edge_work (hb_raster_draw_t *draw, unsigned max_rows); - /* Visibility clip box for curve flattening, in device pixels. Curves * whose control-point bounding box falls entirely outside the box are * replaced by their chord, which is exact for coverage inside the box. @@ -49,15 +40,6 @@ hb_raster_draw_set_clip_box (hb_raster_draw_t *draw, float x0, float y0, float x1, float y1); -/* Points curve-flattening work charges at the caller's session budget - * (one unit per Bézier subdivision) instead of the standalone - * per-session HB_RASTER_MAX_DRAW_WORK budget. The rasterizer's local - * accumulated-edge limit still applies. Cleared by hb_raster_draw_clear() - * (and hence after every render). */ -HB_INTERNAL void -hb_raster_draw_set_external_work (hb_raster_draw_t *draw, - int64_t *work_left); - /* Shared pixel helpers (used by paint and image compositing). */ static HB_ALWAYS_INLINE uint8_t diff --git a/src/hb-repacker.hh b/src/hb-repacker.hh index dbf65c309..3ddc188d4 100644 --- a/src/hb-repacker.hh +++ b/src/hb-repacker.hh @@ -35,6 +35,7 @@ #include "graph/serialize.hh" using graph::graph_t; +using graph::graph_result_t; /* * For a detailed writeup on the overflow resolution algorithm see: @@ -69,7 +70,7 @@ struct lookup_size_t }; static inline -bool _presplit_subtables_if_needed (graph::gsubgpos_graph_context_t& ext_context) +graph_result_t _presplit_subtables_if_needed (graph::gsubgpos_graph_context_t& ext_context) { // For each lookup this will check the size of subtables and split them as needed // so that no subtable is at risk of overflowing. (where we support splitting for @@ -87,11 +88,10 @@ bool _presplit_subtables_if_needed (graph::gsubgpos_graph_context_t& ext_context for (unsigned lookup_index : lookup_indices) { graph::Lookup* lookup = ext_context.lookups.get(lookup_index); - if (!lookup->split_subtables_if_needed (ext_context, lookup_index)) - return false; + TRY (lookup->split_subtables_if_needed (ext_context, lookup_index)); } - return true; + return Ok(); } /* @@ -99,7 +99,7 @@ bool _presplit_subtables_if_needed (graph::gsubgpos_graph_context_t& ext_context * to extension lookups. */ static inline -bool _promote_extensions_if_needed (graph::gsubgpos_graph_context_t& ext_context) +graph_result_t _promote_extensions_if_needed (graph::gsubgpos_graph_context_t& ext_context) { // Simple Algorithm (v1, current): // 1. Calculate how many bytes each non-extension lookup consumes. @@ -117,7 +117,7 @@ bool _promote_extensions_if_needed (graph::gsubgpos_graph_context_t& ext_context // TODO(garretrieger): also support extension promotion during iterative resolution phase, then // we can use a less conservative threshold here. // TODO(grieger): skip this for the 24 bit case. - if (!ext_context.lookups) return true; + if (!ext_context.lookups) return Ok(); unsigned total_lookup_table_sizes = 0; hb_vector_t lookup_sizes; @@ -132,7 +132,7 @@ bool _promote_extensions_if_needed (graph::gsubgpos_graph_context_t& ext_context hb_set_t visited; lookup_sizes.push (lookup_size_t { lookup_index, - ext_context.graph.find_subgraph_size (lookup_index, visited), + ext_context.graph.find_subgraph_size (lookup_index, visited).value_or (0), lookup->number_of_subtables (), }); } @@ -167,7 +167,7 @@ bool _promote_extensions_if_needed (graph::gsubgpos_graph_context_t& ext_context { size_t lookup_size = ext_context.graph.vertices_[p.lookup_index].table_size (); hb_set_t visited; - size_t subtables_size = ext_context.graph.find_subgraph_size (p.lookup_index, visited, 1) - lookup_size; + size_t subtables_size = ext_context.graph.find_subgraph_size (p.lookup_index, visited, 1).value_or (0) - lookup_size; size_t remaining_size = p.size - subtables_size - lookup_size; l3_l4_size += subtables_size; @@ -181,16 +181,15 @@ bool _promote_extensions_if_needed (graph::gsubgpos_graph_context_t& ext_context layers_full = true; } - if (!ext_context.lookups.get(p.lookup_index)->make_extension (ext_context, p.lookup_index)) - return false; + TRY (ext_context.lookups.get(p.lookup_index)->make_extension (ext_context, p.lookup_index)); } - return true; + return Ok(); } static inline -bool _try_isolating_subgraphs (const hb_vector_t& overflows, - graph_t& sorted_graph) +graph_result_t _try_isolating_subgraphs (const hb_vector_t& overflows, + graph_t& sorted_graph) { unsigned space = 0; hb_set_t roots_to_isolate; @@ -212,7 +211,7 @@ bool _try_isolating_subgraphs (const hb_vector_t& over roots_to_isolate.add(root); } - if (!roots_to_isolate) return false; + if (!roots_to_isolate) return Ok(false); unsigned maximum_to_move = hb_max ((sorted_graph.num_roots_for_space (space) / 2u), 1u); if (roots_to_isolate.get_population () > maximum_to_move) { @@ -238,16 +237,17 @@ bool _try_isolating_subgraphs (const hb_vector_t& over roots_to_isolate.get_population (), sorted_graph.next_space ()); - sorted_graph.isolate_subgraph (roots_to_isolate); - sorted_graph.move_to_new_space (roots_to_isolate); + TRY_ASSIGN (bool isolated, sorted_graph.isolate_subgraph (roots_to_isolate)); + if (!isolated) return Ok(false); + TRY (sorted_graph.move_to_new_space (roots_to_isolate)); - return true; + return Ok(true); } static inline -bool _resolve_shared_overflow(const hb_vector_t& overflows, - int overflow_index, - graph_t& sorted_graph) +graph_result_t _resolve_shared_overflow(const hb_vector_t& overflows, + int overflow_index, + graph_t& sorted_graph) { const graph::overflow_record_t& r = overflows[overflow_index]; @@ -263,8 +263,8 @@ bool _resolve_shared_overflow(const hb_vector_t& overf } } - unsigned result = sorted_graph.duplicate(&parents, r.child); - if (result == (unsigned) -1 && parents.get_population() > 2) { + auto result = sorted_graph.duplicate(&parents, r.child); + if (!result.is_ok () && parents.get_population() > 2) { // All links to the child are overflowing, so we can't include all // in the duplication. Remove one parent from the duplication. // Remove the lowest index parent, which will be the closest to the child. @@ -272,7 +272,7 @@ bool _resolve_shared_overflow(const hb_vector_t& overf result = sorted_graph.duplicate(&parents, r.child); } - if (result == (unsigned) -1) return false; + if (!result.is_ok ()) return Ok(false); if (parents.get_population() > 1) { // If the duplicated node has more than one parent pre-emptively raise it's priority to the maximum. @@ -286,16 +286,16 @@ bool _resolve_shared_overflow(const hb_vector_t& overf // to move nodes closer, but only for non-shared nodes. Since this node is shared, it will simply be given // further duplication which defeats the attempt to duplicate with multiple parents. To fix this we // pre-emptively raise priority now which allows the duplicated node to pack into the same layer as it's parents. - sorted_graph.vertices_[result].give_max_priority(); + sorted_graph.vertices_[*result].give_max_priority(); } - return true; + return Ok(true); } static inline -bool _process_overflows (const hb_vector_t& overflows, - hb_set_t& priority_bumped_parents, - graph_t& sorted_graph) +graph_result_t _process_overflows (const hb_vector_t& overflows, + hb_set_t& priority_bumped_parents, + graph_t& sorted_graph) { bool resolution_attempted = false; @@ -303,19 +303,19 @@ bool _process_overflows (const hb_vector_t& overflows, for (int i = overflows.length - 1; i >= 0; i--) { const graph::overflow_record_t& r = overflows[i]; - const auto& child = sorted_graph.vertices_[r.child]; - if (child.is_shared ()) + if (sorted_graph.vertices_[r.child].is_shared ()) { // The child object is shared, we may be able to eliminate the overflow // by duplicating it. - if (_resolve_shared_overflow(overflows, i, sorted_graph)) - return true; + TRY_ASSIGN (bool resolved, _resolve_shared_overflow(overflows, i, sorted_graph)); + if (resolved) + return Ok(true); // Sometimes we can't duplicate a node which looks shared because it's not actually shared // (eg. all links from the same parent) in this case continue on to other resolution options. } - if (child.is_leaf () && !priority_bumped_parents.has (r.parent)) + if (sorted_graph.vertices_[r.child].is_leaf () && !priority_bumped_parents.has (r.parent)) { // This object is too far from it's parent, attempt to move it closer. // @@ -328,7 +328,8 @@ bool _process_overflows (const hb_vector_t& overflows, // is < then the total size of the children (and the parent can be moved). // Since in that case moving the parent will cause a smaller increase in // the length of other offsets. - if (sorted_graph.raise_childrens_priority (r.parent)) { + TRY_ASSIGN (bool raised, sorted_graph.raise_childrens_priority (r.parent)); + if (raised) { priority_bumped_parents.add (r.parent); resolution_attempted = true; } @@ -340,99 +341,106 @@ bool _process_overflows (const hb_vector_t& overflows, // - Table splitting. } - return resolution_attempted; + return Ok(resolution_attempted); } -inline bool +inline graph_result_t +_assign_spaces_and_sort (graph_t& sorted_graph /* IN/OUT */) +{ + DEBUG_MSG (SUBSET_REPACK, nullptr, "Assigning spaces to 32 bit subgraphs."); + TRY_ASSIGN (bool assigned, sorted_graph.assign_spaces ()); + if (assigned) + return sorted_graph.sort_shortest_distance (); + else + return sorted_graph.sort_shortest_distance_if_needed (); +} + +inline graph_result_t +_gsub_gpos_specialization (hb_tag_t table_tag, + bool always_recalculate_extensions, + graph_t& sorted_graph /* IN/OUT */) +{ + DEBUG_MSG (SUBSET_REPACK, nullptr, "Applying GSUB/GPOS repacking specializations."); + if (!always_recalculate_extensions) return _assign_spaces_and_sort (sorted_graph); + + auto context_res = graph::gsubgpos_graph_context_t::create (table_tag, sorted_graph); + + if (unlikely (context_res.is_err())) { + if (context_res.error() == graph::SANITIZE_FAILURE) + // Sanitize failures are ignored, and we just skip splitting/extension promotion which needs a valid + // GSUB/GPOS + return _assign_spaces_and_sort (sorted_graph); + else + // All other errors are propagated. + return Err(context_res.error()); + } + + // Otherwise we have a valid GSUB/GPOS table and can try extension promotion and splitting + auto& ext_context = *context_res; + DEBUG_MSG (SUBSET_REPACK, nullptr, "Splitting subtables if needed."); + TRY (_presplit_subtables_if_needed (ext_context)); + + DEBUG_MSG (SUBSET_REPACK, nullptr, "Promoting lookups to extensions if needed."); + TRY (_promote_extensions_if_needed (ext_context)); + + // an additional sorting is needed before assign_spaces () which requires + // correct topological ordering to find space roots + TRY (sorted_graph.sort_shortest_distance_if_needed ()); + + TRY_ASSIGN (bool will_overflow, graph::will_overflow (sorted_graph)); + if (!will_overflow) return Ok(); + return _assign_spaces_and_sort (sorted_graph); +} + +inline graph_result_t hb_resolve_graph_overflows (hb_tag_t table_tag, unsigned max_rounds , bool always_recalculate_extensions, graph_t& sorted_graph /* IN/OUT */) { DEBUG_MSG (SUBSET_REPACK, nullptr, "Repacking %c%c%c%c.", HB_UNTAG(table_tag)); - sorted_graph.sort_shortest_distance (); - if (sorted_graph.in_error ()) - { - DEBUG_MSG (SUBSET_REPACK, nullptr, "Sorted graph in error state after initial sort."); - return false; - } + TRY (sorted_graph.sort_shortest_distance ()); - bool will_overflow = graph::will_overflow (sorted_graph); + TRY_ASSIGN (bool will_overflow, graph::will_overflow (sorted_graph)); if (!will_overflow) - return true; + return Ok(); bool is_gsub_or_gpos = (table_tag == HB_OT_TAG_GPOS || table_tag == HB_OT_TAG_GSUB); - graph::gsubgpos_graph_context_t ext_context (table_tag, sorted_graph); - if (is_gsub_or_gpos && will_overflow) - { - DEBUG_MSG (SUBSET_REPACK, nullptr, "Applying GSUB/GPOS repacking specializations."); - if (always_recalculate_extensions) - { - DEBUG_MSG (SUBSET_REPACK, nullptr, "Splitting subtables if needed."); - if (!_presplit_subtables_if_needed (ext_context)) { - DEBUG_MSG (SUBSET_REPACK, nullptr, "Subtable splitting failed."); - return false; - } - - DEBUG_MSG (SUBSET_REPACK, nullptr, "Promoting lookups to extensions if needed."); - if (!_promote_extensions_if_needed (ext_context)) { - DEBUG_MSG (SUBSET_REPACK, nullptr, "Extensions promotion failed."); - return false; - } - - // an additional sorting is needed before assign_spaces () which requires - // correct topological ordering to find space roots - sorted_graph.sort_shortest_distance_if_needed (); - if (sorted_graph.in_error ()) - { - DEBUG_MSG (SUBSET_REPACK, nullptr, "Sorted graph in error state."); - return false; - } - - if (!graph::will_overflow (sorted_graph)) return true; - } - - DEBUG_MSG (SUBSET_REPACK, nullptr, "Assigning spaces to 32 bit subgraphs."); - if (sorted_graph.assign_spaces ()) - sorted_graph.sort_shortest_distance (); - else - sorted_graph.sort_shortest_distance_if_needed (); - } + if (is_gsub_or_gpos) + TRY(_gsub_gpos_specialization (table_tag, always_recalculate_extensions, sorted_graph)); unsigned round = 0; unsigned total_iterations = 0; hb_vector_t overflows; // TODO(garretrieger): select a good limit for max rounds. - while (!sorted_graph.in_error () - && graph::will_overflow (sorted_graph, &overflows) - && round < max_rounds - && total_iterations < HB_REPACKER_MAX_ITERATIONS) { + while (round < max_rounds && total_iterations < HB_REPACKER_MAX_ITERATIONS) { + TRY_ASSIGN (bool overflows_exist, graph::will_overflow (sorted_graph, &overflows)); + if (!overflows_exist) + break; + DEBUG_MSG (SUBSET_REPACK, nullptr, "=== Overflow resolution round %u ===", round); print_overflows (sorted_graph, overflows); total_iterations++; hb_set_t priority_bumped_parents; - if (!_try_isolating_subgraphs (overflows, sorted_graph)) + TRY_ASSIGN (bool isolated, _try_isolating_subgraphs (overflows, sorted_graph)); + if (!isolated) { round++; - if (!_process_overflows (overflows, priority_bumped_parents, sorted_graph)) + TRY_ASSIGN (bool processed, _process_overflows (overflows, priority_bumped_parents, sorted_graph)); + if (!processed) { DEBUG_MSG (SUBSET_REPACK, nullptr, "No resolution available :("); break; } } - sorted_graph.sort_shortest_distance (); + TRY (sorted_graph.sort_shortest_distance ()); } - if (sorted_graph.in_error ()) - { - DEBUG_MSG (SUBSET_REPACK, nullptr, "Sorted graph in error state."); - return false; - } - - if (graph::will_overflow (sorted_graph)) + TRY_ASSIGN (bool has_overflow, graph::will_overflow (sorted_graph)); + if (unlikely (has_overflow)) { if (is_gsub_or_gpos && !always_recalculate_extensions) { // If this a GSUB/GPOS table and we didn't try to extension promotion and table splitting then @@ -442,10 +450,10 @@ hb_resolve_graph_overflows (hb_tag_t table_tag, } DEBUG_MSG (SUBSET_REPACK, nullptr, "Offset overflow resolution failed."); - return false; + return Err(graph::OVERFLOW_RESOLUTION_FAILED); } - return true; + return Ok(); } /* @@ -467,31 +475,32 @@ hb_resolve_overflows (const T& packed, hb_tag_t table_tag, unsigned max_rounds = 32, bool recalculate_extensions = false) { - graph_t sorted_graph (packed); - if (sorted_graph.in_error ()) + auto graph_res = graph_t::create (packed); + if (!graph_res.is_ok ()) { - // Invalid graph definition. - return nullptr; - } - - if (!sorted_graph.is_fully_connected ()) - { - sorted_graph.print_orphaned_nodes (); - return nullptr; - } - - if (sorted_graph.in_error ()) - { - // Allocations failed somewhere DEBUG_MSG (SUBSET_REPACK, nullptr, - "Graph is in error, likely due to a memory allocation error."); + "Graph creation failed, cause: %s", graph::to_string(graph_res.error())); + return nullptr; + } + graph_t sorted_graph = std::move (*graph_res); + + auto resolve_res = hb_resolve_graph_overflows (table_tag, max_rounds, recalculate_extensions, sorted_graph); + if (resolve_res.is_err ()) + { + DEBUG_MSG (SUBSET_REPACK, nullptr, + "Overflow resolution failed, cause: %s", graph::to_string(resolve_res.error())); return nullptr; } - if (!hb_resolve_graph_overflows (table_tag, max_rounds, recalculate_extensions, sorted_graph)) + auto serialize_res = graph::serialize (sorted_graph); + if (serialize_res.is_err ()) + { + DEBUG_MSG (SUBSET_REPACK, nullptr, + "Serialization failed, cause: %s", graph::to_string(serialize_res.error())); return nullptr; + } - return graph::serialize (sorted_graph); + return *serialize_res; } #endif /* HB_REPACKER_HH */ diff --git a/src/hb-result.hh b/src/hb-result.hh new file mode 100644 index 000000000..f142c992c --- /dev/null +++ b/src/hb-result.hh @@ -0,0 +1,509 @@ +/* + * Copyright © 2025 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Google Author(s): Garret Rieger + */ + +#ifndef HB_RESULT_HH +#define HB_RESULT_HH + +#include "hb.hh" + +// Helper structs for Ok(...) and Err(...), not used directly +// by users of hb_result_t. +template +struct hb_result_ok_t +{ + T value; +}; + +template <> +struct hb_result_ok_t {}; + +template +struct hb_result_err_t +{ + E error; + + template + constexpr bool operator == (const hb_result_err_t& other) const { return error == other.error; } + template + constexpr bool operator != (const hb_result_err_t& other) const { return error != other.error; } +}; + +template struct _hb_is_result_tag : hb_false_type {}; +template struct _hb_is_result_tag> : hb_true_type {}; +template struct _hb_is_result_tag> : hb_true_type {}; + +template +static inline constexpr hb_result_ok_t Ok (T&& v) +{ + return hb_result_ok_t{std::forward (v)}; +} + +static inline constexpr hb_result_ok_t Ok () +{ + return hb_result_ok_t{}; +} + +template +static inline constexpr hb_result_err_t Err (E&& e) +{ + return hb_result_err_t{std::forward (e)}; +} + +template +struct HB_NODISCARD_STRUCT hb_result_t +{ + private: + union + { + T val_; + E err_; + }; + bool is_ok_; + + void destroy () + { + if (is_ok_) + val_.~T (); + else + err_.~E (); + } + + void init(const hb_result_t& o) { + is_ok_ = o.is_ok_; + if (is_ok_) + new (std::addressof (val_)) T (o.val_); + else + new (std::addressof (err_)) E (o.err_); + } + + void init(hb_result_t&& o) { + is_ok_ = o.is_ok_; + if (is_ok_) + new (std::addressof (val_)) T (std::move (o.val_)); + else + new (std::addressof (err_)) E (std::move (o.err_)); + } + + public: + ~hb_result_t () + { + destroy (); + } + + hb_result_t () = delete; + + hb_result_t (const hb_result_t& o) : is_ok_ (false) + { + init (o); + } + + hb_result_t (hb_result_t&& o) noexcept (std::is_nothrow_move_constructible::value && + std::is_nothrow_move_constructible::value) + : is_ok_ (false) + { + init (std::move (o)); + } + + hb_result_t& operator = (const hb_result_t& o) + { + if (this == &o) return *this; + if (is_ok_ && o.is_ok_) + { + val_ = o.val_; + } + else if (!is_ok_ && !o.is_ok_) + { + err_ = o.err_; + } + else + { + destroy (); + init (o); + } + return *this; + } + + hb_result_t& operator = (hb_result_t&& o) noexcept (std::is_nothrow_move_assignable::value && + std::is_nothrow_move_assignable::value) + { + if (this == &o) return *this; + if (is_ok_ && o.is_ok_) + { + val_ = std::move (o.val_); + } + else if (!is_ok_ && !o.is_ok_) + { + err_ = std::move (o.err_); + } + else + { + destroy (); + init (std::move (o)); + } + return *this; + } + + // Construct from Ok(...) tag + template ::value))> + hb_result_t (hb_result_ok_t&& o) : is_ok_ (true) + { + new (std::addressof (val_)) T (std::move (o.value)); + } + + template ::value))> + hb_result_t (const hb_result_ok_t& o) : is_ok_ (true) + { + new (std::addressof (val_)) T (o.value); + } + + // Construct from Err(...) tag + template ::value))> + hb_result_t (hb_result_err_t&& e) : is_ok_ (false) + { + new (std::addressof (err_)) E (std::move (e.error)); + } + + template ::value))> + hb_result_t (const hb_result_err_t& e) : is_ok_ (false) + { + new (std::addressof (err_)) E (e.error); + } + + // Construct directly from error E (when neither T or E are convertible into each other) + template + hb_result_t (F e) : is_ok_ (false) + { + new (std::addressof (err_)) E (std::move (e)); + } + + // Construct directly from value T (when neither T or E are convertible into each other) + template ::value && + !hb_is_same (hb_decay, E) && + !hb_is_same (hb_decay, hb_result_t) && + !_hb_is_result_tag>::value && + !(hb_is_convertible (T, E) || hb_is_convertible (E, T))))> + hb_result_t (U&& v) : is_ok_ (true) + { + new (std::addressof (val_)) T (std::forward (v)); + } + + // Move fallible into a result if it's in_error() method returns false. + static hb_result_t from (T&& fallible, E error_value) { + if (fallible.in_error()) { + return Err(error_value); + } + return Ok(fallible); + } + + bool is_ok () const { return is_ok_; } + bool is_err () const { return !is_ok_; } + explicit operator bool () const { return is_ok (); } + + T& value () & { assert (is_ok_); return val_; } + const T& value () const & { assert (is_ok_); return val_; } + T value () && { assert (is_ok_); return std::move (val_); } + + T& operator * () & { return value (); } + const T& operator * () const & { return value (); } + T operator * () && { return std::move (*this).value (); } + + T* operator -> () { return std::addressof (value ()); } + const T* operator -> () const { return std::addressof (value ()); } + + template + T value_or (U&& default_value) const & + { + if (is_ok_) return val_; + return std::forward (default_value); + } + + template + T value_or (U&& default_value) && + { + if (is_ok_) return std::move (val_); + return std::forward (default_value); + } + + T value_or_default () const & + { + if (is_ok_) return val_; + return T (); + } + + T value_or_default () && + { + if (is_ok_) return std::move (val_); + return T (); + } + + const E& error () const & { assert (!is_ok_); return err_; } + E& error () & { assert (!is_ok_); return err_; } + E error () && { assert (!is_ok_); return std::move (err_); } + + bool operator == (const hb_result_t& o) const + { + if (is_ok_ != o.is_ok_) return false; + if (is_ok_) return val_ == o.val_; + return err_ == o.err_; + } + + bool operator != (const hb_result_t& o) const + { + return !(*this == o); + } + + template + bool operator == (const hb_result_ok_t& o) const + { + return is_ok_ && val_ == o.value; + } + + template + bool operator != (const hb_result_ok_t& o) const + { + return !(*this == o); + } + + template + bool operator == (const hb_result_err_t& e) const + { + return !is_ok_ && err_ == e.error; + } + + template + bool operator != (const hb_result_err_t& e) const + { + return !(*this == e); + } + + template + bool operator == (const U&) const = delete; + + template + bool operator != (const U&) const = delete; +}; + +// Partial specialization for void +template +struct HB_NODISCARD_STRUCT hb_result_t +{ + private: + union + { + E err_; + }; + bool is_ok_; + + template friend struct hb_result_t; + + public: + ~hb_result_t () + { + if (!is_ok_) + err_.~E (); + } + + hb_result_t () : is_ok_ (true) {} + hb_result_t (hb_result_ok_t) : is_ok_ (true) {} + + hb_result_t (const hb_result_t& o) : is_ok_ (o.is_ok_) + { + if (!is_ok_) + new (std::addressof (err_)) E (o.err_); + } + + hb_result_t (hb_result_t&& o) noexcept (std::is_nothrow_move_constructible::value) + : is_ok_ (o.is_ok_) + { + if (!is_ok_) + new (std::addressof (err_)) E (std::move (o.err_)); + } + + hb_result_t& operator = (const hb_result_t& o) + { + if (this == &o) return *this; + if (!is_ok_ && !o.is_ok_) + { + err_ = o.err_; + } + else if (!is_ok_ && o.is_ok_) + { + err_.~E (); + is_ok_ = true; + } + else if (is_ok_ && !o.is_ok_) + { + new (std::addressof (err_)) E (o.err_); + is_ok_ = false; + } + return *this; + } + + hb_result_t& operator = (hb_result_t&& o) noexcept (std::is_nothrow_move_assignable::value) + { + if (this == &o) return *this; + if (!is_ok_ && !o.is_ok_) + { + err_ = std::move (o.err_); + } + else if (!is_ok_ && o.is_ok_) + { + err_.~E (); + is_ok_ = true; + } + else if (is_ok_ && !o.is_ok_) + { + new (std::addressof (err_)) E (std::move (o.err_)); + is_ok_ = false; + } + return *this; + } + + template ::value))> + hb_result_t (hb_result_err_t&& e) : is_ok_ (false) + { + new (std::addressof (err_)) E (std::move (e.error)); + } + + template ::value))> + hb_result_t (const hb_result_err_t& e) : is_ok_ (false) + { + new (std::addressof (err_)) E (e.error); + } + + // Construct directly from error E + hb_result_t (E e) : is_ok_ (false) + { + new (std::addressof (err_)) E (std::move(e)); + } + + // V is any class which has an in_error() method. This checks the result + // of in_error() and returns either Ok() or Err(error_value). + template + static hb_result_t from (const V& fallible, E error_value) { + if (fallible.in_error()) { + return Err(error_value); + } + return Ok(); + } + + bool is_ok () const { return is_ok_; } + bool is_err () const { return !is_ok_; } + explicit operator bool () const { return is_ok (); } + + const E& error () const & { assert (!is_ok_); return err_; } + E& error () & { assert (!is_ok_); return err_; } + E error () && { assert (!is_ok_); return std::move (err_); } + + void operator * () & { return; } + void operator * () const & { return; } + void operator * () && { return; } + + bool operator == (const hb_result_t& o) const + { + return is_ok_ == o.is_ok_ && (is_ok_ || err_ == o.err_); + } + + bool operator != (const hb_result_t& o) const + { + return !(*this == o); + } + + bool operator == (hb_result_ok_t) const + { + return is_ok_; + } + + bool operator != (hb_result_ok_t) const + { + return !is_ok_; + } + + template + bool operator == (const hb_result_err_t& e) const + { + return !is_ok_ && err_ == e.error; + } + + template + bool operator != (const hb_result_err_t& e) const + { + return !(*this == e); + } + + template + bool operator == (const U&) const = delete; + + template + bool operator != (const U&) const = delete; +}; + +template +static inline bool operator == (const hb_result_ok_t& o, const hb_result_t& r) +{ + return r == o; +} +template +static inline bool operator != (const hb_result_ok_t& o, const hb_result_t& r) +{ + return r != o; +} +template +static inline bool operator == (const hb_result_err_t& e, const hb_result_t& r) +{ + return r == e; +} +template +static inline bool operator != (const hb_result_err_t& e, const hb_result_t& r) +{ + return r != e; +} + +#ifndef TRY +#define TRY(expr) \ + do { \ + auto _res = (expr); \ + if (unlikely (!_res.is_ok())) return Err(std::move(_res).error()); \ + } while (0) +#endif + +#ifndef TRY_ASSIGN +#define TRY_ASSIGN(var, ...) \ + auto HB_PASTE(_res_, __LINE__) = (__VA_ARGS__); \ + if (unlikely (!HB_PASTE(_res_, __LINE__).is_ok())) return Err(std::move(HB_PASTE(_res_, __LINE__)).error()); \ + var = *std::move(HB_PASTE(_res_, __LINE__)) +#endif + +#endif /* HB_RESULT_HH */ diff --git a/src/hb-serialize.hh b/src/hb-serialize.hh index fd91784de..7b2bbb59f 100644 --- a/src/hb-serialize.hh +++ b/src/hb-serialize.hh @@ -87,6 +87,11 @@ struct hb_serialize_context_t virtual_links.push (o.virtual_links[i]); } + bool in_error () const + { + return real_links.in_error() || virtual_links.in_error(); + } + bool add_virtual_link (objidx_t objidx) { if (!objidx) diff --git a/src/hb-set.cc b/src/hb-set.cc index 0f3ae7f05..7488546d0 100644 --- a/src/hb-set.cc +++ b/src/hb-set.cc @@ -366,7 +366,7 @@ hb_set_is_equal (const hb_set_t *set, * * Return value: `true` if the two sets intersect, `false` otherwise. * - * XSince: REPLACEME + * Since: 14.4.0 **/ hb_bool_t hb_set_intersects (const hb_set_t *set, diff --git a/src/hb-subset-plan.hh b/src/hb-subset-plan.hh index a84a305fe..0111f15e3 100644 --- a/src/hb-subset-plan.hh +++ b/src/hb-subset-plan.hh @@ -181,8 +181,8 @@ struct hb_subset_plan_t os2_info_t os2_info; - const hb_subset_accelerator_t* accelerator; - hb_subset_accelerator_t* inprogress_accelerator; + const hb_subset_accelerator_t* accelerator = nullptr; + hb_subset_accelerator_t* inprogress_accelerator = nullptr; public: diff --git a/src/hb-unicode.hh b/src/hb-unicode.hh index 485f3f527..4509b5202 100644 --- a/src/hb-unicode.hh +++ b/src/hb-unicode.hh @@ -176,7 +176,7 @@ HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS_SIMPLE case 0x03: return unlikely (ch == 0x034Fu); case 0x06: return unlikely (ch == 0x061Cu); case 0x17: return hb_in_range (ch, 0x17B4u, 0x17B5u); - case 0x18: return hb_in_range (ch, 0x180Bu, 0x180Eu); + case 0x18: return hb_in_range (ch, 0x180Bu, 0x180Fu); case 0x20: return hb_in_ranges (ch, 0x200Bu, 0x200Fu, 0x202Au, 0x202Eu, 0x2060u, 0x206Fu); diff --git a/src/hb-vector-buf.hh b/src/hb-vector-buf.hh index 5624cd181..41404eb3a 100644 --- a/src/hb-vector-buf.hh +++ b/src/hb-vector-buf.hh @@ -28,6 +28,7 @@ #define HB_VECTOR_BUF_HH #include "hb.hh" +#include "hb-limits.hh" #include "hb-vector.hh" #include #include @@ -43,11 +44,47 @@ struct hb_vector_buf_t : hb_vector_t { unsigned precision = 2; + /* Sticky flag set once the serialized document would exceed + * HB_VECTOR_MAX_DOCUMENT_SIZE. Folded into in_error() so every emission + * site that already checks it -- path commands, gradient meshes -- stops + * cleanly. Bounds output that the outline work budget cannot see, most + * importantly sweep-gradient meshes and embedded bitmaps. */ + bool overflowed = false; + + /* Hides (does not override -- the base method is not virtual) the base + * in_error(); every emission site uses hb_vector_buf_t directly, so the + * cap is seen everywhere. clear() resets the sticky flag so a context + * reused across renders recovers after one over-cap glyph. */ + bool in_error () const + { return hb_vector_t::in_error () || overflowed; } + + void clear () + { + overflowed = false; + hb_vector_t::clear (); + } + unsigned scale_precision () const { return precision < 7 ? 7 : precision; } + bool would_overflow (unsigned add) + { + if (unlikely (in_error ())) + return true; + unsigned new_len; + if (unlikely (hb_unsigned_add_overflows (length, add, &new_len) || + new_len > HB_VECTOR_MAX_DOCUMENT_SIZE)) + { + overflowed = true; + return true; + } + return false; + } + bool append_len (const char *s, unsigned l) { + if (unlikely (would_overflow (l))) + return false; unsigned old_len = length; unsigned new_len; if (unlikely (hb_unsigned_add_overflows (old_len, l, &new_len) || @@ -58,7 +95,11 @@ struct hb_vector_buf_t : hb_vector_t } bool append_c (char ch) - { return push_or_fail (ch); } + { + if (unlikely (would_overflow (1))) + return false; + return push_or_fail (ch); + } bool append_str (const char *s) { return append_len (s, (unsigned) strlen (s)); } @@ -206,6 +247,7 @@ struct hb_vector_buf_t : hb_vector_t unsigned old_len = length; unsigned new_len; if (unlikely (hb_unsigned_mul_overflows (ngroups, 4, &out_len) || + would_overflow (out_len) || hb_unsigned_add_overflows (old_len, out_len, &new_len) || !resize_dirty ((int) new_len))) return false; diff --git a/src/hb-vector-draw.cc b/src/hb-vector-draw.cc index 5208fdcf5..4884d1337 100644 --- a/src/hb-vector-draw.cc +++ b/src/hb-vector-draw.cc @@ -51,46 +51,41 @@ hb_vector_svg_buffer_contains (const hb_vector_buf_t &buf, const char *needle) static void hb_vector_draw_svg_move_to (hb_draw_funcs_t *, void *dd, hb_draw_state_t *, float x, float y, void *) { auto *d = (hb_vector_draw_t *) dd; - unsigned before; - if (unlikely (!d->begin_path_command (&before))) return; + if (unlikely (!d->begin_path_command ())) return; d->path.append_c ('M'); d->append_xy_svg (x, y); - d->end_path_command (before); + d->end_path_command (); } static void hb_vector_draw_svg_line_to (hb_draw_funcs_t *, void *dd, hb_draw_state_t *, float x, float y, void *) { auto *d = (hb_vector_draw_t *) dd; - unsigned before; - if (unlikely (!d->begin_path_command (&before))) return; + if (unlikely (!d->begin_path_command ())) return; d->path.append_c ('L'); d->append_xy_svg (x, y); - d->end_path_command (before); + d->end_path_command (); } static void hb_vector_draw_svg_quadratic_to (hb_draw_funcs_t *, void *dd, hb_draw_state_t *, float cx, float cy, float x, float y, void *) { auto *d = (hb_vector_draw_t *) dd; - unsigned before; - if (unlikely (!d->begin_path_command (&before))) return; + if (unlikely (!d->begin_path_command ())) return; d->path.append_c ('Q'); d->append_xy_svg (cx, cy); d->path.append_c (' '); d->append_xy_svg (x, y); - d->end_path_command (before); + d->end_path_command (); } static void hb_vector_draw_svg_cubic_to (hb_draw_funcs_t *, void *dd, hb_draw_state_t *, float c1x, float c1y, float c2x, float c2y, float x, float y, void *) { auto *d = (hb_vector_draw_t *) dd; - unsigned before; - if (unlikely (!d->begin_path_command (&before))) return; + if (unlikely (!d->begin_path_command ())) return; d->path.append_c ('C'); d->append_xy_svg (c1x, c1y); d->path.append_c (' '); d->append_xy_svg (c2x, c2y); d->path.append_c (' '); d->append_xy_svg (x, y); - d->end_path_command (before); + d->end_path_command (); } static void hb_vector_draw_svg_close_path (hb_draw_funcs_t *, void *dd, hb_draw_state_t *, void *) { auto *d = (hb_vector_draw_t *) dd; - unsigned before; - if (unlikely (!d->begin_path_command (&before))) return; + if (unlikely (!d->begin_path_command ())) return; d->path.append_c ('Z'); - d->end_path_command (before); + d->end_path_command (); } @@ -99,19 +94,17 @@ static void hb_vector_draw_svg_close_path (hb_draw_funcs_t *, void *dd, hb_draw_ static void hb_vector_draw_pdf_move_to (hb_draw_funcs_t *, void *dd, hb_draw_state_t *, float x, float y, void *) { auto *d = (hb_vector_draw_t *) dd; - unsigned before; - if (unlikely (!d->begin_path_command (&before))) return; + if (unlikely (!d->begin_path_command ())) return; d->append_xy_pdf (x, y); d->path.append_str (" m\n"); - d->end_path_command (before); + d->end_path_command (); } static void hb_vector_draw_pdf_line_to (hb_draw_funcs_t *, void *dd, hb_draw_state_t *, float x, float y, void *) { auto *d = (hb_vector_draw_t *) dd; - unsigned before; - if (unlikely (!d->begin_path_command (&before))) return; + if (unlikely (!d->begin_path_command ())) return; d->append_xy_pdf (x, y); d->path.append_str (" l\n"); - d->end_path_command (before); + d->end_path_command (); } /* No quadratic_to — null fallback auto-promotes to cubic. */ @@ -119,19 +112,39 @@ static void hb_vector_draw_pdf_line_to (hb_draw_funcs_t *, void *dd, hb_draw_sta static void hb_vector_draw_pdf_cubic_to (hb_draw_funcs_t *, void *dd, hb_draw_state_t *, float c1x, float c1y, float c2x, float c2y, float x, float y, void *) { auto *d = (hb_vector_draw_t *) dd; - unsigned before; - if (unlikely (!d->begin_path_command (&before))) return; + if (unlikely (!d->begin_path_command ())) return; d->append_xy_pdf (c1x, c1y); d->path.append_c (' '); d->append_xy_pdf (c2x, c2y); d->path.append_c (' '); d->append_xy_pdf (x, y); d->path.append_str (" c\n"); - d->end_path_command (before); + d->end_path_command (); } static void hb_vector_draw_pdf_close_path (hb_draw_funcs_t *, void *dd, hb_draw_state_t *, void *) { auto *d = (hb_vector_draw_t *) dd; - unsigned before; - if (unlikely (!d->begin_path_command (&before))) return; + if (unlikely (!d->begin_path_command ())) return; d->path.append_str ("h\n"); - d->end_path_command (before); + d->end_path_command (); +} + +static hb_bool_t +hb_vector_draw_set_budget (hb_draw_funcs_t *, void *draw_data, + int64_t budget, void *) +{ + auto *draw = (hb_vector_draw_t *) draw_data; + draw->budget = budget; + draw->recharge_budget (); + return true; +} + +static int64_t +hb_vector_draw_get_budget (hb_draw_funcs_t *, void *draw_data, void *) +{ + return ((hb_vector_draw_t *) draw_data)->budget; +} + +static int64_t * +hb_vector_draw_get_budget_remaining (hb_draw_funcs_t *, void *draw_data, void *) +{ + return &((hb_vector_draw_t *) draw_data)->budget_remaining; } @@ -149,6 +162,9 @@ static struct hb_vector_draw_svg_funcs_lazy_loader_t hb_draw_funcs_set_quadratic_to_func (funcs, (hb_draw_quadratic_to_func_t) hb_vector_draw_svg_quadratic_to, nullptr, nullptr); hb_draw_funcs_set_cubic_to_func (funcs, (hb_draw_cubic_to_func_t) hb_vector_draw_svg_cubic_to, nullptr, nullptr); hb_draw_funcs_set_close_path_func (funcs, (hb_draw_close_path_func_t) hb_vector_draw_svg_close_path, nullptr, nullptr); + hb_draw_funcs_set_set_budget_func (funcs, hb_vector_draw_set_budget, nullptr, nullptr); + hb_draw_funcs_set_get_budget_func (funcs, hb_vector_draw_get_budget, nullptr, nullptr); + hb_draw_funcs_set_get_budget_remaining_func (funcs, hb_vector_draw_get_budget_remaining, nullptr, nullptr); hb_draw_funcs_make_immutable (funcs); hb_atexit (free_static_vector_draw_svg_funcs); return funcs; @@ -168,6 +184,9 @@ static struct hb_vector_draw_pdf_funcs_lazy_loader_t /* No quadratic_to: null fallback auto-promotes to cubic. */ hb_draw_funcs_set_cubic_to_func (funcs, (hb_draw_cubic_to_func_t) hb_vector_draw_pdf_cubic_to, nullptr, nullptr); hb_draw_funcs_set_close_path_func (funcs, (hb_draw_close_path_func_t) hb_vector_draw_pdf_close_path, nullptr, nullptr); + hb_draw_funcs_set_set_budget_func (funcs, hb_vector_draw_set_budget, nullptr, nullptr); + hb_draw_funcs_set_get_budget_func (funcs, hb_vector_draw_get_budget, nullptr, nullptr); + hb_draw_funcs_set_get_budget_remaining_func (funcs, hb_vector_draw_get_budget_remaining, nullptr, nullptr); hb_draw_funcs_make_immutable (funcs); hb_atexit (free_static_vector_draw_pdf_funcs); return funcs; @@ -949,7 +968,7 @@ hb_vector_draw_clear (hb_vector_draw_t *draw) draw->defs.clear (); draw->body.clear (); draw->path.clear (); - draw->work_left = HB_VECTOR_MAX_DRAW_WORK; + draw->recharge_budget (); } /** @@ -967,6 +986,7 @@ hb_vector_draw_reset (hb_vector_draw_t *draw) draw->x_scale_factor = 1.f; draw->y_scale_factor = 1.f; draw->set_precision (2); + draw->budget = HB_BUDGET_DEFAULT; hb_vector_draw_clear (draw); } diff --git a/src/hb-vector-draw.hh b/src/hb-vector-draw.hh index 6f21a32bd..9035e3ece 100644 --- a/src/hb-vector-draw.hh +++ b/src/hb-vector-draw.hh @@ -54,25 +54,30 @@ struct hb_vector_draw_t hb_vector_buf_t pdf_extgstate_dict; unsigned pdf_extgstate_count = 0; - /* Cumulative output budget for the current draw session; reset by - * hb_vector_draw_clear(). Charge complete path commands so budget - * exhaustion cannot leave a syntactically partial command. */ - int64_t work_left = HB_VECTOR_MAX_DRAW_WORK; + /* Cumulative work budget for the current draw session; reset by + * hb_vector_draw_clear(). Outline traversal and complete path commands + * charge the same live counter. */ + int64_t budget = HB_BUDGET_DEFAULT; + int64_t budget_remaining = HB_BUDGET_GLYPH; - bool begin_path_command (unsigned *before) + void recharge_budget () { - if (unlikely (work_left <= 0 || path.in_error ())) - return false; - *before = path.length; - return true; + budget_remaining = budget == HB_BUDGET_DEFAULT ? + HB_BUDGET_GLYPH : budget; } - void end_path_command (unsigned before) + bool begin_path_command () { + return likely (budget_remaining >= 0 && !path.in_error ()); + } + + void end_path_command () + { + /* The serialized bytes are bounded by the output buffer's document-size + * cap (in_error), not the outline work budget; stop outline traversal + * once that cap or an allocation error trips. */ if (unlikely (path.in_error ())) - work_left = 0; - else - work_left -= path.length - before; + budget_remaining = 0; } void set_precision (unsigned p) diff --git a/src/hb-vector-paint-pdf.cc b/src/hb-vector-paint-pdf.cc index 69a522c86..bf13eb8f0 100644 --- a/src/hb-vector-paint-pdf.cc +++ b/src/hb-vector-paint-pdf.cc @@ -342,11 +342,11 @@ hb_pdf_emit_glyph_path (hb_vector_paint_t *paint, paint->path.clear (); /* Skip the outline extraction when the session work budget is * spent; an empty path keeps the document structure intact. */ - if (likely (paint->work_left > 0)) + if (likely (paint->budget_remaining >= 0)) { hb_vector_path_sink_t sink = {&paint->path, paint->get_precision (), paint->x_scale_factor, paint->y_scale_factor, - &paint->work_left}; + &paint->budget_remaining}; hb_font_draw_glyph (font, glyph, hb_vector_pdf_path_draw_funcs_get (), &sink); @@ -512,7 +512,7 @@ hb_pdf_paint_push_clip_path_start (hb_paint_funcs_t *, paint->clip_path_sink = {&body, paint->get_precision (), paint->x_scale_factor, paint->y_scale_factor, - &paint->work_left}; + &paint->budget_remaining}; *draw_data = &paint->clip_path_sink; return hb_vector_pdf_path_draw_funcs_get (); } @@ -1376,7 +1376,6 @@ hb_pdf_add_sweep_patch (hb_vector_buf_t *mesh, /* Callback context + trampoline for hb_paint_sweep_gradient_tiles. */ struct hb_pdf_sweep_ctx_t { - hb_vector_paint_t *paint; hb_vector_buf_t *mesh; hb_vector_buf_t *alpha_mesh; float cx, cy, xlo, xhi, ylo, yhi; @@ -1388,21 +1387,17 @@ hb_pdf_sweep_emit_patch (float a0, hb_color_t c0, void *user_data) { auto *ctx = (hb_pdf_sweep_ctx_t *) user_data; - auto *paint = ctx->paint; - /* Skip patch generation when the session work budget is spent, so - * per-gradient patch counts cannot multiply with the paint-graph - * traversal limits of the font tables driving us. */ - if (unlikely (paint->work_left <= 0)) + /* Sweep-gradient meshes are not outline-derived, so they are bounded by + * the output document-size cap, not the outline work budget: stop once a + * mesh buffer trips its cap so per-gradient patch counts cannot multiply + * with the paint-graph traversal limits of the font tables driving us. */ + if (unlikely (ctx->mesh->in_error () || + (ctx->alpha_mesh && ctx->alpha_mesh->in_error ()))) return; - unsigned before = ctx->mesh->length + - (ctx->alpha_mesh ? ctx->alpha_mesh->length : 0); hb_pdf_add_sweep_patch (ctx->mesh, ctx->alpha_mesh, ctx->cx, ctx->cy, ctx->xlo, ctx->xhi, ctx->ylo, ctx->yhi, a0, c0, a1, c1); - unsigned after = ctx->mesh->length + - (ctx->alpha_mesh ? ctx->alpha_mesh->length : 0); - paint->work_left -= after - before; } static void @@ -1444,7 +1439,7 @@ hb_pdf_paint_sweep_gradient (hb_paint_funcs_t *, if (needs_alpha) alpha_mesh.alloc (256); - hb_pdf_sweep_ctx_t ctx { paint, &mesh, needs_alpha ? &alpha_mesh : nullptr, + hb_pdf_sweep_ctx_t ctx { &mesh, needs_alpha ? &alpha_mesh : nullptr, scx, scy, xlo, xhi, ylo, yhi }; hb_paint_sweep_gradient_tiles (stops.arrayZ, stops.length, extend, start_angle, end_angle, @@ -1619,6 +1614,9 @@ static struct hb_pdf_paint_funcs_lazy_loader_t hb_paint_funcs_set_push_group_func (funcs, (hb_paint_push_group_func_t) hb_pdf_paint_push_group, nullptr, nullptr); hb_paint_funcs_set_push_group_for_func (funcs, (hb_paint_push_group_for_func_t) hb_pdf_paint_push_group_for, nullptr, nullptr); hb_paint_funcs_set_pop_group_func (funcs, (hb_paint_pop_group_func_t) hb_pdf_paint_pop_group, nullptr, nullptr); + hb_paint_funcs_set_set_budget_func (funcs, hb_vector_paint_set_budget_callback, nullptr, nullptr); + hb_paint_funcs_set_get_budget_func (funcs, hb_vector_paint_get_budget_callback, nullptr, nullptr); + hb_paint_funcs_set_get_budget_remaining_func (funcs, hb_vector_paint_get_budget_remaining_callback, nullptr, nullptr); hb_paint_funcs_make_immutable (funcs); hb_atexit (free_static_pdf_paint_funcs); return funcs; diff --git a/src/hb-vector-paint-svg.cc b/src/hb-vector-paint-svg.cc index e8b9f4456..67fc396ba 100644 --- a/src/hb-vector-paint-svg.cc +++ b/src/hb-vector-paint-svg.cc @@ -246,7 +246,6 @@ hb_vector_svg_add_sweep_patch (hb_vector_buf_t *body, /* Callback context + trampoline for hb_paint_sweep_gradient_tiles. */ struct hb_vector_svg_sweep_ctx_t { - hb_vector_paint_t *paint; hb_vector_buf_t *body; unsigned precision; float cx, cy, radius; @@ -258,18 +257,16 @@ hb_vector_svg_sweep_emit_patch (float a0, hb_color_t c0, void *user_data) { auto *ctx = (hb_vector_svg_sweep_ctx_t *) user_data; - auto *paint = ctx->paint; - /* Skip patch generation when the session work budget is spent, so - * per-gradient patch counts cannot multiply with the paint-graph - * traversal limits of the font tables driving us. */ - if (unlikely (paint->work_left <= 0)) + /* Sweep-gradient meshes are not outline-derived, so they are bounded by + * the output document-size cap, not the outline work budget: stop once + * the buffer trips its cap so per-gradient patch counts cannot multiply + * with the paint-graph traversal limits of the font tables driving us. */ + if (unlikely (ctx->body->in_error ())) return; - unsigned before = ctx->body->length; hb_vector_svg_add_sweep_patch (ctx->body, ctx->precision, ctx->cx, ctx->cy, ctx->radius, a0, hb_vector_svg_rgba_from_hb_color (c0), a1, hb_vector_svg_rgba_from_hb_color (c1)); - paint->work_left -= ctx->body->length - before; } @@ -333,6 +330,9 @@ static struct hb_vector_paint_funcs_lazy_loader_t hb_paint_funcs_set_pop_group_func (funcs, (hb_paint_pop_group_func_t) hb_vector_paint_pop_group, nullptr, nullptr); hb_paint_funcs_set_color_glyph_func (funcs, (hb_paint_color_glyph_func_t) hb_vector_paint_color_glyph, nullptr, nullptr); hb_paint_funcs_set_custom_palette_color_func (funcs, (hb_paint_custom_palette_color_func_t) hb_vector_paint_custom_palette_color, nullptr, nullptr); + hb_paint_funcs_set_set_budget_func (funcs, hb_vector_paint_set_budget_callback, nullptr, nullptr); + hb_paint_funcs_set_get_budget_func (funcs, hb_vector_paint_get_budget_callback, nullptr, nullptr); + hb_paint_funcs_set_get_budget_remaining_func (funcs, hb_vector_paint_get_budget_remaining_callback, nullptr, nullptr); hb_paint_funcs_make_immutable (funcs); hb_atexit (free_static_vector_paint_funcs); return funcs; @@ -440,11 +440,11 @@ hb_vector_paint_fill_glyph (hb_paint_funcs_t *, paint->path.clear (); /* Skip the outline extraction when the session work budget is * spent; an empty path keeps the document structure intact. */ - if (likely (paint->work_left > 0)) + if (likely (paint->budget_remaining >= 0)) { hb_vector_path_sink_t sink = {&paint->path, paint->get_precision (), paint->x_scale_factor, paint->y_scale_factor, - &paint->work_left}; + &paint->budget_remaining}; hb_font_draw_glyph (font, glyph, hb_vector_svg_path_draw_funcs_get (), &sink); } @@ -473,11 +473,11 @@ hb_vector_paint_push_clip_glyph (hb_paint_funcs_t *, paint->path.clear (); /* Skip the outline extraction when the session work budget is * spent; an empty clip path clips everything out. */ - if (likely (paint->work_left > 0)) + if (likely (paint->budget_remaining >= 0)) { hb_vector_path_sink_t sink = {&paint->path, paint->get_precision (), paint->x_scale_factor, paint->y_scale_factor, - &paint->work_left}; + &paint->budget_remaining}; hb_font_draw_glyph (font, glyph, hb_vector_svg_path_draw_funcs_get (), &sink); } @@ -558,7 +558,7 @@ hb_vector_paint_push_clip_path_start (hb_paint_funcs_t *, paint->clip_path_sink = {&paint->path, paint->get_precision (), paint->x_scale_factor, paint->y_scale_factor, - &paint->work_left}; + &paint->budget_remaining}; *draw_data = &paint->clip_path_sink; return hb_vector_svg_path_draw_funcs_get (); } @@ -829,7 +829,7 @@ hb_vector_paint_sweep_gradient (hb_paint_funcs_t *, float ga1 = start_angle + mx * (end_angle - start_angle); hb_vector_svg_sweep_ctx_t ctx { - paint, &paint->current_body (), paint->get_precision (), paint->sx (cx), paint->sy (cy), 32767.f + &paint->current_body (), paint->get_precision (), paint->sx (cx), paint->sy (cy), 32767.f }; hb_paint_sweep_gradient_tiles (stops.arrayZ, stops.length, hb_color_line_get_extend (color_line), diff --git a/src/hb-vector-paint.cc b/src/hb-vector-paint.cc index 92a1de35a..227a329ba 100644 --- a/src/hb-vector-paint.cc +++ b/src/hb-vector-paint.cc @@ -744,7 +744,7 @@ hb_vector_paint_clear (hb_vector_paint_t *paint) paint->transform_group_overflow_depth = 0; paint->clip_rect_counter = 0; paint->clip_path_counter = 0; - paint->work_left = HB_VECTOR_MAX_PAINT_WORK; + paint->recharge_budget (); paint->gradient_counter = 0; paint->color_glyph_depth = 0; paint->path_def_count = 0; @@ -797,6 +797,7 @@ hb_vector_paint_reset (hb_vector_paint_t *paint) paint->foreground = HB_COLOR (0, 0, 0, 255); paint->palette = 0; paint->set_precision (2); + paint->budget = HB_BUDGET_DEFAULT; hb_vector_paint_clear (paint); } diff --git a/src/hb-vector-paint.hh b/src/hb-vector-paint.hh index fecb4a0a3..d38301380 100644 --- a/src/hb-vector-paint.hh +++ b/src/hb-vector-paint.hh @@ -67,11 +67,12 @@ struct hb_vector_paint_t unsigned clip_path_counter = 0; /* Cumulative work budget for the current paint session; reset by * hb_vector_paint_clear(). Charged with the bytes of path data - * generated by each glyph-outline extraction and of sweep-gradient - * patch data, so per-glyph and per-gradient limits cannot multiply - * with the paint-graph traversal limits of the font tables driving - * us (e.g. COLR). */ - int64_t work_left = HB_VECTOR_MAX_PAINT_WORK; + * generated by each glyph-outline extraction, outline traversal, and + * sweep-gradient patch data, so per-glyph and per-gradient limits cannot + * multiply with the paint-graph traversal limits of the font tables + * driving us (e.g. COLR). */ + int64_t budget = HB_BUDGET_DEFAULT; + int64_t budget_remaining = HB_BUDGET_GLYPH; hb_vector_path_sink_t clip_path_sink = {nullptr, 0, 1.f, 1.f, nullptr}; unsigned gradient_counter = 0; unsigned color_glyph_depth = 0; @@ -83,6 +84,12 @@ struct hb_vector_paint_t hb_vector_buf_t ¤t_body () { return group_stack.tail (); } + void recharge_budget () + { + budget_remaining = budget == HB_BUDGET_DEFAULT ? + HB_BUDGET_GLYPH : budget; + } + float sx (float v) const { return v / x_scale_factor; } float sy (float v) const { return v / y_scale_factor; } @@ -124,6 +131,29 @@ struct hb_vector_paint_t } }; +static inline hb_bool_t +hb_vector_paint_set_budget_callback (hb_paint_funcs_t *, void *paint_data, + int64_t budget, void *) +{ + auto *paint = (hb_vector_paint_t *) paint_data; + paint->budget = budget; + paint->recharge_budget (); + return true; +} + +static inline int64_t +hb_vector_paint_get_budget_callback (hb_paint_funcs_t *, void *paint_data, void *) +{ + return ((hb_vector_paint_t *) paint_data)->budget; +} + +static inline int64_t * +hb_vector_paint_get_budget_remaining_callback (hb_paint_funcs_t *, + void *paint_data, void *) +{ + return &((hb_vector_paint_t *) paint_data)->budget_remaining; +} + /* Implemented in hb-vector-paint-svg.cc */ HB_INTERNAL hb_paint_funcs_t * hb_vector_paint_svg_funcs_get (); HB_INTERNAL hb_blob_t * hb_vector_paint_render_svg (hb_vector_paint_t *paint); diff --git a/src/hb-vector-path.cc b/src/hb-vector-path.cc index db66e12a7..79dc6e5f0 100644 --- a/src/hb-vector-path.cc +++ b/src/hb-vector-path.cc @@ -48,11 +48,10 @@ hb_vector_svg_path_move_to (hb_draw_funcs_t *, void *draw_data, hb_draw_state_t float to_x, float to_y, void *) { auto *s = (hb_vector_path_sink_t *) draw_data; - unsigned before; - if (unlikely (!s->begin_command (&before))) return; + if (unlikely (!s->begin_command ())) return; s->path->append_c ('M'); hb_vector_svg_path_append_xy (s, to_x, to_y); - s->end_command (before); + s->end_command (); } static void @@ -60,11 +59,10 @@ hb_vector_svg_path_line_to (hb_draw_funcs_t *, void *draw_data, hb_draw_state_t float to_x, float to_y, void *) { auto *s = (hb_vector_path_sink_t *) draw_data; - unsigned before; - if (unlikely (!s->begin_command (&before))) return; + if (unlikely (!s->begin_command ())) return; s->path->append_c ('L'); hb_vector_svg_path_append_xy (s, to_x, to_y); - s->end_command (before); + s->end_command (); } static void @@ -72,13 +70,12 @@ hb_vector_svg_path_quadratic_to (hb_draw_funcs_t *, void *draw_data, hb_draw_sta float cx, float cy, float to_x, float to_y, void *) { auto *s = (hb_vector_path_sink_t *) draw_data; - unsigned before; - if (unlikely (!s->begin_command (&before))) return; + if (unlikely (!s->begin_command ())) return; s->path->append_c ('Q'); hb_vector_svg_path_append_xy (s, cx, cy); s->path->append_c (' '); hb_vector_svg_path_append_xy (s, to_x, to_y); - s->end_command (before); + s->end_command (); } static void @@ -87,25 +84,23 @@ hb_vector_svg_path_cubic_to (hb_draw_funcs_t *, void *draw_data, hb_draw_state_t float to_x, float to_y, void *) { auto *s = (hb_vector_path_sink_t *) draw_data; - unsigned before; - if (unlikely (!s->begin_command (&before))) return; + if (unlikely (!s->begin_command ())) return; s->path->append_c ('C'); hb_vector_svg_path_append_xy (s, c1x, c1y); s->path->append_c (' '); hb_vector_svg_path_append_xy (s, c2x, c2y); s->path->append_c (' '); hb_vector_svg_path_append_xy (s, to_x, to_y); - s->end_command (before); + s->end_command (); } static void hb_vector_svg_path_close_path (hb_draw_funcs_t *, void *draw_data, hb_draw_state_t *, void *) { auto *s = (hb_vector_path_sink_t *) draw_data; - unsigned before; - if (unlikely (!s->begin_command (&before))) return; + if (unlikely (!s->begin_command ())) return; s->path->append_c ('Z'); - s->end_command (before); + s->end_command (); } @@ -124,11 +119,10 @@ hb_vector_pdf_path_move_to (hb_draw_funcs_t *, void *draw_data, hb_draw_state_t float to_x, float to_y, void *) { auto *s = (hb_vector_path_sink_t *) draw_data; - unsigned before; - if (unlikely (!s->begin_command (&before))) return; + if (unlikely (!s->begin_command ())) return; hb_vector_pdf_path_append_xy (s, to_x, to_y); s->path->append_str (" m\n"); - s->end_command (before); + s->end_command (); } static void @@ -136,11 +130,10 @@ hb_vector_pdf_path_line_to (hb_draw_funcs_t *, void *draw_data, hb_draw_state_t float to_x, float to_y, void *) { auto *s = (hb_vector_path_sink_t *) draw_data; - unsigned before; - if (unlikely (!s->begin_command (&before))) return; + if (unlikely (!s->begin_command ())) return; hb_vector_pdf_path_append_xy (s, to_x, to_y); s->path->append_str (" l\n"); - s->end_command (before); + s->end_command (); } /* No quadratic_to — the null fallback auto-promotes to cubic. */ @@ -151,25 +144,29 @@ hb_vector_pdf_path_cubic_to (hb_draw_funcs_t *, void *draw_data, hb_draw_state_t float to_x, float to_y, void *) { auto *s = (hb_vector_path_sink_t *) draw_data; - unsigned before; - if (unlikely (!s->begin_command (&before))) return; + if (unlikely (!s->begin_command ())) return; hb_vector_pdf_path_append_xy (s, c1x, c1y); s->path->append_c (' '); hb_vector_pdf_path_append_xy (s, c2x, c2y); s->path->append_c (' '); hb_vector_pdf_path_append_xy (s, to_x, to_y); s->path->append_str (" c\n"); - s->end_command (before); + s->end_command (); } static void hb_vector_pdf_path_close_path (hb_draw_funcs_t *, void *draw_data, hb_draw_state_t *, void *) { auto *s = (hb_vector_path_sink_t *) draw_data; - unsigned before; - if (unlikely (!s->begin_command (&before))) return; + if (unlikely (!s->begin_command ())) return; s->path->append_str ("h\n"); - s->end_command (before); + s->end_command (); +} + +static int64_t * +hb_vector_path_get_budget_remaining (hb_draw_funcs_t *, void *draw_data, void *) +{ + return ((hb_vector_path_sink_t *) draw_data)->budget; } @@ -187,6 +184,7 @@ static struct hb_vector_svg_path_draw_funcs_lazy_loader_t hb_draw_funcs_set_quadratic_to_func (funcs, (hb_draw_quadratic_to_func_t) hb_vector_svg_path_quadratic_to, nullptr, nullptr); hb_draw_funcs_set_cubic_to_func (funcs, (hb_draw_cubic_to_func_t) hb_vector_svg_path_cubic_to, nullptr, nullptr); hb_draw_funcs_set_close_path_func (funcs, (hb_draw_close_path_func_t) hb_vector_svg_path_close_path, nullptr, nullptr); + hb_draw_funcs_set_get_budget_remaining_func (funcs, hb_vector_path_get_budget_remaining, nullptr, nullptr); hb_draw_funcs_make_immutable (funcs); hb_atexit (free_static_vector_svg_path_draw_funcs); return funcs; @@ -214,6 +212,7 @@ static struct hb_vector_pdf_path_draw_funcs_lazy_loader_t /* No quadratic_to: the null fallback auto-promotes to cubic. */ hb_draw_funcs_set_cubic_to_func (funcs, (hb_draw_cubic_to_func_t) hb_vector_pdf_path_cubic_to, nullptr, nullptr); hb_draw_funcs_set_close_path_func (funcs, (hb_draw_close_path_func_t) hb_vector_pdf_path_close_path, nullptr, nullptr); + hb_draw_funcs_set_get_budget_remaining_func (funcs, hb_vector_path_get_budget_remaining, nullptr, nullptr); hb_draw_funcs_make_immutable (funcs); hb_atexit (free_static_vector_pdf_path_draw_funcs); return funcs; diff --git a/src/hb-vector-path.hh b/src/hb-vector-path.hh index 8618a5b82..eb2c37081 100644 --- a/src/hb-vector-path.hh +++ b/src/hb-vector-path.hh @@ -44,24 +44,21 @@ struct hb_vector_path_sink_t unsigned precision; float x_scale; float y_scale; - int64_t *work_left; + int64_t *budget; - bool begin_command (unsigned *before) + bool begin_command () { - if (unlikely (path->in_error () || - (work_left && *work_left <= 0))) - return false; - *before = path->length; - return true; + return likely (!path->in_error () && !(budget && *budget < 0)); } - void end_command (unsigned before) + void end_command () { - if (!work_left) return; + /* Serialized bytes are bounded by the output buffer's document-size + * cap (in_error), not the outline work budget; stop outline traversal + * once that cap or an allocation error trips. */ + if (!budget) return; if (unlikely (path->in_error ())) - *work_left = 0; - else - *work_left -= path->length - before; + *budget = 0; } }; diff --git a/src/hb-version.h b/src/hb-version.h index 2206ad7b5..10aed6731 100644 --- a/src/hb-version.h +++ b/src/hb-version.h @@ -47,20 +47,20 @@ HB_BEGIN_DECLS * * The minor component of the library version available at compile-time. */ -#define HB_VERSION_MINOR 3 +#define HB_VERSION_MINOR 4 /** * HB_VERSION_MICRO: * * The micro component of the library version available at compile-time. */ -#define HB_VERSION_MICRO 1 +#define HB_VERSION_MICRO 0 /** * HB_VERSION_STRING: * * A string literal containing the library version available at compile-time. */ -#define HB_VERSION_STRING "14.3.1" +#define HB_VERSION_STRING "14.4.0" /** * HB_VERSION_ATLEAST: diff --git a/src/hb.hh b/src/hb.hh index 27f400a8e..6eed97ce0 100644 --- a/src/hb.hh +++ b/src/hb.hh @@ -160,7 +160,6 @@ #include "hb-config.hh" -#include "hb-limits.hh" /* @@ -385,6 +384,13 @@ # define HB_NODISCARD #endif +/* Like HB_NODISCARD but can be used on structs */ +#if __cplusplus >= 201703L +# define HB_NODISCARD_STRUCT [[nodiscard]] +#else +# define HB_NODISCARD_STRUCT +#endif + #ifdef _WIN32 /* We need Windows Vista for both Uniscribe backend and for * MemoryBarrier. We don't support compiling on Windows XP, @@ -557,6 +563,7 @@ extern "C" void hb_free_impl(void *ptr); /* Headers we include for everyone. Keep topologically sorted by dependency. * They express dependency amongst themselves, but no other file should include * them directly.*/ +#include "hb-limits.hh" #include "hb-cplusplus.hh" #include "hb-meta.hh" #include "hb-mutex.hh" diff --git a/src/meson.build b/src/meson.build index 3c33fce78..002d03b39 100644 --- a/src/meson.build +++ b/src/meson.build @@ -394,6 +394,7 @@ hb_subset_sources = files( 'hb-number.hh', 'hb-ot-cff1-table.cc', 'hb-ot-cff2-table.cc', + 'hb-result.hh', 'hb-static.cc', 'hb-subset-accelerator.hh', 'hb-subset-cff-common.cc', @@ -419,6 +420,7 @@ hb_subset_sources = files( 'hb-subset-table-cff.cc', 'hb-subset-table-color.cc', 'hb-subset-table-other.cc', + 'graph/graph-result.hh', 'graph/gsubgpos-context.cc', 'graph/gsubgpos-context.hh', 'graph/gsubgpos-graph.hh', @@ -993,6 +995,7 @@ if get_option('tests').enabled() 'test-bimap': ['test-bimap.cc', 'hb-static.cc'], 'test-cff': ['test-cff.cc', 'hb-static.cc'], 'test-classdef-graph': ['graph/test-classdef-graph.cc', 'hb-static.cc', 'graph/gsubgpos-context.cc'], + 'test-result': ['test-result.cc', 'hb-static.cc'], 'test-decycler': ['test-decycler.cc', 'hb-static.cc'], 'test-iter': ['test-iter.cc', 'hb-static.cc'], 'test-geometry': ['test-geometry.cc', 'hb-static.cc'], @@ -1001,6 +1004,7 @@ if get_option('tests').enabled() 'test-multimap': ['test-multimap.cc', 'hb-static.cc'], 'test-number': ['test-number.cc', 'hb-number.cc'], 'test-ot-tag': ['hb-ot-tag.cc'], + 'test-paint-extents': ['test-paint-extents.cc', 'hb-paint-extents.cc', 'hb-static.cc'], 'test-set': ['test-set.cc', 'hb-static.cc'], 'test-serialize': ['test-serialize.cc', 'hb-static.cc'], 'test-vector': ['test-vector.cc', 'hb-static.cc'], diff --git a/src/ms-use/IndicPositionalCategory-Additional.txt b/src/ms-use/IndicPositionalCategory-Additional.txt index 354e31552..20a161d4b 100644 --- a/src/ms-use/IndicPositionalCategory-Additional.txt +++ b/src/ms-use/IndicPositionalCategory-Additional.txt @@ -10,6 +10,8 @@ # Updated for Unicode 15.0 by Andrew Glass 2022-09-16 # Updated for Unicode 15.1 by Andrew Glass 2023-09-14 # Updated for Unicode 16.0 by Andrew Glass 2024-09-11 +# Updated for Unicode 17.0 by Andrew Glass 2025-09-15 +# Updated for Unicode 18.0 by Andrew Glass 2026-09-04 # ================================================ # ================================================ @@ -54,7 +56,7 @@ AA35   ; Top # Mn       CHAM CONSONANT SIGN AAB4 ; Top # Mn TAI VIET VOWEL U # Override: ccc controls order, USE issue #58 1112A..1112B ; Top # Mn [2] CHAKMA VOWEL SIGN U..CHAKMA VOWEL SIGN UU # see USE issue #25 11131..11132 ; Top # Mn [2] CHAKMA O MARK..CHAKMA AU MARK # see USE issue #25 -1E4EC..1E4EF ; Top # Mn [4] NAG MUNDARI SIGN MUHOR..NAG MUNDARI SIGN SUTUH # 1E4EE is below, but made to for ccc +1E4EC..1E4EF ; Top # Mn [4] NAG MUNDARI SIGN MUHOR..NAG MUNDARI SIGN SUTUH # 1E4EE is below, but made to for ccc # ================================================ @@ -100,7 +102,7 @@ AAB4 ; Top # Mn TAI VIET VOWEL U # Override: ccc controls ord 07EB..07F3 ; Top # Mn [9] NKO COMBINING SHORT HIGH TONE..NKO COMBINING DOUBLE DOT ABOVE 07FD ; Top # Mn NKO DANTAYALAN # Not really top, but assigned here to allow ccc to control mark order 1885..1886 ; Top # Mn [2] MONGOLIAN LETTER ALI GALI BALUDA..MONGOLIAN LETTER ALI GALI THREE BALUDA -1B6C ; Top # Mn BALINESE MUSICAL SYMBOL COMBINING ENDEP +1B6C ; Top # Mn BALINESE MUSICAL SYMBOL COMBINING ENDEP 1CF8..1CF9 ; Top # Mn [2] VEDIC TONE RING ABOVE..VEDIC TONE DOUBLE RING ABOVE 10D24..10D27 ; Top # Mn [4] HANIFI ROHINGYA SIGN HARBAHAY..HANIFI ROHINGYA SIGN TASSI 10EAB..10EAC ; Top # Mn [2] YEZIDI COMBINING HAMZA MARK..YEZIDI COMBINING MADDA MARK diff --git a/src/ms-use/IndicSyllabicCategory-Additional.txt b/src/ms-use/IndicSyllabicCategory-Additional.txt index fcd22e63d..3b46ca2ff 100644 --- a/src/ms-use/IndicSyllabicCategory-Additional.txt +++ b/src/ms-use/IndicSyllabicCategory-Additional.txt @@ -8,12 +8,14 @@ # Updated for Unicode 15.0 by Andrew Glass 2022-09-16 # Updated for Unicode 15.1 by Andrew Glass 2023-09-14 # Updated for Unicode 16.0 by Andrew Glass 2024-09-11 +# Updated for Unicode 17.0 by Andrew Glass 2025-09-15 +# Updated for Unicode 18.0 by Andrew Glass 2026-09-04 # ================================================ # OVERRIDES TO ASSIGNED VALUES # ================================================ -# Indic_Syllabic_Category=Bindu +# Indic_Syllabic_Category=Bindu 193A ; Bindu # Mn LIMBU SIGN KEMPHRENG AA29 ; Bindu # Mn CHAM VOWEL SIGN AA 10A0D ; Bindu # Mn KHAROSHTHI SIGN DOUBLE RING BELOW @@ -32,11 +34,6 @@ AA29 ; Bindu # Mn CHAM VOWEL SIGN AA # ================================================ -# Indic_Syllabic_Category=Consonant_With_Stacker -11A3A ; Consonant_With_Stacker # Lo ZANABAZAR SQUARE CLUSTER-INITIAL LETTER RA - -# ================================================ - # Indic_Syllabic_Category=Consonant_Subjoined 11A3B..11A3E ; Consonant_Subjoined # Mn [4] ZANABAZAR SQUARE CLUSTER-FINAL LETTER YA..ZANABAZAR SQUARE CLUSTER-FINAL LETTER VA @@ -47,12 +44,12 @@ AA29 ; Bindu # Mn CHAM VOWEL SIGN AA # ================================================ -# Indic_Syllabic_Category=Gemination_Mark +# Indic_Syllabic_Category=Gemination_Mark 11134 ; Gemination_Mark # Mc CHAKMA MAAYYAA # ================================================ -# Indic_Syllabic_Category=Nukta +# Indic_Syllabic_Category=Nukta 0F71 ; Nukta # Mn TIBETAN VOWEL SIGN AA # Reassigned to get this before an above vowel, but see #22 113CF ; Nukta # Mc TULU-TIGALARI SIGN LOOPED VIRAMA @@ -114,7 +111,7 @@ AABD ; Vowel_Independent # Lo TAI VIET VOWEL AN 18B00..18CD5 ; Consonant # Lo [470] KHITAN SMALL SCRIPT CHARACTER-18B00..KHITAN SMALL SCRIPT CHARACTER-18CD5 18CFF ; Consonant # Lo KHITAN SMALL SCRIPT CHARACTER-18CFF 1BC00..1BC6A ; Consonant # Lo [107] DUPLOYAN LETTER H..DUPLOYAN LETTER VOCALIC M -1BC70..1BC7C ; Consonant # Lo [13] DUPLOYAN AFFIX LEFT HORIZONTAL SECANT..DUPLOYAN AFFIX ATTACHED TANGENT HOOK +1BC70..1BC7C ; Consonant # Lo [13] DUPLOYAN AFFIX LEFT HORIZONTAL SECANT..DUPLOYAN AFFIX ATTACHED TANGENT HOOK 1BC80..1BC88 ; Consonant # Lo [9] DUPLOYAN AFFIX HIGH ACUTE..DUPLOYAN AFFIX HIGH VERTICAL 1BC90..1BC99 ; Consonant # Lo [10] DUPLOYAN AFFIX LOW ACUTE..DUPLOYAN AFFIX LOW ARROW 1E100..1E12C ; Consonant # Lo [45] NYIAKENG PUACHUE HMONG LETTER MA..NYIAKENG PUACHUE HMONG LETTER W @@ -259,7 +256,7 @@ FE00..FE0F ; Modifying_Letter # Mn [16] VARIATION SELECTOR-1..VARIATION SEL # ================================================ # USE, Extended_Syllabic_Category=Hieroglyph_Segment_End -13438 ; Hieroglyph_Segment_End # Cf EGYPTIAN HIEROGLYPH END SEGMENT +13438 ; Hieroglyph_Segment_End # Cf EGYPTIAN HIEROGLYPH END SEGMENT # ================================================ diff --git a/src/rust/font.rs b/src/rust/font.rs index 6abb00923..3aa3f1007 100644 --- a/src/rust/font.rs +++ b/src/rust/font.rs @@ -7,6 +7,7 @@ use std::ptr::null_mut; use std::sync::atomic::{AtomicPtr, AtomicU32, Ordering}; use std::sync::Mutex; +use skrifa::bitmap::{BitmapFormat, BitmapGlyph, BitmapStrikes, Origin}; use skrifa::charmap::Charmap; use skrifa::charmap::MapVariant::{UseDefault, Variant}; use skrifa::color::ColorGlyphCollection; @@ -25,6 +26,7 @@ use skrifa::outline::{pen::OutlinePen, DrawSettings}; #[cfg(feature = "paint")] use skrifa::{ + bitmap::BitmapData, color::{Brush, ColorPainter, ColorStop, CompositeMode, Extend, Transform}, metrics::BoundingBox, raw::tables::cpal::ColorRecord, @@ -39,6 +41,8 @@ struct FontationsData<'a> { char_map: Charmap<'a>, outline_glyphs: OutlineGlyphCollection<'a>, color_glyphs: ColorGlyphCollection<'a>, + cbdt_strikes: Option>, + sbix_strikes: Option>, glyph_names: GlyphNames<'a>, size: Size, vert_metrics: Option>, @@ -77,6 +81,9 @@ impl FontationsData<'_> { let color_glyphs = font_ref.color_glyphs(); + let cbdt_strikes = BitmapStrikes::with_format(&font_ref, BitmapFormat::Cbdt); + let sbix_strikes = BitmapStrikes::with_format(&font_ref, BitmapFormat::Sbix); + let glyph_names = font_ref.glyph_names(); let upem = hb_face_get_upem(hb_font_get_face(font)); @@ -92,6 +99,8 @@ impl FontationsData<'_> { char_map, outline_glyphs, color_glyphs, + cbdt_strikes, + sbix_strikes, glyph_names, size: Size::new(upem as f32), vert_metrics, @@ -176,6 +185,60 @@ fn struct_at_offset_mut(first: *mut T, index: u32, stride: u32) -> &'st unsafe { &mut *((first as *mut u8).offset((index * stride) as isize) as *mut T) } } +fn bitmap_size(font: *mut hb_font_t) -> Size { + let mut x_ppem = 0; + let mut y_ppem = 0; + unsafe { hb_font_get_ppem(font, &mut x_ppem, &mut y_ppem) }; + let ppem = x_ppem.max(y_ppem); + if ppem == 0 { + Size::unscaled() + } else { + Size::new(ppem as f32) + } +} + +fn bitmap_glyph_extents( + data: &FontationsData, + bitmap_glyph: &BitmapGlyph, +) -> Option { + if !bitmap_glyph.ppem_x.is_finite() + || !bitmap_glyph.ppem_y.is_finite() + || bitmap_glyph.ppem_x <= 0.0 + || bitmap_glyph.ppem_y <= 0.0 + || bitmap_glyph.width >= 65536 + || bitmap_glyph.height >= 65536 + { + return None; + } + + let upem = data.size.ppem()?; + let x_scale = upem / bitmap_glyph.ppem_x; + let y_scale = upem / bitmap_glyph.ppem_y; + + let x_bearing = (bitmap_glyph.bearing_x + bitmap_glyph.inner_bearing_x * x_scale).round(); + let inner_y = bitmap_glyph.inner_bearing_y + + if bitmap_glyph.placement_origin == Origin::BottomLeft { + bitmap_glyph.height as f32 + } else { + 0.0 + }; + let y_bearing = (bitmap_glyph.bearing_y + inner_y * y_scale).round(); + let width = (bitmap_glyph.width as f32 * x_scale).round(); + let height = -(bitmap_glyph.height as f32 * y_scale).round(); + + let scaled_x_bearing = (x_bearing * data.x_mult).floor() as hb_position_t; + let scaled_y_bearing = (y_bearing * data.y_mult).floor() as hb_position_t; + let scaled_x_end = ((x_bearing + width) * data.x_mult).ceil() as hb_position_t; + let scaled_y_end = ((y_bearing + height) * data.y_mult).ceil() as hb_position_t; + + Some(hb_glyph_extents_t { + x_bearing: scaled_x_bearing, + y_bearing: scaled_y_bearing, + width: scaled_x_end.saturating_sub(scaled_x_bearing), + height: scaled_y_end.saturating_sub(scaled_y_bearing), + }) +} + extern "C" fn _hb_fontations_get_nominal_glyphs( _font: *mut hb_font_t, font_data: *mut ::std::os::raw::c_void, @@ -393,7 +456,7 @@ extern "C" fn _hb_fontations_get_glyph_v_origin( } extern "C" fn _hb_fontations_get_glyph_extents( - _font: *mut hb_font_t, + font: *mut hb_font_t, font_data: *mut ::std::os::raw::c_void, glyph: hb_codepoint_t, extents: *mut hb_glyph_extents_t, @@ -404,15 +467,36 @@ extern "C" fn _hb_fontations_get_glyph_extents( let glyph_id = GlyphId::new(glyph); - // COLRv1 color glyphs are not supported by glyph_metrics. - let color_glyphs = &data.color_glyphs; - if color_glyphs.get(glyph_id).is_some() { - return false as hb_bool_t; - }; + let size = bitmap_size(font); + let bitmap_glyph = data + .sbix_strikes + .as_ref() + .and_then(|strikes| strikes.glyph_for_size(size, glyph_id)) + .or_else(|| { + data.cbdt_strikes + .as_ref() + .and_then(|strikes| strikes.glyph_for_size(size, glyph_id)) + }); + if let Some(bitmap_glyph) = bitmap_glyph { + let Some(bitmap_extents) = bitmap_glyph_extents(data, &bitmap_glyph) else { + return false as hb_bool_t; + }; + unsafe { *extents = bitmap_extents }; + return true as hb_bool_t; + } - let glyph_metrics = &data.glyph_metrics.as_ref().unwrap(); - let Some(glyph_extents) = glyph_metrics.bounds(glyph_id) else { - return false as hb_bool_t; + let color_glyphs = &data.color_glyphs; + let glyph_extents = if let Some(color_glyph) = color_glyphs.get(glyph_id) { + let Some(glyph_extents) = color_glyph.bounding_box(&data.location, data.size) else { + return false as hb_bool_t; + }; + glyph_extents + } else { + let glyph_metrics = &data.glyph_metrics.as_ref().unwrap(); + let Some(glyph_extents) = glyph_metrics.bounds(glyph_id) else { + return false as hb_bool_t; + }; + glyph_extents }; let x_bearing = (glyph_extents.x_min * data.x_mult).round() as hb_position_t; @@ -935,6 +1019,77 @@ impl ColorPainter for HbColorPainter<'_> { } } +#[cfg(feature = "paint")] +unsafe extern "C" fn destroy_bitmap_blob(user_data: *mut c_void) { + hb_blob_destroy(user_data.cast()); +} + +#[cfg(feature = "paint")] +fn paint_bitmap_glyph( + font: *mut hb_font_t, + data: &FontationsData, + glyph_id: GlyphId, + paint_funcs: *mut hb_paint_funcs_t, + paint_data: *mut ::std::os::raw::c_void, +) -> hb_bool_t { + let size = bitmap_size(font); + let bitmap_glyph = data + .cbdt_strikes + .as_ref() + .and_then(|strikes| strikes.glyph_for_size(size, glyph_id)) + .or_else(|| { + data.sbix_strikes + .as_ref() + .and_then(|strikes| strikes.glyph_for_size(size, glyph_id)) + }); + let Some(bitmap_glyph) = bitmap_glyph else { + return false as hb_bool_t; + }; + let Some(mut extents) = bitmap_glyph_extents(data, &bitmap_glyph) else { + return false as hb_bool_t; + }; + + let (image, format) = match &bitmap_glyph.data { + BitmapData::Png(image) => (*image, u32::from_be_bytes(*b"png ")), + BitmapData::Bgra(image) => (*image, u32::from_be_bytes(*b"BGRA")), + BitmapData::Mask(_) => return false as hb_bool_t, + }; + if image.is_empty() { + return false as hb_bool_t; + } + let Ok(image_length) = image.len().try_into() else { + return false as hb_bool_t; + }; + let face_blob = unsafe { hb_blob_reference(data.face_blob) }; + let blob = unsafe { + hb_blob_create_or_fail( + image.as_ptr().cast(), + image_length, + hb_memory_mode_t_HB_MEMORY_MODE_READONLY, + face_blob.cast(), + Some(destroy_bitmap_blob), + ) + }; + if blob.is_null() { + return false as hb_bool_t; + } + + unsafe { + hb_paint_image( + paint_funcs, + paint_data, + blob, + bitmap_glyph.width, + bitmap_glyph.height, + format, + 0.0, + &mut extents, + ); + hb_blob_destroy(blob); + } + true as hb_bool_t +} + #[cfg(feature = "paint")] extern "C" fn _hb_fontations_paint_glyph_or_fail( font: *mut hb_font_t, @@ -955,7 +1110,7 @@ extern "C" fn _hb_fontations_paint_glyph_or_fail( let glyph_id = GlyphId::new(glyph); let Some(color_glyph) = color_glyphs.get(glyph_id) else { - return false as hb_bool_t; + return paint_bitmap_glyph(font, data, glyph_id, paint_funcs, paint_data); }; let cpal = font_ref.cpal(); diff --git a/src/test-algs.cc b/src/test-algs.cc index 3689d9f6f..ead87e28e 100644 --- a/src/test-algs.cc +++ b/src/test-algs.cc @@ -106,6 +106,23 @@ main (int argc, char **argv) hb_always_assert (hb_clamp_to ((int64_t) INT_MAX + 1) == INT_MAX); hb_always_assert (hb_clamp_to ((int64_t) INT_MIN - 1) == INT_MIN); + int64_t budget = 10; + hb_always_assert (hb_budget_spend (budget, 4, 2)); + hb_always_assert (budget == 2); + hb_always_assert (!hb_budget_spend (budget, 3)); + hb_always_assert (budget == -1); + hb_always_assert (!hb_budget_spend (budget, 1)); + hb_always_assert (budget == -2); + + budget = 0; + hb_always_assert (hb_budget_spend (budget, 0)); + hb_always_assert (!hb_budget_spend (budget, 1)); + hb_always_assert (budget == -1); + + budget = INT64_MAX; + hb_always_assert (hb_budget_spend (budget, 1024)); + hb_always_assert (budget == INT64_MAX - 1024); + x = 1; hb_always_assert (++hb_inc (x) == 3); hb_always_assert (x == 3); diff --git a/src/test-paint-extents.cc b/src/test-paint-extents.cc new file mode 100644 index 000000000..f24920fe9 --- /dev/null +++ b/src/test-paint-extents.cc @@ -0,0 +1,94 @@ +/* + * Copyright © 2026 Behdad Esfahbod + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + */ + +#include "hb.hh" +#include "hb-paint-extents.hh" + + +struct budget_probe_t +{ + int64_t observed = -1; +}; + +static hb_bool_t +draw_budget_probe (hb_font_t *, void *font_data, hb_codepoint_t, + hb_draw_funcs_t *draw_funcs, void *draw_data, void *) +{ + auto *probe = (budget_probe_t *) font_data; + probe->observed = hb_draw_get_budget_remaining (draw_funcs, draw_data); + + hb_draw_state_t state = HB_DRAW_STATE_DEFAULT; + hb_draw_move_to (draw_funcs, draw_data, &state, 10.f, 20.f); + hb_draw_line_to (draw_funcs, draw_data, &state, 30.f, 40.f); + return true; +} + +int +main (int argc HB_UNUSED, char **argv HB_UNUSED) +{ + hb_paint_funcs_t *paint_funcs = hb_paint_extents_get_funcs (); + + /* COLR caches this context in zero-allocated scratch storage. */ + auto *zeroed = (hb_paint_extents_context_t *) + hb_calloc (1, sizeof (hb_paint_extents_context_t)); + hb_always_assert (zeroed); + zeroed->clear (); + hb_always_assert (hb_paint_get_budget (paint_funcs, zeroed) == HB_BUDGET_DEFAULT); + hb_always_assert (hb_paint_get_budget_remaining (paint_funcs, zeroed) > 0); + zeroed->~hb_paint_extents_context_t (); + hb_free (zeroed); + + hb_paint_extents_context_t context; + + hb_always_assert (hb_paint_get_budget (paint_funcs, &context) == HB_BUDGET_DEFAULT); + hb_always_assert (hb_paint_get_budget_remaining (paint_funcs, &context) > 0); + hb_always_assert (hb_paint_get_budget_remaining (paint_funcs, &context) < HB_BUDGET_UNLIMITED); + + budget_probe_t probe; + hb_font_funcs_t *font_funcs = hb_font_funcs_create (); + hb_font_funcs_set_draw_glyph_or_fail_func (font_funcs, draw_budget_probe, nullptr, nullptr); + hb_font_t *font = hb_font_create (hb_face_get_empty ()); + hb_font_set_funcs (font, font_funcs, &probe, nullptr); + hb_font_funcs_destroy (font_funcs); + + hb_always_assert (hb_paint_set_budget (paint_funcs, &context, 1)); + hb_paint_push_clip_glyph (paint_funcs, &context, 0, font); + hb_always_assert (probe.observed == 1); + hb_always_assert (hb_paint_get_budget_remaining (paint_funcs, &context) < 0); + + context.clear (); + hb_always_assert (hb_paint_get_budget (paint_funcs, &context) == 1); + hb_always_assert (hb_paint_get_budget_remaining (paint_funcs, &context) == 1); + + hb_always_assert (hb_paint_set_budget (paint_funcs, &context, HB_BUDGET_UNLIMITED)); + hb_always_assert (hb_paint_get_budget_remaining (paint_funcs, &context) == HB_BUDGET_UNLIMITED); + + hb_always_assert (hb_paint_set_budget (paint_funcs, &context, 0)); + context.clear (); + hb_always_assert (hb_paint_get_budget (paint_funcs, &context) == 0); + hb_always_assert (hb_paint_get_budget_remaining (paint_funcs, &context) == 0); + + hb_font_destroy (font); + return 0; +} diff --git a/src/test-repacker.cc b/src/test-repacker.cc index bf0c38871..6a2f012af 100644 --- a/src/test-repacker.cc +++ b/src/test-repacker.cc @@ -483,30 +483,33 @@ static void run_resolve_overflow_test (const char* name, printf (">>> Testing overflowing resolution for %s\n", name); - graph_t graph (overflowing.object_graph ()); + graph_t graph = graph_t::create (overflowing.object_graph ()).value (); - graph_t expected_graph (expected.object_graph ()); - if (graph::will_overflow (expected_graph)) + graph_t expected_graph = graph_t::create (expected.object_graph ()).value (); + if (graph::will_overflow (expected_graph).value ()) { if (check_binary_equivalence) { printf("when binary equivalence checking is enabled, the expected graph cannot overflow."); hb_always_assert(!check_binary_equivalence); } - expected_graph.assign_spaces (); - expected_graph.sort_shortest_distance (); + hb_always_assert (expected_graph.assign_spaces ().is_ok ()); + hb_always_assert (expected_graph.sort_shortest_distance ().is_ok ()); } // Check that overflow resolution succeeds hb_always_assert (overflowing.offset_overflow ()); - hb_always_assert (hb_resolve_graph_overflows (tag, + auto r = hb_resolve_graph_overflows (tag, num_iterations, recalculate_extensions, - graph)); + graph); + if (r.is_err()) + printf("run_resolve_overflow_test: overflow resolution failed, cause: %s\n", graph::to_string(r.error())); + hb_always_assert (r.is_ok()); // Check the graphs can be serialized. - hb_blob_t* out1 = graph::serialize (graph); + hb_blob_t* out1 = graph::serialize (graph).value (); hb_always_assert (out1); - hb_blob_t* out2 = graph::serialize (expected_graph); + hb_blob_t* out2 = graph::serialize (expected_graph).value (); hb_always_assert (out2); if (check_binary_equivalence) { unsigned l1, l2; @@ -1894,10 +1897,9 @@ static void test_sort_shortest () hb_serialize_context_t e (buffer_e, buffer_size); populate_serializer_complex_2 (&a); - graph_t graph (a.object_graph ()); - graph.sort_shortest_distance (); + graph_t graph = graph_t::create (a.object_graph ()).value (); + hb_always_assert (graph.sort_shortest_distance ().is_ok()); graph.normalize(); - hb_always_assert (!graph.in_error ()); // Expected graph e.start_serialize(); @@ -1920,7 +1922,7 @@ static void test_sort_shortest () e.pop_pack (false); e.end_serialize(); - graph_t expected(e.object_graph()); + graph_t expected = graph_t::create (e.object_graph ()).value (); expected.normalize(); assert(expected == graph); @@ -1938,8 +1940,8 @@ static void test_duplicate_leaf () hb_serialize_context_t e (buffer_e, buffer_size); populate_serializer_complex_2 (&a); - graph_t graph (a.object_graph ()); - graph.duplicate (4, 1, false); + graph_t graph = graph_t::create (a.object_graph ()).value (); + hb_always_assert (graph.duplicate (4, 1, false).is_ok ()); graph.normalize(); e.start_serialize(); @@ -1962,7 +1964,7 @@ static void test_duplicate_leaf () add_offset(mn, &e); e.pop_pack(false); - graph_t expected(e.object_graph()); + graph_t expected = graph_t::create (e.object_graph ()).value (); expected.normalize(); assert(expected == graph); @@ -1978,8 +1980,8 @@ static void test_duplicate_interior () hb_serialize_context_t c (buffer, buffer_size); populate_serializer_complex_3 (&c); - graph_t graph (c.object_graph ()); - graph.duplicate (3, 2, false); + graph_t graph = graph_t::create (c.object_graph ()).value (); + hb_always_assert (graph.duplicate (3, 2, false).is_ok ()); hb_always_assert(strncmp (graph.object (6).head, "jkl", 3) == 0); hb_always_assert(graph.object (6).real_links.length == 1); @@ -2021,8 +2023,8 @@ test_serialize () populate_serializer_simple (&c1); hb_bytes_t expected = c1.copy_bytes (); - graph_t graph (c1.object_graph ()); - hb_blob_t* out = graph::serialize (graph); + graph_t graph = graph_t::create (c1.object_graph ()).value (); + hb_blob_t* out = graph::serialize (graph).value (); free (buffer_1); hb_bytes_t actual = out->as_bytes (); @@ -2038,9 +2040,9 @@ static void test_will_overflow_1 () hb_serialize_context_t c (buffer, buffer_size); populate_serializer_complex_2 (&c); - graph_t graph (c.object_graph ()); + graph_t graph = graph_t::create (c.object_graph ()).value (); - hb_always_assert (!graph::will_overflow (graph, nullptr)); + hb_always_assert (!graph::will_overflow (graph, nullptr).value ()); free (buffer); } @@ -2051,9 +2053,9 @@ static void test_will_overflow_2 () void* buffer = malloc (buffer_size); hb_serialize_context_t c (buffer, buffer_size); populate_serializer_with_overflow (&c); - graph_t graph (c.object_graph ()); + graph_t graph = graph_t::create (c.object_graph ()).value (); - hb_always_assert (graph::will_overflow (graph, nullptr)); + hb_always_assert (graph::will_overflow (graph, nullptr).value ()); free (buffer); } @@ -2064,9 +2066,9 @@ static void test_will_overflow_3 () void* buffer = malloc (buffer_size); hb_serialize_context_t c (buffer, buffer_size); populate_serializer_with_dedup_overflow (&c); - graph_t graph (c.object_graph ()); + graph_t graph = graph_t::create (c.object_graph ()).value (); - hb_always_assert (graph::will_overflow (graph, nullptr)); + hb_always_assert (graph::will_overflow (graph, nullptr).value ()); free (buffer); } @@ -2077,7 +2079,7 @@ static void test_resolve_overflows_via_sort () void* buffer = malloc (buffer_size); hb_serialize_context_t c (buffer, buffer_size); populate_serializer_with_overflow (&c); - graph_t graph (c.object_graph ()); + graph_t graph = graph_t::create (c.object_graph ()).value (); hb_blob_t* out = hb_resolve_overflows (c.object_graph (), HB_TAG_NONE); hb_always_assert (out); @@ -2094,7 +2096,7 @@ static void test_resolve_overflows_via_duplication () void* buffer = malloc (buffer_size); hb_serialize_context_t c (buffer, buffer_size); populate_serializer_with_dedup_overflow (&c); - graph_t graph (c.object_graph ()); + graph_t graph = graph_t::create (c.object_graph ()).value (); hb_blob_t* out = hb_resolve_overflows (c.object_graph (), HB_TAG_NONE); hb_always_assert (out); @@ -2111,7 +2113,7 @@ static void test_resolve_overflows_via_multiple_duplications () void* buffer = malloc (buffer_size); hb_serialize_context_t c (buffer, buffer_size); populate_serializer_with_multiple_dedup_overflow (&c); - graph_t graph (c.object_graph ()); + graph_t graph = graph_t::create (c.object_graph ()).value (); hb_blob_t* out = hb_resolve_overflows (c.object_graph (), HB_TAG_NONE, 5); hb_always_assert (out); @@ -2145,7 +2147,7 @@ static void test_resolve_overflows_via_isolation () void* buffer = malloc (buffer_size); hb_serialize_context_t c (buffer, buffer_size); populate_serializer_with_isolation_overflow (&c); - graph_t graph (c.object_graph ()); + graph_t graph = graph_t::create (c.object_graph ()).value (); hb_always_assert (c.offset_overflow ()); hb_blob_t* out = hb_resolve_overflows (c.object_graph (), HB_TAG ('G', 'S', 'U', 'B'), 0); @@ -2220,7 +2222,7 @@ static void test_resolve_overflows_via_isolation_spaces () void* buffer = malloc (buffer_size); hb_serialize_context_t c (buffer, buffer_size); populate_serializer_with_isolation_overflow_spaces (&c); - graph_t graph (c.object_graph ()); + graph_t graph = graph_t::create (c.object_graph ()).value (); hb_always_assert (c.offset_overflow ()); hb_blob_t* out = hb_resolve_overflows (c.object_graph (), HB_TAG ('G', 'S', 'U', 'B'), 0); @@ -2241,7 +2243,7 @@ static void test_resolve_mixed_overflows_via_isolation_spaces () void* buffer = malloc (buffer_size); hb_serialize_context_t c (buffer, buffer_size); populate_serializer_with_24_and_32_bit_offsets (&c); - graph_t graph (c.object_graph ()); + graph_t graph = graph_t::create (c.object_graph ()).value (); hb_always_assert (c.offset_overflow ()); hb_blob_t* out = hb_resolve_overflows (c.object_graph (), HB_TAG ('G', 'S', 'U', 'B'), 0); @@ -2749,32 +2751,30 @@ test_deep_graph_traversal () } c.end_serialize (); - graph_t graph (c.object_graph ()); - hb_always_assert (!graph.in_error ()); + graph_t graph = graph_t::create (c.object_graph ()).value (); // Test find_subgraph (set) hb_set_t visited_set; - graph.find_subgraph (graph.root_idx (), visited_set); + hb_always_assert (graph.find_subgraph (graph.root_idx (), visited_set).is_ok ()); hb_always_assert (visited_set.get_population () == 2001); // Test find_subgraph_size hb_set_t size_set; - size_t sz = graph.find_subgraph_size (graph.root_idx (), size_set); + size_t sz = graph.find_subgraph_size (graph.root_idx (), size_set).value (); hb_always_assert (sz == 4 + 2000 * 6); // Test find_subgraph (map) hb_map_t map; map.set (graph.root_idx (), 1); - graph.find_subgraph (graph.root_idx (), map); + hb_always_assert (graph.find_subgraph (graph.root_idx (), map).is_ok ()); hb_always_assert (map.get_population () == 2001); // Test assign_spaces (which exercises find_connected_nodes and find_space_roots) - graph.assign_spaces (); - hb_always_assert (!graph.in_error ()); + hb_always_assert (graph.assign_spaces ().is_ok ()); // Test duplicate_subgraph hb_map_t index_map; - graph.duplicate_subgraph (graph.root_idx (), index_map); + hb_always_assert (graph.duplicate_subgraph (graph.root_idx (), index_map).is_ok ()); hb_always_assert (index_map.get_population () == 2001); free (buffer); @@ -2801,11 +2801,10 @@ test_32bit_roots_traversal () c.pop_pack (false); c.end_serialize (); - graph_t graph (c.object_graph ()); - hb_always_assert (!graph.in_error ()); + graph_t graph = graph_t::create (c.object_graph ()).value (); hb_set_t roots; - graph.find_32bit_roots (graph.root_idx (), roots); + hb_always_assert (graph.find_32bit_roots (graph.root_idx (), roots).is_ok ()); hb_always_assert (roots.has (leaf1 - 1)); hb_always_assert (roots.has (leaf2 - 1)); hb_always_assert (!roots.has (mid - 1)); @@ -2840,11 +2839,10 @@ test_32bit_roots_traversal () c2.end_serialize (); - graph_t graph2 (c2.object_graph ()); - hb_always_assert (!graph2.in_error ()); + graph_t graph2 = graph_t::create (c2.object_graph ()).value (); hb_set_t roots2; - graph2.find_32bit_roots (graph2.root_idx (), roots2); + hb_always_assert (graph2.find_32bit_roots (graph2.root_idx (), roots2).is_ok ()); hb_always_assert (roots2.get_population () == 1); hb_always_assert (roots2.has (a - 1)); hb_always_assert (!roots2.has (b - 1)); @@ -2852,12 +2850,54 @@ test_32bit_roots_traversal () free (buffer); } +static void test_invalid_link_objidx () +{ + size_t buffer_size = 100; + void* buffer = malloc (buffer_size); + hb_serialize_context_t c (buffer, buffer_size); + populate_serializer_complex_2 (&c); + + graph_t graph = graph_t::create (c.object_graph ()).value (); + + // Poison a link to point to (unsigned) -1 + auto links = graph.vertices_[graph.root_idx ()].real_links_writer(); + links->objidx = (unsigned) -1; + + // Running Dijkstra / shortest distance sorting must not crash or OOB access, + // and must return an error. + hb_always_assert (!graph.sort_shortest_distance ().is_ok ()); + + free (buffer); +} + +static void test_invalid_link_add_and_move () +{ + size_t buffer_size = 100; + void* buffer = malloc (buffer_size); + hb_serialize_context_t c (buffer, buffer_size); + populate_serializer_complex_2 (&c); + + graph_t graph = graph_t::create (c.object_graph ()).value (); + + // add_link with out-of-bounds child + OT::Offset16 dummy; + hb_always_assert (!graph.add_link (&dummy, 0, (unsigned) -1).is_ok ()); + + // move_child with non-existent offset + auto res = graph.move_child (0, &dummy, 1, &dummy); + hb_always_assert (!res.is_ok ()); + + free (buffer); +} + // TODO(garretrieger): update will_overflow tests to check the overflows array. // TODO(garretrieger): add tests for priority raising. int main (int argc, char **argv) { + test_invalid_link_objidx (); + test_invalid_link_add_and_move (); test_serialize (); test_sort_shortest (); test_will_overflow_1 (); diff --git a/src/test-result.cc b/src/test-result.cc new file mode 100644 index 000000000..9d487d408 --- /dev/null +++ b/src/test-result.cc @@ -0,0 +1,648 @@ +/* + * Copyright © 2025 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Google Author(s): Garret Rieger + */ + +#include "hb-result.hh" + + +// Track constructor and destructor counts to verify leak-freedom +static int live_instances = 0; + +enum error_code_t { + ERR_A, + ERR_B, + ERR_C, +}; + +template +using result = hb_result_t; + +struct resource_t +{ + int id; + + explicit resource_t (int id_) : id (id_) { live_instances++; } + resource_t (const resource_t& o) : id (o.id) { live_instances++; } + resource_t (resource_t&& o) : id (o.id) { o.id = -1; live_instances++; } + ~resource_t () { live_instances--; } + + resource_t& operator = (const resource_t& o) + { + id = o.id; + return *this; + } + resource_t& operator = (resource_t&& o) + { + id = o.id; + o.id = -1; + return *this; + } + + bool operator == (const resource_t& o) const { return id == o.id; } +}; + +static result returns_ok (int v) +{ + return Ok(v); +} + +static result returns_err (error_code_t e) +{ + return Err(e); +} + +static result try_callee (bool fail, int v, error_code_t e = ERR_A) +{ + if (fail) return Err(e); + return Ok(v); +} + +static result try_callee_void (bool fail, error_code_t e) +{ + if (fail) return e; + return Ok(); +} + +static result try_caller (bool fail1, bool fail2) +{ + TRY_ASSIGN (int index, try_callee (fail1, 10, ERR_A)); + TRY_ASSIGN (int index2, try_callee (fail2, 20, ERR_B)); + return Ok(index + index2); +} + +static result try_caller_void (bool fail) +{ + TRY (try_callee_void (fail, ERR_C)); + return Ok(); +} + +static result try_caller_type_change (bool fail) +{ + TRY_ASSIGN (int index, try_callee (fail, 100, ERR_A)); + return Ok((float) index * 1.5f); +} + +static result try_assign_existing (bool fail) +{ + int val = 1; + TRY_ASSIGN (val, try_callee (fail, 42, ERR_A)); + return Ok(val); +} + +static void test_ok_basic () +{ + result r = returns_ok (42); + hb_always_assert (r.is_ok ()); + hb_always_assert (!r.is_err ()); + hb_always_assert ((bool) r); + hb_always_assert (r.value () == 42); + hb_always_assert (*r == 42); + hb_always_assert (r.value_or (0) == 42); + hb_always_assert (r.value_or_default () == 42); + hb_always_assert (r == Ok(42)); + hb_always_assert (Ok(42) == r); +} + +static void test_err_basic () +{ + result r = returns_err (ERR_A); + hb_always_assert (!r.is_ok ()); + hb_always_assert (r.is_err ()); + hb_always_assert (!r); + hb_always_assert (r.error () == ERR_A); + hb_always_assert (r.value_or (99) == 99); + hb_always_assert (r.value_or_default () == 0); + hb_always_assert (r == Err(ERR_A)); + hb_always_assert (Err(ERR_A) == r); + hb_always_assert (r != Err(ERR_B)); + hb_always_assert (Err(ERR_B) != r); +} + +static void test_explicit_ok_err () +{ + result r1 = Ok(100u); + hb_always_assert (r1.is_ok ()); + hb_always_assert (r1.value () == 100u); + + result r2 = Err(ERR_A); + hb_always_assert (r2.is_err ()); + hb_always_assert (r2.error () == ERR_A); +} + +static void test_pointers () +{ + int x = 123; + result r = &x; + hb_always_assert (r.is_ok ()); + hb_always_assert (*r == &x); + hb_always_assert (**r == 123); + **r = 456; + hb_always_assert (x == 456); +} + +static void test_void () +{ + result r1 = Ok(); + hb_always_assert (r1.is_ok ()); + hb_always_assert (!r1.is_err ()); + hb_always_assert ((bool) r1); + hb_always_assert (r1 == Ok()); + hb_always_assert (r1 != Err(ERR_A)); + hb_always_assert (Ok() == r1); + hb_always_assert (Err(ERR_A) != r1); + + result r2 = Err(ERR_A); + hb_always_assert (!r2.is_ok ()); + hb_always_assert (r2.is_err ()); + hb_always_assert (!r2); + hb_always_assert (r2.error () == ERR_A); + hb_always_assert (r2 == Err(ERR_A)); + hb_always_assert (r2 != Err(ERR_B)); + hb_always_assert (r2 != Ok()); + hb_always_assert (Err(ERR_A) == r2); + hb_always_assert (Err(ERR_B) != r2); + hb_always_assert (Ok() != r2); +} + +static void test_resource_cleanup () +{ + hb_always_assert (live_instances == 0); + + { + result r = resource_t (1); + hb_always_assert (live_instances == 1); + hb_always_assert (r.value ().id == 1); + } + hb_always_assert (live_instances == 0); + + { + result r1 = resource_t (2); + hb_always_assert (live_instances == 1); + result r2 = r1; + hb_always_assert (live_instances == 2); + result r3 = std::move (r1); + hb_always_assert (live_instances == 3); + } + hb_always_assert (live_instances == 0); + + { + result r = resource_t (3); + hb_always_assert (live_instances == 1); + r = Err(ERR_A); + hb_always_assert (live_instances == 0); + hb_always_assert (r.is_err ()); + } + hb_always_assert (live_instances == 0); +} + +static void test_try_macro () +{ + // Test success path + result r_success = try_caller (false, false); + hb_always_assert (r_success.is_ok ()); + hb_always_assert (r_success.value () == 30); + + // Test first failure propagates + result r_fail1 = try_caller (true, false); + hb_always_assert (r_fail1.is_err ()); + hb_always_assert (r_fail1.error () == ERR_A); + + // Test second failure propagates + result r_fail2 = try_caller (false, true); + hb_always_assert (r_fail2.is_err ()); + hb_always_assert (r_fail2.error () == ERR_B); + + // Test TRY in void function + result v_ok = try_caller_void (false); + hb_always_assert (v_ok.is_ok ()); + + result v_err = try_caller_void (true); + hb_always_assert (v_err.is_err ()); + hb_always_assert (v_err.error () == ERR_C); + + // Test TRY with different return type + result f_ok = try_caller_type_change (false); + hb_always_assert (f_ok.is_ok ()); + hb_always_assert (f_ok.value () == 150.0f); + + result f_err = try_caller_type_change (true); + hb_always_assert (f_err.is_err ()); + hb_always_assert (f_err.error () == ERR_A); + + // Test TRY_ASSIGN into existing variable + result a_ok = try_assign_existing (false); + hb_always_assert (a_ok.is_ok ()); + hb_always_assert (a_ok.value () == 42); + + result a_err = try_assign_existing (true); + hb_always_assert (a_err.is_err ()); + hb_always_assert (a_err.error () == ERR_A); +} + +template +struct is_equality_comparable : std::false_type {}; + +template +struct is_equality_comparable> : std::true_type {}; + +static void test_same_or_convertible_types () +{ + // Comparisons between result and raw types are disallowed + static_assert (!is_equality_comparable, int>::value, ""); + static_assert (!is_equality_comparable, int64_t>::value, ""); + static_assert (!is_equality_comparable>::value, ""); + static_assert (!is_equality_comparable, error_code_t>::value, ""); + static_assert (!is_equality_comparable>::value, ""); + static_assert (!is_equality_comparable, error_code_t>::value, ""); + static_assert (is_equality_comparable, result>::value, ""); + static_assert (is_equality_comparable, hb_result_ok_t>::value, ""); + static_assert (is_equality_comparable, hb_result_err_t>::value, ""); + + // Types convertible into each other cannot be directly constructed without Ok/Err + static_assert (!std::is_constructible, int>::value, ""); + static_assert (!std::is_constructible, int64_t>::value, ""); + static_assert (!std::is_constructible, int32_t>::value, ""); + static_assert (std::is_constructible, hb_result_ok_t>::value, ""); + static_assert (std::is_constructible, hb_result_err_t>::value, ""); + + // Same types cannot be directly constructed without Ok/Err + static_assert (!std::is_constructible, int>::value, ""); + static_assert (std::is_constructible, hb_result_ok_t>::value, ""); + static_assert (std::is_constructible, hb_result_err_t>::value, ""); + + // Types convertible into each other cannot be directly constructed + static_assert (!std::is_constructible, int>::value, ""); + static_assert (!std::is_constructible, error_code_t>::value, ""); + + // Types not convertible into each other can be directly constructed + static_assert (std::is_constructible, resource_t>::value, ""); + static_assert (std::is_constructible, error_code_t>::value, ""); + + hb_result_t r_ok = Ok(1); + hb_always_assert (r_ok.is_ok ()); + hb_always_assert (r_ok.value () == 1); + + hb_result_t r_err = Err(2); + hb_always_assert (r_err.is_err ()); + hb_always_assert (r_err.error () == 2); + + hb_result_t same_ok = Ok(42); + hb_always_assert (same_ok.is_ok ()); + hb_always_assert (same_ok.value () == 42); + + hb_result_t same_err = Err(99); + hb_always_assert (same_err.is_err ()); + hb_always_assert (same_err.error () == 99); +} + +struct any_value_t +{ + template + any_value_t (X&&) {} +}; + +static void test_error_interception() { + // Checks that U&& constructor does not intercept mismatched error tags as a success value. + static_assert (!std::is_constructible, hb_result_err_t>::value, ""); + + hb_result_t r = Err(ERR_A); + hb_always_assert (r.is_err ()); + + hb_result_t r_ok = Ok(123); + hb_always_assert (r_ok.is_ok ()); +} + +struct move_only_err_t +{ + int code; + + explicit move_only_err_t (int c) : code (c) {} + move_only_err_t (const move_only_err_t&) = delete; + move_only_err_t (move_only_err_t&& o) : code (o.code) { o.code = -1; } + move_only_err_t& operator = (const move_only_err_t&) = delete; + move_only_err_t& operator = (move_only_err_t&& o) { code = o.code; o.code = -1; return *this; } + ~move_only_err_t () = default; + + bool operator == (const move_only_err_t& o) const { return code == o.code; } +}; + +struct move_only_val_t +{ + int val; + + explicit move_only_val_t (int v) : val (v) {} + move_only_val_t (const move_only_val_t&) = delete; + move_only_val_t (move_only_val_t&& o) : val (o.val) { o.val = -1; } + move_only_val_t& operator = (const move_only_val_t&) = delete; + move_only_val_t& operator = (move_only_val_t&& o) { val = o.val; o.val = -1; return *this; } + ~move_only_val_t () = default; + + bool operator == (const move_only_val_t& o) const { return val == o.val; } +}; + +static void test_move_only_types () +{ + // Test hb_result_t with Err(...) + { + hb_result_t r = Err(move_only_err_t (123)); + hb_always_assert (r.is_err ()); + hb_always_assert (r.error ().code == 123); + + move_only_err_t err = std::move (r).error (); + hb_always_assert (err.code == 123); + } + + // Test direct construction from move_only_err_t + { + hb_result_t r = move_only_err_t (456); + hb_always_assert (r.is_err ()); + hb_always_assert (r.error ().code == 456); + } + + // Test hb_result_t with Err(...) and direct construction + { + hb_result_t v1 = Err(move_only_err_t (789)); + hb_always_assert (v1.is_err ()); + hb_always_assert (v1.error ().code == 789); + + hb_result_t v2 = move_only_err_t (999); + hb_always_assert (v2.is_err ()); + hb_always_assert (v2.error ().code == 999); + } + + // Test value_or with move-only value types + { + hb_result_t r_ok = Ok(move_only_val_t (42)); + move_only_val_t v = std::move (r_ok).value_or (move_only_val_t (0)); + hb_always_assert (v.val == 42); + + hb_result_t r_err = Err(ERR_A); + move_only_val_t v_fallback = std::move (r_err).value_or (move_only_val_t (99)); + hb_always_assert (v_fallback.val == 99); + } +} + +struct copy_move_counter_t +{ + static int copy_count; + static int move_count; + + static void reset () + { + copy_count = 0; + move_count = 0; + } + + int val; + + bool in_error() const { + return val == -1; + } + + explicit copy_move_counter_t (int v) : val (v) {} + copy_move_counter_t (const copy_move_counter_t& o) : val (o.val) { copy_count++; } + copy_move_counter_t (copy_move_counter_t&& o) : val (o.val) { o.val = -1; move_count++; } + ~copy_move_counter_t () = default; +}; + +int copy_move_counter_t::copy_count = 0; +int copy_move_counter_t::move_count = 0; + +static result return_tracked_from_local () +{ + copy_move_counter_t out (42); + return out; +} + +static result return_tracked_from_local_with_tag () +{ + copy_move_counter_t out (42); + return Ok(out); +} + +static hb_result_t return_tracked_error_from_local () +{ + copy_move_counter_t out (42); + return out; +} + +static hb_result_t return_tracked_error_from_local_with_tag () +{ + copy_move_counter_t out (42); + return Err(out); +} + +static result return_move_only_from_local () +{ + move_only_val_t out (42); + return out; +} + +static void test_return_moves_from_local () +{ + // Verify 0 copies and only moves occur when returning local value directly + { + copy_move_counter_t::reset (); + result r = return_tracked_from_local (); + hb_always_assert (r.is_ok ()); + hb_always_assert (r.value ().val == 42); + hb_always_assert (copy_move_counter_t::copy_count == 0); + hb_always_assert (copy_move_counter_t::move_count >= 1); + } + + // Verify 0 copies and only moves occur when returning local value directly + { + copy_move_counter_t::reset (); + result r = return_tracked_from_local_with_tag (); + hb_always_assert (r.is_ok ()); + hb_always_assert (r.value ().val == 42); + hb_always_assert (copy_move_counter_t::copy_count == 0); + hb_always_assert (copy_move_counter_t::move_count >= 1); + } + + + // Verify 0 copies and only moves occur when returning local error directly + { + copy_move_counter_t::reset (); + hb_result_t r = return_tracked_error_from_local (); + hb_always_assert (r.is_err ()); + hb_always_assert (r.error().val == 42); + hb_always_assert (copy_move_counter_t::copy_count == 0); + hb_always_assert (copy_move_counter_t::move_count >= 1); + } + + // Verify 0 copies and only moves occur when returning local error directly + { + copy_move_counter_t::reset (); + hb_result_t r = return_tracked_error_from_local_with_tag (); + hb_always_assert (r.is_err ()); + hb_always_assert (r.error().val == 42); + hb_always_assert (copy_move_counter_t::copy_count == 0); + hb_always_assert (copy_move_counter_t::move_count >= 1); + } + + + // Test returning move-only type (statically proves no copy is attempted) + { + result r = return_move_only_from_local (); + hb_always_assert (r.is_ok ()); + hb_always_assert (r.value ().val == 42); + } +} + +struct in_error_t { + bool successful; + + in_error_t(bool s) : successful(s) {} + + bool in_error() const { + return !successful; + } +}; + +static void test_from () { + in_error_t has_error(false); + in_error_t no_error(true); + result r = result::from(has_error, ERR_B); + hb_always_assert(r.is_err()); + hb_always_assert(r.error() == ERR_B); + r = result::from(no_error, ERR_B); + hb_always_assert(!r.is_err()); +} + +struct default_constructible_t +{ + int val; + + default_constructible_t () : val (123) {} + explicit default_constructible_t (int v) : val (v) {} +}; + +struct move_only_default_t +{ + int val; + move_only_default_t () : val (77) {} + explicit move_only_default_t (int v) : val (v) {} + move_only_default_t (const move_only_default_t&) = delete; + move_only_default_t (move_only_default_t&& o) : val (o.val) { o.val = -1; } + move_only_default_t& operator = (const move_only_default_t&) = delete; + move_only_default_t& operator = (move_only_default_t&& o) { val = o.val; o.val = -1; return *this; } + ~move_only_default_t () = default; +}; + +static void test_value_or_default () +{ + // Test const & + { + const result r_ok = Ok(42); + hb_always_assert (r_ok.value_or_default () == 42); + + const result r_err = Err(ERR_A); + hb_always_assert (r_err.value_or_default () == 0); + } + + // Test && (rvalues and move) + { + result r_ok = Ok(42); + hb_always_assert (std::move (r_ok).value_or_default () == 42); + + result r_err = Err(ERR_A); + hb_always_assert (std::move (r_err).value_or_default () == 0); + } + + // Test custom struct with default constructor + { + result r_ok = default_constructible_t (456); + hb_always_assert (r_ok.value_or_default ().val == 456); + + result r_err = ERR_A; + hb_always_assert (r_err.value_or_default ().val == 123); + + hb_always_assert (std::move (r_ok).value_or_default ().val == 456); + hb_always_assert (std::move (r_err).value_or_default ().val == 123); + } + + // Test pointers + { + int x = 10; + result r_ok = &x; + hb_always_assert (r_ok.value_or_default () == &x); + + result r_err = ERR_A; + hb_always_assert (r_err.value_or_default () == nullptr); + } + + // Test move-only types + { + result r_mo_ok = move_only_default_t (88); + hb_always_assert (std::move (r_mo_ok).value_or_default ().val == 88); + + result r_mo_err = ERR_A; + hb_always_assert (std::move (r_mo_err).value_or_default ().val == 77); + } +} + +static void test_from_move() +{ + { + copy_move_counter_t::reset(); + copy_move_counter_t ok (24); + result r_ok = result::from(std::move(ok), ERR_B); + hb_always_assert (r_ok.is_ok()); + hb_always_assert (r_ok->val == 24); + hb_always_assert (copy_move_counter_t::copy_count == 0); + hb_always_assert (copy_move_counter_t::move_count == 1); + } + + { + copy_move_counter_t::reset(); + copy_move_counter_t fail (-1); + result r_fail = result::from(std::move(fail), ERR_B); + hb_always_assert (r_fail.is_err()); + hb_always_assert (r_fail.error() == ERR_B); + hb_always_assert (copy_move_counter_t::copy_count == 0); + hb_always_assert (copy_move_counter_t::move_count == 0); + } +} + +int main () +{ + test_ok_basic (); + test_err_basic (); + test_explicit_ok_err (); + test_pointers (); + test_void (); + test_resource_cleanup (); + test_try_macro (); + test_same_or_convertible_types (); + test_error_interception (); + test_move_only_types (); + test_return_moves_from_local (); + test_from(); + test_value_or_default (); + test_from_move (); + + return 0; +} diff --git a/test/api/meson.build b/test/api/meson.build index 4b8393a00..36f4d3401 100644 --- a/test/api/meson.build +++ b/test/api/meson.build @@ -96,6 +96,10 @@ if conf.get('HAVE_DIRECTWRITE', 0) == 1 ] endif +if conf.get('HAVE_CAIRO', 0) == 1 + tests += 'test-cairo.c' +endif + if conf.get('HAVE_PTHREAD', 0) == 1 tests += 'test-multithread.c' endif diff --git a/test/api/test-cairo.c b/test/api/test-cairo.c new file mode 100644 index 000000000..c4a4e289d --- /dev/null +++ b/test/api/test-cairo.c @@ -0,0 +1,77 @@ +/* + * Copyright © 2026 Behdad Esfahbod + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + */ + +#include "hb-test.h" + +#include + +#if defined(__has_feature) +#if __has_feature(thread_sanitizer) +#define HB_TEST_CAIRO_TSAN 1 +#endif +#endif +#if defined(__SANITIZE_THREAD__) +#define HB_TEST_CAIRO_TSAN 1 +#endif + +static void +test_hb_cairo_budget (void) +{ +#ifdef HB_TEST_CAIRO_TSAN + /* Cairo's user-font rendering takes two internal mutexes in both orders. + * The same workload reports this lock-order inversion against unmodified + * HarfBuzz; keep race detection enabled rather than suppressing Cairo + * deadlock reports process-wide. */ + g_test_skip ("Cairo user-font rendering has a pre-existing lock-order inversion under TSan"); + return; +#endif + + hb_face_t *face = hb_test_open_font_file ("../fuzzing/fonts/clusterfuzz-testcase-minimized-hb-vector-fuzzer-4886959609413632"); + cairo_font_face_t *cairo_face = hb_cairo_font_face_create_for_face (face); + cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 64, 64); + cairo_t *cr = cairo_create (surface); + + cairo_set_font_face (cr, cairo_face); + cairo_set_font_size (cr, 30); + + cairo_glyph_t glyph = {0, 0, 0}; + cairo_show_glyphs (cr, &glyph, 1); + + g_assert_cmpint (cairo_status (cr), ==, CAIRO_STATUS_SUCCESS); + g_assert_cmpint (cairo_surface_status (surface), ==, CAIRO_STATUS_SUCCESS); + + cairo_destroy (cr); + cairo_surface_destroy (surface); + cairo_font_face_destroy (cairo_face); + hb_face_destroy (face); +} + +int +main (int argc, char **argv) +{ + hb_test_init (&argc, &argv); + hb_test_add (test_hb_cairo_budget); + + return hb_test_run (); +} diff --git a/test/api/test-draw-varc.c b/test/api/test-draw-varc.c index 29645c0a6..70a84f1ee 100644 --- a/test/api/test-draw-varc.c +++ b/test/api/test-draw-varc.c @@ -36,6 +36,13 @@ typedef struct draw_data_t unsigned close_path_count; } draw_data_t; +typedef struct budget_draw_data_t +{ + draw_data_t draw; + int64_t policy; + int64_t remaining; +} budget_draw_data_t; + /* Our modified itoa, why not using libc's? it is going to be used in harfbuzzjs where libc isn't available */ static void _hb_reverse (char *buf, unsigned int len) @@ -149,6 +156,30 @@ close_path (HB_UNUSED hb_draw_funcs_t *dfuncs, void *draw_data_, draw_data->close_path_count++; } +static hb_bool_t +set_budget (HB_UNUSED hb_draw_funcs_t *dfuncs, void *draw_data_, + int64_t budget, HB_UNUSED void *user_data) +{ + budget_draw_data_t *draw_data = (budget_draw_data_t *) draw_data_; + draw_data->policy = budget; + draw_data->remaining = budget == HB_BUDGET_DEFAULT ? 1 << 20 : budget; + return TRUE; +} + +static int64_t +get_budget (HB_UNUSED hb_draw_funcs_t *dfuncs, void *draw_data_, + HB_UNUSED void *user_data) +{ + return ((budget_draw_data_t *) draw_data_)->policy; +} + +static int64_t * +get_budget_remaining (HB_UNUSED hb_draw_funcs_t *dfuncs, void *draw_data_, + HB_UNUSED void *user_data) +{ + return &((budget_draw_data_t *) draw_data_)->remaining; +} + static hb_draw_funcs_t *funcs; #ifdef HB_EXPERIMENTAL_API @@ -248,6 +279,44 @@ test_hb_draw_varc_conditional (void) hb_font_destroy (font); } + +static void +test_hb_draw_varc_budget (void) +{ + hb_face_t *face = hb_test_open_font_file ("fonts/varc-6868.ttf"); + hb_font_t *font = hb_font_create (face); + hb_face_destroy (face); + + hb_codepoint_t gid = 0; + g_assert_true (hb_font_get_nominal_glyph (font, 0x6868u, &gid)); + + hb_draw_funcs_t *budget_funcs = hb_draw_funcs_create (); + hb_draw_funcs_set_move_to_func (budget_funcs, move_to, NULL, NULL); + hb_draw_funcs_set_line_to_func (budget_funcs, line_to, NULL, NULL); + hb_draw_funcs_set_quadratic_to_func (budget_funcs, quadratic_to, NULL, NULL); + hb_draw_funcs_set_cubic_to_func (budget_funcs, cubic_to, NULL, NULL); + hb_draw_funcs_set_close_path_func (budget_funcs, close_path, NULL, NULL); + hb_draw_funcs_set_set_budget_func (budget_funcs, set_budget, NULL, NULL); + hb_draw_funcs_set_get_budget_func (budget_funcs, get_budget, NULL, NULL); + hb_draw_funcs_set_get_budget_remaining_func (budget_funcs, get_budget_remaining, NULL, NULL); + hb_draw_funcs_make_immutable (budget_funcs); + + budget_draw_data_t draw_data = {{0}, HB_BUDGET_DEFAULT, 0}; + g_assert_true (hb_draw_set_budget (budget_funcs, &draw_data, 1 << 20)); + hb_font_draw_glyph (font, gid, budget_funcs, &draw_data); + g_assert_cmpuint (draw_data.draw.move_to_count, ==, 11); + g_assert_cmpint (draw_data.remaining, <, 1 << 20); + g_assert_cmpint (draw_data.remaining, >=, 0); + + draw_data.draw = (draw_data_t) {0}; + g_assert_true (hb_draw_set_budget (budget_funcs, &draw_data, 1)); + hb_font_draw_glyph (font, gid, budget_funcs, &draw_data); + g_assert_cmpint (draw_data.remaining, <, 0); + g_assert_cmpuint (draw_data.draw.move_to_count, ==, 0); + + hb_draw_funcs_destroy (budget_funcs); + hb_font_destroy (font); +} #endif int @@ -267,6 +336,7 @@ main (int argc, char **argv) hb_test_add (test_hb_draw_varc_simple_hangul); hb_test_add (test_hb_draw_varc_simple_hanzi); hb_test_add (test_hb_draw_varc_conditional); + hb_test_add (test_hb_draw_varc_budget); #endif unsigned result = hb_test_run (); diff --git a/test/api/test-draw.c b/test/api/test-draw.c index e12048cbb..a52ccb941 100644 --- a/test/api/test-draw.c +++ b/test/api/test-draw.c @@ -1075,6 +1075,132 @@ test_hb_draw_immutable (void) hb_draw_funcs_destroy (draw_funcs); } +typedef struct +{ + int64_t policy; + int64_t live; +} draw_budget_data_t; + +static hb_bool_t +draw_set_budget (hb_draw_funcs_t *dfuncs HB_UNUSED, + void *draw_data, + int64_t budget, + void *user_data HB_UNUSED) +{ + draw_budget_data_t *data = (draw_budget_data_t *) draw_data; + data->policy = budget; + data->live = budget == HB_BUDGET_DEFAULT ? 1234 : budget; + return TRUE; +} + +static int64_t +draw_get_budget (hb_draw_funcs_t *dfuncs HB_UNUSED, + void *draw_data, + void *user_data HB_UNUSED) +{ + return ((draw_budget_data_t *) draw_data)->policy; +} + +static int64_t * +draw_get_budget_remaining (hb_draw_funcs_t *dfuncs HB_UNUSED, + void *draw_data, + void *user_data HB_UNUSED) +{ + return &((draw_budget_data_t *) draw_data)->live; +} + +static int64_t +draw_budget_consumption (const char *font_file, + hb_codepoint_t glyph, + const hb_variation_t *variation) +{ + const int64_t budget = 100000; + draw_budget_data_t data = {HB_BUDGET_DEFAULT, 0}; + hb_draw_funcs_t *draw_funcs = hb_draw_funcs_create (); + hb_draw_funcs_set_set_budget_func (draw_funcs, draw_set_budget, NULL, NULL); + hb_draw_funcs_set_get_budget_func (draw_funcs, draw_get_budget, NULL, NULL); + hb_draw_funcs_set_get_budget_remaining_func (draw_funcs, draw_get_budget_remaining, NULL, NULL); + g_assert_true (hb_draw_set_budget (draw_funcs, &data, budget)); + + hb_face_t *face = hb_test_open_font_file (font_file); + hb_font_t *font = hb_font_create (face); + hb_face_destroy (face); + if (variation) + hb_font_set_variations (font, variation, 1); + + g_assert_true (hb_font_draw_glyph_or_fail (font, glyph, draw_funcs, &data)); + int64_t consumption = budget - data.live; + + hb_font_destroy (font); + hb_draw_funcs_destroy (draw_funcs); + + return consumption; +} + +static void +test_hb_draw_cff_budget (void) +{ + int64_t cff1_seac = draw_budget_consumption ("fonts/cff1_seac.otf", 3, NULL); + hb_variation_t variation = {HB_TAG ('w','g','h','t'), 800}; + int64_t cff2_blend = draw_budget_consumption ("fonts/AdobeVFPrototype.abc.otf", 3, &variation); + + /* These bounds exceed the parent charstring's flat operator cost, so they + * specifically cover the two seac children and the proportional blend. */ + g_assert_cmpint (cff1_seac, >, 100); + g_assert_cmpint (cff2_blend, >, 512); +} + +static void +test_hb_draw_budget (void) +{ + draw_budget_data_t data = {HB_BUDGET_DEFAULT, 1234}; + hb_draw_funcs_t *draw_funcs = hb_draw_funcs_create (); + + g_assert_false (hb_draw_set_budget (draw_funcs, &data, 100)); + g_assert_cmpint (hb_draw_get_budget (draw_funcs, &data), ==, HB_BUDGET_DEFAULT); + g_assert_cmpint (hb_draw_get_budget_remaining (draw_funcs, &data), ==, HB_BUDGET_UNLIMITED); + + hb_draw_funcs_set_set_budget_func (draw_funcs, draw_set_budget, NULL, NULL); + hb_draw_funcs_set_get_budget_func (draw_funcs, draw_get_budget, NULL, NULL); + hb_draw_funcs_set_get_budget_remaining_func (draw_funcs, draw_get_budget_remaining, NULL, NULL); + + g_assert_true (hb_draw_set_budget (draw_funcs, &data, -42)); + g_assert_cmpint (hb_draw_get_budget (draw_funcs, &data), ==, 0); + g_assert_cmpint (hb_draw_get_budget_remaining (draw_funcs, &data), ==, 0); + + g_assert_true (hb_draw_set_budget (draw_funcs, &data, HB_BUDGET_DEFAULT)); + g_assert_cmpint (hb_draw_get_budget (draw_funcs, &data), ==, HB_BUDGET_DEFAULT); + g_assert_cmpint (hb_draw_get_budget_remaining (draw_funcs, &data), ==, 1234); + + g_assert_true (hb_draw_set_budget (draw_funcs, &data, HB_BUDGET_UNLIMITED)); + g_assert_cmpint (hb_draw_get_budget (draw_funcs, &data), ==, HB_BUDGET_UNLIMITED); + g_assert_cmpint (hb_draw_get_budget_remaining (draw_funcs, &data), ==, HB_BUDGET_UNLIMITED); + + hb_face_t *face = hb_test_open_font_file ("fonts/glyphs.ttf"); + hb_font_t *font = hb_font_create (face); + + g_assert_true (hb_draw_set_budget (draw_funcs, &data, 100000)); + g_assert_true (hb_font_draw_glyph_or_fail (font, 0, draw_funcs, &data)); + g_assert_cmpint (hb_draw_get_budget (draw_funcs, &data), ==, 100000); + g_assert_cmpint (hb_draw_get_budget_remaining (draw_funcs, &data), <, 100000); + g_assert_cmpint (hb_draw_get_budget_remaining (draw_funcs, &data), >=, 0); + + g_assert_true (hb_draw_set_budget (draw_funcs, &data, HB_BUDGET_UNLIMITED)); + g_assert_true (hb_font_draw_glyph_or_fail (font, 0, draw_funcs, &data)); + g_assert_cmpint (hb_draw_get_budget (draw_funcs, &data), ==, HB_BUDGET_UNLIMITED); + g_assert_cmpint (hb_draw_get_budget_remaining (draw_funcs, &data), <, HB_BUDGET_UNLIMITED); + g_assert_cmpint (hb_draw_get_budget_remaining (draw_funcs, &data), >, 0); + + hb_font_set_synthetic_slant (font, 0.2f); + g_assert_true (hb_draw_set_budget (draw_funcs, &data, 1)); + g_assert_false (hb_font_draw_glyph_or_fail (font, 0, draw_funcs, &data)); + g_assert_cmpint (hb_draw_get_budget_remaining (draw_funcs, &data), <, 0); + + hb_font_destroy (font); + hb_face_destroy (face); + hb_draw_funcs_destroy (draw_funcs); +} + static void test_hb_draw_funcs (const void* user_data) { @@ -1190,6 +1316,8 @@ main (int argc, char **argv) hb_test_add (test_hb_draw_synthetic_slant); hb_test_add (test_hb_draw_subfont_scale); hb_test_add (test_hb_draw_immutable); + hb_test_add (test_hb_draw_budget); + hb_test_add (test_hb_draw_cff_budget); const char **font_funcs = hb_font_list_funcs (); for (const char **font_funcs_name = font_funcs; *font_funcs_name; font_funcs_name++) diff --git a/test/api/test-ft.c b/test/api/test-ft.c index e32e0b6a0..9415ffbc0 100644 --- a/test/api/test-ft.c +++ b/test/api/test-ft.c @@ -206,6 +206,51 @@ found: cleanup_freetype (); } +static gpointer +create_static_ft_faces (gpointer data) +{ + hb_blob_t *blob = (hb_blob_t *) data; + + for (unsigned int i = 0; i < 100; i++) + { + hb_face_t *face = hb_ft_face_create_from_blob_or_fail (blob, 0); + g_assert_nonnull (face); + + hb_font_t *font = hb_font_create (face); + hb_ft_font_set_funcs (font); + + hb_font_destroy (font); + hb_face_destroy (face); + } + + return NULL; +} + +static void +test_static_ft_library_multithreaded (void) +{ + hb_blob_t *blob; + GThread *threads[8]; + +#if GLIB_CHECK_VERSION(2,37,2) + char *path = g_test_build_filename (G_TEST_DIST, "fonts/adwaita.ttf", NULL); +#else + char *path = g_strdup ("fonts/adwaita.ttf"); +#endif + + blob = hb_blob_create_from_file_or_fail (path); + g_assert_nonnull (blob); + g_free (path); + + for (unsigned int i = 0; i < G_N_ELEMENTS (threads); i++) + threads[i] = g_thread_new (NULL, create_static_ft_faces, blob); + + for (unsigned int i = 0; i < G_N_ELEMENTS (threads); i++) + g_thread_join (threads[i]); + + hb_blob_destroy (blob); +} + int main (int argc, char **argv) { @@ -214,6 +259,7 @@ main (int argc, char **argv) hb_test_add (test_native_ft_basic); hb_test_add (test_native_ft_set_funcs_preserves_load_flags); hb_test_add (test_native_ft_glyph_name_zero_size_probe); + hb_test_add (test_static_ft_library_multithreaded); return hb_test_run (); } diff --git a/test/api/test-gpu.cc b/test/api/test-gpu.cc index c637c9039..ae18d3dde 100644 --- a/test/api/test-gpu.cc +++ b/test/api/test-gpu.cc @@ -176,6 +176,80 @@ test_reset (void) hb_face_destroy (face); } +static void +test_budget (void) +{ + hb_face_t *face = hb_test_open_font_file (FONT_FILE); + hb_font_t *font = hb_font_create (face); + hb_codepoint_t gid; + g_assert_true (hb_font_get_nominal_glyph (font, 'a', &gid)); + + hb_gpu_draw_t *draw = hb_gpu_draw_create_or_fail (); + hb_draw_funcs_t *draw_funcs = hb_gpu_draw_get_funcs (draw); + g_assert_cmpint (hb_draw_get_budget (draw_funcs, draw), ==, HB_BUDGET_DEFAULT); + g_assert_cmpint (hb_draw_get_budget_remaining (draw_funcs, draw), >, 0); + g_assert_cmpint (hb_draw_get_budget_remaining (draw_funcs, draw), <, HB_BUDGET_UNLIMITED); + + g_assert_true (hb_draw_set_budget (draw_funcs, draw, 1)); + hb_gpu_draw_glyph (draw, font, gid); + g_assert_cmpint (hb_draw_get_budget_remaining (draw_funcs, draw), <, 0); + hb_gpu_draw_clear (draw); + g_assert_cmpint (hb_draw_get_budget (draw_funcs, draw), ==, 1); + g_assert_cmpint (hb_draw_get_budget_remaining (draw_funcs, draw), ==, 1); + + hb_draw_state_t draw_state = HB_DRAW_STATE_DEFAULT; + hb_draw_move_to (draw_funcs, draw, &draw_state, 0.f, 0.f); + hb_draw_line_to (draw_funcs, draw, &draw_state, 1.f, 0.f); + g_assert_cmpint (hb_draw_get_budget_remaining (draw_funcs, draw), ==, 0); + hb_draw_line_to (draw_funcs, draw, &draw_state, 2.f, 0.f); + g_assert_cmpint (hb_draw_get_budget_remaining (draw_funcs, draw), <, 0); + + hb_gpu_draw_clear (draw); + g_assert_cmpint (hb_draw_get_budget_remaining (draw_funcs, draw), ==, 1); + hb_gpu_draw_reset (draw); + g_assert_cmpint (hb_draw_get_budget (draw_funcs, draw), ==, HB_BUDGET_DEFAULT); + g_assert_cmpint (hb_draw_get_budget_remaining (draw_funcs, draw), >, 0); + + hb_gpu_paint_t *paint = hb_gpu_paint_create_or_fail (); + hb_paint_funcs_t *paint_funcs = hb_gpu_paint_get_funcs (paint); + g_assert_cmpint (hb_paint_get_budget (paint_funcs, paint), ==, HB_BUDGET_DEFAULT); + g_assert_cmpint (hb_paint_get_budget_remaining (paint_funcs, paint), >, 0); + g_assert_cmpint (hb_paint_get_budget_remaining (paint_funcs, paint), <, HB_BUDGET_UNLIMITED); + + /* Identity clip extraction must borrow the paint session counter. */ + g_assert_true (hb_paint_set_budget (paint_funcs, paint, 1)); + hb_paint_push_clip_glyph (paint_funcs, paint, gid, font); + hb_paint_color (paint_funcs, paint, false, HB_COLOR (0, 0, 0, 255)); + hb_paint_pop_clip (paint_funcs, paint); + g_assert_cmpint (hb_paint_get_budget_remaining (paint_funcs, paint), <, 0); + + hb_gpu_paint_clear (paint); + g_assert_cmpint (hb_paint_get_budget (paint_funcs, paint), ==, 1); + g_assert_cmpint (hb_paint_get_budget_remaining (paint_funcs, paint), ==, 1); + + /* The transforming pen must expose that same live counter. */ + hb_paint_push_transform (paint_funcs, paint, 2.f, 0.f, 0.f, 2.f, 0.f, 0.f); + hb_paint_push_clip_glyph (paint_funcs, paint, gid, font); + hb_paint_pop_transform (paint_funcs, paint); + hb_paint_color (paint_funcs, paint, false, HB_COLOR (0, 0, 0, 255)); + hb_paint_pop_clip (paint_funcs, paint); + g_assert_cmpint (hb_paint_get_budget_remaining (paint_funcs, paint), <, 0); + + hb_gpu_paint_reset (paint); + g_assert_cmpint (hb_paint_get_budget (paint_funcs, paint), ==, HB_BUDGET_DEFAULT); + g_assert_cmpint (hb_paint_get_budget_remaining (paint_funcs, paint), >, 0); + + g_assert_true (hb_draw_set_budget (draw_funcs, draw, HB_BUDGET_UNLIMITED)); + g_assert_cmpint (hb_draw_get_budget_remaining (draw_funcs, draw), ==, HB_BUDGET_UNLIMITED); + g_assert_true (hb_paint_set_budget (paint_funcs, paint, HB_BUDGET_UNLIMITED)); + g_assert_cmpint (hb_paint_get_budget_remaining (paint_funcs, paint), ==, HB_BUDGET_UNLIMITED); + + hb_gpu_paint_destroy (paint); + hb_gpu_draw_destroy (draw); + hb_font_destroy (font); + hb_face_destroy (face); +} + static void test_draw_funcs (void) { @@ -834,6 +908,7 @@ main (int argc, char **argv) hb_test_add (test_empty_encode); hb_test_add (test_encode_glyph); hb_test_add (test_reset); + hb_test_add (test_budget); hb_test_add (test_draw_funcs); hb_test_add (test_shader_sources); hb_test_add (test_encode_quantizes_extents_outward); diff --git a/test/api/test-ot-face.c b/test/api/test-ot-face.c index 37c2be127..30e474543 100644 --- a/test/api/test-ot-face.c +++ b/test/api/test-ot-face.c @@ -216,6 +216,37 @@ test_ot_var_axis_on_zero_named_instance (void) } #ifndef HB_NO_VERTICAL +static void +test_ot_font_v_origin_extents_overflow (void) +{ + static const char data[] = { + 0x00, 0x01, 0x00, 0x00, 0x00, 0x05, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x43, 0x4f, 0x4c, 0x52, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x09, + 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x10, 0x00, 0x00, + 0x00, 0x22, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, + 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x11, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x0c, + 0x00, 0x00, 0x17, 0x00, 0x00, 0x02, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + (char) 0xff, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x1d, 0x00, + 0x00, 0x04, 0x20, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x04, 0x03, 0x20, + 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00 + }; + hb_blob_t *blob = hb_blob_create (data, sizeof (data), HB_MEMORY_MODE_READONLY, + NULL, NULL); + hb_face_t *face = hb_face_create (blob, 0); + hb_font_t *font = hb_font_create (face); + hb_position_t x, y; + + hb_font_set_scale (font, 12, 12); + g_assert_true (hb_font_get_glyph_v_origin (font, 0, &x, &y)); + g_assert_cmpint (y, ==, -1073741719); + + hb_font_destroy (font); + hb_face_destroy (face); + hb_blob_destroy (blob); +} + static void test_ot_font_v_origin_cache_invalidated_by_scale (void) { @@ -247,6 +278,7 @@ main (int argc, char **argv) hb_test_add (test_ot_face_empty); hb_test_add (test_ot_var_axis_on_zero_named_instance); #ifndef HB_NO_VERTICAL + hb_test_add (test_ot_font_v_origin_extents_overflow); hb_test_add (test_ot_font_v_origin_cache_invalidated_by_scale); #endif diff --git a/test/api/test-paint.c b/test/api/test-paint.c index fb829c809..8fb676b6b 100644 --- a/test/api/test-paint.c +++ b/test/api/test-paint.c @@ -911,6 +911,73 @@ test_color_glyph_user_data (void) hb_paint_funcs_destroy (funcs); } +typedef struct +{ + int64_t policy; + int64_t live; +} paint_budget_data_t; + +static hb_bool_t +paint_set_budget (hb_paint_funcs_t *funcs HB_UNUSED, + void *paint_data, + int64_t budget, + void *user_data HB_UNUSED) +{ + paint_budget_data_t *data = (paint_budget_data_t *) paint_data; + data->policy = budget; + data->live = budget == HB_BUDGET_DEFAULT ? 4321 : budget; + return TRUE; +} + +static int64_t +paint_get_budget (hb_paint_funcs_t *funcs HB_UNUSED, + void *paint_data, + void *user_data HB_UNUSED) +{ + return ((paint_budget_data_t *) paint_data)->policy; +} + +static int64_t * +paint_get_budget_remaining (hb_paint_funcs_t *funcs HB_UNUSED, + void *paint_data, + void *user_data HB_UNUSED) +{ + return &((paint_budget_data_t *) paint_data)->live; +} + +static void +test_hb_paint_budget (void) +{ + paint_budget_data_t data = {HB_BUDGET_DEFAULT, 4321}; + hb_paint_funcs_t *funcs = hb_paint_funcs_create (); + + g_assert_false (hb_paint_set_budget (funcs, &data, 100)); + g_assert_cmpint (hb_paint_get_budget (funcs, &data), ==, HB_BUDGET_DEFAULT); + g_assert_cmpint (hb_paint_get_budget_remaining (funcs, &data), ==, HB_BUDGET_UNLIMITED); + + hb_paint_funcs_set_set_budget_func (funcs, paint_set_budget, NULL, NULL); + hb_paint_funcs_set_get_budget_func (funcs, paint_get_budget, NULL, NULL); + hb_paint_funcs_set_get_budget_remaining_func (funcs, paint_get_budget_remaining, NULL, NULL); + + g_assert_true (hb_paint_set_budget (funcs, &data, -7)); + g_assert_cmpint (hb_paint_get_budget (funcs, &data), ==, 0); + g_assert_cmpint (hb_paint_get_budget_remaining (funcs, &data), ==, 0); + + g_assert_true (hb_paint_set_budget (funcs, &data, HB_BUDGET_DEFAULT)); + g_assert_cmpint (hb_paint_get_budget (funcs, &data), ==, HB_BUDGET_DEFAULT); + g_assert_cmpint (hb_paint_get_budget_remaining (funcs, &data), ==, 4321); + + g_assert_true (hb_paint_set_budget (funcs, &data, 9876)); + g_assert_cmpint (hb_paint_get_budget (funcs, &data), ==, 9876); + g_assert_cmpint (hb_paint_get_budget_remaining (funcs, &data), ==, 9876); + + g_assert_true (hb_paint_set_budget (funcs, &data, HB_BUDGET_UNLIMITED)); + g_assert_cmpint (hb_paint_get_budget (funcs, &data), ==, HB_BUDGET_UNLIMITED); + g_assert_cmpint (hb_paint_get_budget_remaining (funcs, &data), ==, HB_BUDGET_UNLIMITED); + + hb_paint_funcs_destroy (funcs); +} + int main (int argc, char **argv) @@ -925,6 +992,7 @@ main (int argc, char **argv) hb_test_add (test_push_clip_path_round_trip); hb_test_add (test_fill_glyph_nil_decomposes); hb_test_add (test_color_glyph_user_data); + hb_test_add (test_hb_paint_budget); for (unsigned int i = 0; i < G_N_ELEMENTS (paint_tests); i++) { diff --git a/test/api/test-raster.cc b/test/api/test-raster.cc index f82f91583..9a87614d4 100644 --- a/test/api/test-raster.cc +++ b/test/api/test-raster.cc @@ -286,6 +286,101 @@ test_set_glyph_extents_overflow (void) hb_raster_paint_destroy (paint); } +/* ── Test 8: shared work-budget lifecycle ───────────────────────── */ + +static void +test_budget (void) +{ + hb_face_t *face = hb_test_open_font_file ("fonts/glyphs.ttf"); + hb_font_t *font = hb_font_create (face); + + hb_raster_draw_t *draw = hb_raster_draw_create_or_fail (); + hb_draw_funcs_t *draw_funcs = hb_raster_draw_get_funcs (draw); + g_assert_cmpint (hb_draw_get_budget (draw_funcs, draw), ==, HB_BUDGET_DEFAULT); + g_assert_cmpint (hb_draw_get_budget_remaining (draw_funcs, draw), >, 0); + g_assert_cmpint (hb_draw_get_budget_remaining (draw_funcs, draw), <, HB_BUDGET_UNLIMITED); + + g_assert_true (hb_draw_set_budget (draw_funcs, draw, 1)); + hb_raster_draw_glyph (draw, font, 0); + g_assert_cmpint (hb_draw_get_budget_remaining (draw_funcs, draw), <, 0); + hb_raster_draw_clear (draw); + g_assert_cmpint (hb_draw_get_budget (draw_funcs, draw), ==, 1); + g_assert_cmpint (hb_draw_get_budget_remaining (draw_funcs, draw), ==, 1); + hb_raster_draw_reset (draw); + g_assert_cmpint (hb_draw_get_budget (draw_funcs, draw), ==, HB_BUDGET_DEFAULT); + g_assert_cmpint (hb_draw_get_budget_remaining (draw_funcs, draw), >, 0); + + hb_raster_paint_t *paint = hb_raster_paint_create_or_fail (); + hb_paint_funcs_t *paint_funcs = hb_raster_paint_get_funcs (paint); + g_assert_cmpint (hb_paint_get_budget (paint_funcs, paint), ==, HB_BUDGET_DEFAULT); + g_assert_cmpint (hb_paint_get_budget_remaining (paint_funcs, paint), >, 0); + g_assert_cmpint (hb_paint_get_budget_remaining (paint_funcs, paint), <, HB_BUDGET_UNLIMITED); + + hb_raster_extents_t extents = {0, 0, 1, 1, 0}; + hb_raster_paint_set_extents (paint, &extents); + g_assert_true (hb_paint_set_budget (paint_funcs, paint, 2)); + hb_raster_paint_glyph (paint, font, 0); + g_assert_cmpint (hb_paint_get_budget_remaining (paint_funcs, paint), <, 0); + hb_raster_paint_clear (paint); + g_assert_cmpint (hb_paint_get_budget (paint_funcs, paint), ==, 2); + g_assert_cmpint (hb_paint_get_budget_remaining (paint_funcs, paint), ==, 2); + hb_raster_paint_reset (paint); + g_assert_cmpint (hb_paint_get_budget (paint_funcs, paint), ==, HB_BUDGET_DEFAULT); + g_assert_cmpint (hb_paint_get_budget_remaining (paint_funcs, paint), >, 0); + + g_assert_true (hb_draw_set_budget (draw_funcs, draw, HB_BUDGET_UNLIMITED)); + g_assert_cmpint (hb_draw_get_budget_remaining (draw_funcs, draw), ==, HB_BUDGET_UNLIMITED); + g_assert_true (hb_paint_set_budget (paint_funcs, paint, HB_BUDGET_UNLIMITED)); + g_assert_cmpint (hb_paint_get_budget_remaining (paint_funcs, paint), ==, HB_BUDGET_UNLIMITED); + + hb_raster_paint_destroy (paint); + hb_raster_draw_destroy (draw); + hb_font_destroy (font); + hb_face_destroy (face); +} + +/* ── Test 9: outline budget bounds a real COLR walk, apart from pixels ─ */ + +/* The paint session's outline and pixel budgets are separate. A 1x1 + * surface makes the pixel budget effectively unbounded, so only the + * outline budget can bound a multi-layer COLR glyph here -- which + * requires the outline work of every layer to aggregate into one counter + * through the public seed/readback transfer. A broken transfer (no + * readback, or a re-armed counter) would leave the budget positive. */ +static void +test_budget_colr_outline (void) +{ + hb_face_t *face = hb_test_open_font_file ("fonts/COLRv0.extents.ttf"); + hb_font_t *font = hb_font_create (face); + const hb_codepoint_t colr_glyph = 13; /* 5 COLR layers */ + hb_raster_extents_t extents = {0, 0, 1, 1, 0}; + + /* Large outline budget: the walk completes, and real outline work is + * charged back (the counter drops below the configured cap). */ + hb_raster_paint_t *paint = hb_raster_paint_create_or_fail (); + hb_paint_funcs_t *funcs = hb_raster_paint_get_funcs (paint); + hb_raster_paint_set_extents (paint, &extents); + g_assert_true (hb_paint_set_budget (funcs, paint, 1 << 20)); + hb_raster_paint_glyph (paint, font, colr_glyph); + int64_t remaining = hb_paint_get_budget_remaining (funcs, paint); + g_assert_cmpint (remaining, <, 1 << 20); /* outline work aggregated back */ + g_assert_cmpint (remaining, >=, 0); /* not depleted at this budget */ + hb_raster_paint_destroy (paint); + + /* Tiny outline budget: the aggregate walk is bounded by it, not by the + * (unbounded) pixel budget of the 1x1 surface. */ + paint = hb_raster_paint_create_or_fail (); + funcs = hb_raster_paint_get_funcs (paint); + hb_raster_paint_set_extents (paint, &extents); + g_assert_true (hb_paint_set_budget (funcs, paint, 1)); + hb_raster_paint_glyph (paint, font, colr_glyph); + g_assert_cmpint (hb_paint_get_budget_remaining (funcs, paint), <, 0); + hb_raster_paint_destroy (paint); + + hb_font_destroy (font); + hb_face_destroy (face); +} + /* ── main ────────────────────────────────────────────────────────── */ int @@ -300,6 +395,8 @@ main (int argc, char **argv) hb_test_add (test_set_glyph_extents_with_transform); hb_test_add (test_image_nonfinite_transform); hb_test_add (test_set_glyph_extents_overflow); + hb_test_add (test_budget); + hb_test_add (test_budget_colr_outline); return hb_test_run (); } diff --git a/test/api/test-set.c b/test/api/test-set.c index 9264c6d36..c03af6dc3 100644 --- a/test/api/test-set.c +++ b/test/api/test-set.c @@ -1312,12 +1312,85 @@ test_set_next_many_out_of_order_pages (void) { hb_set_destroy(set); } +static void +test_set_next_previous_range (void) +{ + hb_set_t *s = hb_set_create (); + + /* Test with ranges covering: + * - 0..0 (single element at 0) + * - 2..3 (small range within word 0) + * - 60..70 (spans 64-bit word boundary 0 -> 1) + * - 127..127 (single element at word boundary) + * - 129..130 (starts after word boundary) + * - 500..525 (spans 512-bit page boundary 0 -> 1) + * - 1000..3000 (spans multiple full pages) + * - 50000..50000 (isolated high codepoint) + */ + hb_set_add (s, 0); + /* gap: 1 */ + hb_set_add_range (s, 2, 3); + /* gap: 4..59 */ + hb_set_add_range (s, 60, 70); + /* gap: 71..126 */ + hb_set_add (s, 127); + /* gap: 128 */ + hb_set_add_range (s, 129, 130); + /* gap: 131..499 */ + hb_set_add_range (s, 500, 525); + /* gap: 526..999 */ + hb_set_add_range (s, 1000, 3000); + /* gap: 3001..49999 */ + hb_set_add (s, 50000); + + struct { hb_codepoint_t first, last; } expected[] = { + {0, 0}, + {2, 3}, + {60, 70}, + {127, 127}, + {129, 130}, + {500, 525}, + {1000, 3000}, + {50000, 50000} + }; + unsigned int num_expected = sizeof (expected) / sizeof (expected[0]); + + /* Forward iteration */ + hb_codepoint_t first = HB_SET_VALUE_INVALID; + hb_codepoint_t last = HB_SET_VALUE_INVALID; + for (unsigned int idx = 0; idx < num_expected; idx++) + { + g_assert_true (hb_set_next_range (s, &first, &last)); + g_assert_cmpint (first, ==, expected[idx].first); + g_assert_cmpint (last, ==, expected[idx].last); + } + g_assert_true (!hb_set_next_range (s, &first, &last)); + g_assert_cmpint (first, ==, HB_SET_VALUE_INVALID); + g_assert_cmpint (last, ==, HB_SET_VALUE_INVALID); + + /* Backward iteration */ + first = HB_SET_VALUE_INVALID; + last = HB_SET_VALUE_INVALID; + for (int idx = (int) num_expected - 1; idx >= 0; idx--) + { + g_assert_true (hb_set_previous_range (s, &first, &last)); + g_assert_cmpint (first, ==, expected[idx].first); + g_assert_cmpint (last, ==, expected[idx].last); + } + g_assert_true (!hb_set_previous_range (s, &first, &last)); + g_assert_cmpint (first, ==, HB_SET_VALUE_INVALID); + g_assert_cmpint (last, ==, HB_SET_VALUE_INVALID); + + hb_set_destroy (s); +} + int main (int argc, char **argv) { hb_test_init (&argc, &argv); hb_test_add (test_set_basic); + hb_test_add (test_set_next_previous_range); hb_test_add (test_set_subsets); hb_test_add (test_set_subsets_empty_pages); hb_test_add (test_set_subsets_inverted); diff --git a/test/fuzzing/fonts/1365781b41cb64df3676cf79dd9f11f783facfe3 b/test/fuzzing/fonts/1365781b41cb64df3676cf79dd9f11f783facfe3 new file mode 100644 index 000000000..82ab1132a Binary files /dev/null and b/test/fuzzing/fonts/1365781b41cb64df3676cf79dd9f11f783facfe3 differ diff --git a/test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-gpu-fuzzer-5336988644081664 b/test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-gpu-fuzzer-5336988644081664 new file mode 100644 index 000000000..aef09f1f9 Binary files /dev/null and b/test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-gpu-fuzzer-5336988644081664 differ diff --git a/test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-raster-fuzzer-6328536122851328 b/test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-raster-fuzzer-6328536122851328 new file mode 100644 index 000000000..ab8d18173 Binary files /dev/null and b/test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-raster-fuzzer-6328536122851328 differ diff --git a/test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-repacker-fuzzer-5009721206833152 b/test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-repacker-fuzzer-5009721206833152 new file mode 100644 index 000000000..e33839c31 Binary files /dev/null and b/test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-repacker-fuzzer-5009721206833152 differ diff --git a/test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-vector-fuzzer-4886959609413632 b/test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-vector-fuzzer-4886959609413632 new file mode 100644 index 000000000..8d5f51323 Binary files /dev/null and b/test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-vector-fuzzer-4886959609413632 differ diff --git a/test/shape/data/aots/tests/gsub4_1_multiple_ligatures.tests b/test/shape/data/aots/tests/gsub4_1_multiple_ligatures.tests index 447db5f71..6d124cf41 100644 --- a/test/shape/data/aots/tests/gsub4_1_multiple_ligatures.tests +++ b/test/shape/data/aots/tests/gsub4_1_multiple_ligatures.tests @@ -1,3 +1,5 @@ @shaper=ot ../fonts/gsub4_1_multiple_ligatures_f1.otf;--features="test" --single-par --no-clusters --no-glyph-names --no-positions;U+0011,U+0012,U+0013,U+0014,U+0011,U+0012,U+0013,U+0016,U+0014;[17|23|17|24|22|20] ../fonts/gsub4_1_multiple_ligatures_f2.otf;--features="test" --single-par --no-clusters --no-glyph-names --no-positions;U+0011,U+0012,U+0013,U+0014,U+0011,U+0012,U+0013,U+0016,U+0014;[17|24|20|17|24|22|20] +../fonts/gsub4_1_multiple_ligatures_f1.otf;--features="test" --no-clusters --no-glyph-names --no-positions --show-flags --unsafe-to-concat;U+0012,U+0015;[18#2|21#2] +../fonts/gsub4_1_multiple_ligatures_f2.otf;--features="test" --no-clusters --no-glyph-names --no-positions --show-flags --unsafe-to-concat;U+0012,U+0015;[18#2|21#2] diff --git a/test/shape/data/in-house/fonts/3113f846b81ea15c02e05a1c14fa65f9fd342143.otf b/test/shape/data/in-house/fonts/3113f846b81ea15c02e05a1c14fa65f9fd342143.otf new file mode 100644 index 000000000..0f42c843a Binary files /dev/null and b/test/shape/data/in-house/fonts/3113f846b81ea15c02e05a1c14fa65f9fd342143.otf differ diff --git a/test/shape/data/in-house/fonts/c70495f304286cb87964400d03752ae5bc5622b9.ttf b/test/shape/data/in-house/fonts/c70495f304286cb87964400d03752ae5bc5622b9.ttf new file mode 100644 index 000000000..44a494fb5 Binary files /dev/null and b/test/shape/data/in-house/fonts/c70495f304286cb87964400d03752ae5bc5622b9.ttf differ diff --git a/test/shape/data/in-house/tests/mongolian-variation-selector.tests b/test/shape/data/in-house/tests/mongolian-variation-selector.tests index 35b4701ef..ac042c8a1 100644 --- a/test/shape/data/in-house/tests/mongolian-variation-selector.tests +++ b/test/shape/data/in-house/tests/mongolian-variation-selector.tests @@ -4,6 +4,8 @@ ../fonts/4d4206e30b2dbf1c1ef492a8eae1c9e7829ebad8.ttf;;U+183A,U+1823,U+182E,U+182B,U+1822,U+1826,U+180B,U+1832,U+180B,U+1827,U+1837;[uni183A1823.E971_ko.init=0+950|uni182E.E904_m.medi=2+400|uni182B1822.E8A6_pi.medi=3+1150|uni1826.E854_ue.medi1=5+1100|uni1832.E916_t.medi1=7+1000|uni1827.E85C_ee.medi=9+750|uni1837.E931_r.fina=10+750] ../fonts/4d4206e30b2dbf1c1ef492a8eae1c9e7829ebad8.ttf;;U+182D,U+182D,U+180B;[uni182D.E8E2_g.init=0+1000|uni182D.E8E8_g.fina1=1+1250] ../fonts/4d4206e30b2dbf1c1ef492a8eae1c9e7829ebad8.ttf;;U+182D,U+180C;[uni182D.EA1B_g.isol2=0+1000] +../fonts/4d4206e30b2dbf1c1ef492a8eae1c9e7829ebad8.ttf;;U+182D,U+180F;[uni182D.E8E0_g.isol=0+950|space=0+0] +../fonts/4d4206e30b2dbf1c1ef492a8eae1c9e7829ebad8.ttf;;U+182D,U+1810;[uni182D.E8E0_g.isol=0+950|.notdef=1+1200] ../fonts/4d4206e30b2dbf1c1ef492a8eae1c9e7829ebad8.ttf;;U+182D,U+180D,U+200D;[uni182D.EA1E_g.init3=0+650|space=0+0] ../fonts/4d4206e30b2dbf1c1ef492a8eae1c9e7829ebad8.ttf;;U+182D,U+200D,U+182D,U+180B,U+200D;[uni182D.E8E2_g.init=0+1000|space=0+0|uni182D.E8E5_g.medi1=2+800|space=2+0] ../fonts/4d4206e30b2dbf1c1ef492a8eae1c9e7829ebad8.ttf;;U+182D,U+180C,U+200D;[uni182D.EA1D_g.init2=0+950|space=0+0] diff --git a/test/shape/data/in-house/tests/unsafe-to-concat.tests b/test/shape/data/in-house/tests/unsafe-to-concat.tests index 64381a3a5..81ae26e36 100644 --- a/test/shape/data/in-house/tests/unsafe-to-concat.tests +++ b/test/shape/data/in-house/tests/unsafe-to-concat.tests @@ -1 +1,4 @@ ../fonts/34da9aab7bee86c4dfc3b85e423435822fdf4b62.ttf;--show-flags --unsafe-to-concat;U+0628,U+200C,U+0628;[uni0628=1+993#2|uni0628=0+993#2] +../fonts/3113f846b81ea15c02e05a1c14fa65f9fd342143.otf;--features=test --no-glyph-names --no-positions --no-clusters --show-flags --unsafe-to-concat;U+0042,U+0041,U+0058,U+0042;[66|65#2|88#2|66] +../fonts/c70495f304286cb87964400d03752ae5bc5622b9.ttf;--features=ctxt --no-glyph-names --no-positions --no-clusters --show-flags --unsafe-to-concat;U+0041;[1#2] +../fonts/c70495f304286cb87964400d03752ae5bc5622b9.ttf;--features=chne --no-glyph-names --no-positions --no-clusters --show-flags --unsafe-to-concat;U+0041;[1#2] diff --git a/test/subset/data/expected/subset_base_v1/NotoSansJP_subset.retain-base-table-filter-scripts.all.ttf b/test/subset/data/expected/subset_base_v1/NotoSansJP_subset.retain-base-table-filter-scripts.all.ttf new file mode 100644 index 000000000..9267aae9b Binary files /dev/null and b/test/subset/data/expected/subset_base_v1/NotoSansJP_subset.retain-base-table-filter-scripts.all.ttf differ diff --git a/test/subset/data/expected/subset_base_v1/NotoSansJP_subset.retain-base-table.all.ttf b/test/subset/data/expected/subset_base_v1/NotoSansJP_subset.retain-base-table.all.ttf new file mode 100644 index 000000000..862048f11 Binary files /dev/null and b/test/subset/data/expected/subset_base_v1/NotoSansJP_subset.retain-base-table.all.ttf differ diff --git a/test/subset/data/fonts/NotoSansJP_subset.ttf b/test/subset/data/fonts/NotoSansJP_subset.ttf new file mode 100644 index 000000000..862048f11 Binary files /dev/null and b/test/subset/data/fonts/NotoSansJP_subset.ttf differ diff --git a/test/subset/data/tests/subset_base_v1.tests b/test/subset/data/tests/subset_base_v1.tests new file mode 100644 index 000000000..a7f5c86b9 --- /dev/null +++ b/test/subset/data/tests/subset_base_v1.tests @@ -0,0 +1,15 @@ +FONTS: +NotoSansJP_subset.ttf + +PROFILES: +retain-base-table.txt +retain-base-table-filter-scripts.txt + +SUBSETS: +* + +# diff with fonttools +# BASE table(fonttools doesn't support BASE table) +OPTIONS: +no_fonttools + diff --git a/test/subset/meson.build b/test/subset/meson.build index 3d75bd961..0c0e3abc5 100644 --- a/test/subset/meson.build +++ b/test/subset/meson.build @@ -46,6 +46,7 @@ tests = [ 'math', 'math_coverage_offset', 'subset_base', + 'subset_base_v1', # TODO: re-enable once colrv1 subsetting is stabilized. # 'colrv1.notoemoji', 'colrv1', diff --git a/test/vector/meson.build b/test/vector/meson.build index 8247aecfe..dcbf02003 100644 --- a/test/vector/meson.build +++ b/test/vector/meson.build @@ -1,5 +1,14 @@ run_test = find_program('run-tests.py') +test_vector_budget = executable('test-vector-budget', 'test-vector-budget.c', + dependencies: [libharfbuzz_vector_dep], +) + +test('budget', test_vector_budget, + args: [meson.project_source_root() / 'test' / 'api' / 'fonts' / 'glyphs.ttf'], + suite: 'vector', +) + tests = [ 'basic', 'varc', diff --git a/test/vector/test-vector-budget.c b/test/vector/test-vector-budget.c new file mode 100644 index 000000000..d1c80e020 --- /dev/null +++ b/test/vector/test-vector-budget.c @@ -0,0 +1,149 @@ +/* + * Copyright © 2026 Behdad Esfahbod + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + */ + +#ifdef NDEBUG +#undef NDEBUG +#endif +#include +#include + +#include +#include + +static void +test_format (hb_vector_format_t format, hb_font_t *font) +{ + hb_vector_draw_t *draw = hb_vector_draw_create_or_fail (format); + hb_vector_paint_t *paint = hb_vector_paint_create_or_fail (format); + assert (draw); + assert (paint); + + hb_draw_funcs_t *draw_funcs = hb_vector_draw_get_funcs (draw); + hb_paint_funcs_t *paint_funcs = hb_vector_paint_get_funcs (paint); + + assert (hb_draw_get_budget (draw_funcs, draw) == HB_BUDGET_DEFAULT); + assert (hb_draw_get_budget_remaining (draw_funcs, draw) > 0); + assert (hb_draw_get_budget_remaining (draw_funcs, draw) < HB_BUDGET_UNLIMITED); + assert (hb_paint_get_budget (paint_funcs, paint) == HB_BUDGET_DEFAULT); + assert (hb_paint_get_budget_remaining (paint_funcs, paint) > 0); + assert (hb_paint_get_budget_remaining (paint_funcs, paint) < HB_BUDGET_UNLIMITED); + + assert (hb_draw_set_budget (draw_funcs, draw, 1)); + hb_vector_draw_glyph (draw, font, 0, HB_VECTOR_EXTENTS_MODE_NONE); + assert (hb_draw_get_budget_remaining (draw_funcs, draw) < 0); + hb_vector_draw_clear (draw); + assert (hb_draw_get_budget (draw_funcs, draw) == 1); + assert (hb_draw_get_budget_remaining (draw_funcs, draw) == 1); + hb_vector_draw_reset (draw); + assert (hb_draw_get_budget (draw_funcs, draw) == HB_BUDGET_DEFAULT); + assert (hb_draw_get_budget_remaining (draw_funcs, draw) > 0); + + assert (hb_paint_set_budget (paint_funcs, paint, 1)); + hb_vector_paint_glyph (paint, font, 0, HB_VECTOR_EXTENTS_MODE_NONE); + assert (hb_paint_get_budget_remaining (paint_funcs, paint) < 0); + hb_vector_paint_clear (paint); + assert (hb_paint_get_budget (paint_funcs, paint) == 1); + assert (hb_paint_get_budget_remaining (paint_funcs, paint) == 1); + hb_vector_paint_reset (paint); + assert (hb_paint_get_budget (paint_funcs, paint) == HB_BUDGET_DEFAULT); + assert (hb_paint_get_budget_remaining (paint_funcs, paint) > 0); + + assert (hb_draw_set_budget (draw_funcs, draw, HB_BUDGET_UNLIMITED)); + assert (hb_draw_get_budget (draw_funcs, draw) == HB_BUDGET_UNLIMITED); + assert (hb_draw_get_budget_remaining (draw_funcs, draw) == HB_BUDGET_UNLIMITED); + assert (hb_paint_set_budget (paint_funcs, paint, HB_BUDGET_UNLIMITED)); + assert (hb_paint_get_budget (paint_funcs, paint) == HB_BUDGET_UNLIMITED); + assert (hb_paint_get_budget_remaining (paint_funcs, paint) == HB_BUDGET_UNLIMITED); + + hb_vector_draw_destroy (draw); + hb_vector_paint_destroy (paint); +} + +/* Embedded bitmaps are not outline work, so their base64 output is bounded + * by the document-size cap, not the outline budget: painting an oversized + * image must keep the serialized document bounded instead of ballooning + * with the image. Exercised through SVG, whose image path base64-embeds + * the raw blob directly; PDF assembles its whole document through the same + * capped buffer (hb_vector_buf_t), but validates the PNG, so a bogus blob + * cannot drive it here. */ +static void +test_document_cap (void) +{ + hb_vector_paint_t *paint = hb_vector_paint_create_or_fail (HB_VECTOR_FORMAT_SVG); + hb_paint_funcs_t *funcs = hb_vector_paint_get_funcs (paint); + + unsigned len = 40u << 20; /* 40 MB, well past the 16 MB cap */ + char *data = (char *) calloc (len, 1); + assert (data); + hb_blob_t *image = hb_blob_create (data, len, HB_MEMORY_MODE_READONLY, data, free); + + hb_glyph_extents_t ext = {0, 100, 100, -100}; + hb_vector_paint_set_glyph_extents (paint, &ext); + hb_paint_image (funcs, paint, image, 100, 100, + HB_PAINT_IMAGE_FORMAT_PNG, 0.f, &ext); + + hb_blob_t *out = hb_vector_paint_render (paint); + /* The cap either makes render refuse the over-budget document (null) or + * bounds its size; either way it must not balloon to the base64 of the + * whole 40 MB image (~53 MB), which is what an uncapped buffer produces. */ + assert (!out || hb_blob_get_length (out) < (32u << 20)); + hb_blob_destroy (out); + hb_blob_destroy (image); + + /* Reusing the context after an over-cap glyph must recover: the sticky + * overflow flag has to be cleared, or every later render fails forever. */ + hb_vector_paint_clear (paint); + hb_vector_paint_set_glyph_extents (paint, &ext); + unsigned small_len = 12; + char *small = (char *) calloc (small_len, 1); + assert (small); + hb_blob_t *small_image = hb_blob_create (small, small_len, HB_MEMORY_MODE_READONLY, small, free); + hb_paint_image (funcs, paint, small_image, 4, 3, + HB_PAINT_IMAGE_FORMAT_PNG, 0.f, &ext); + hb_blob_t *out2 = hb_vector_paint_render (paint); + assert (out2); + hb_blob_destroy (out2); + hb_blob_destroy (small_image); + + hb_vector_paint_destroy (paint); +} + +int +main (int argc, char **argv) +{ + assert (argc == 2); + hb_blob_t *blob = hb_blob_create_from_file_or_fail (argv[1]); + assert (blob); + hb_face_t *face = hb_face_create (blob, 0); + hb_font_t *font = hb_font_create (face); + + test_format (HB_VECTOR_FORMAT_SVG, font); + test_format (HB_VECTOR_FORMAT_PDF, font); + test_document_cap (); + + hb_font_destroy (font); + hb_face_destroy (face); + hb_blob_destroy (blob); + return 0; +} diff --git a/util/options.hh b/util/options.hh index 83cef2563..233cd67b0 100644 --- a/util/options.hh +++ b/util/options.hh @@ -285,6 +285,12 @@ inline bool option_parser_t::parse (int *argc, char ***argv, bool ignore_error) { setlocale (LC_ALL, ""); + /* Parse numbers with a '.' radix regardless of the environment's + * LC_NUMERIC. Options like --font-size, --margin and --font-extents + * read floats with sscanf("%lf"), which otherwise mis-parses e.g. + * "10.5" as 10 under a comma-radix locale. This matches the ascii + * number handling already used for --width via g_ascii_strtod. */ + setlocale (LC_NUMERIC, "C"); add_exit_code (RETURN_VALUE_SUCCESS, "Success."); add_exit_code (RETURN_VALUE_OPTION_PARSING_FAILED, "Option parsing failed.");