diff options
| author | Po Lu | 2022-12-31 18:04:18 +0800 |
|---|---|---|
| committer | Po Lu | 2022-12-31 18:04:18 +0800 |
| commit | cfbc8a5dbcd362b69b37b4e6832ae4a31834364c (patch) | |
| tree | ce003d03c4ae98f4e1d02186d78e5ae6e0d36e55 /src/androidfont.c | |
| parent | 785095c416f9bae43d2947849282b814e2c7942e (diff) | |
| download | emacs-cfbc8a5dbcd362b69b37b4e6832ae4a31834364c.tar.gz emacs-cfbc8a5dbcd362b69b37b4e6832ae4a31834364c.zip | |
Bring up the Android operating system and its window system
* .dir-locals.el (c-mode): Add ANDROID_EXPORT noise macro.
* .gitignore: Add new files to ignore.
* Makefile.in: Adjust for Android.
* admin/merge-gnulib: Add new warning.
* configure.ac: Detect Android. Run cross-configuration for
Android when appropriate.
* etc/DEBUG: Document how to debug Emacs on Android.
* java/AndroidManifest.xml:
* java/Makefile.in:
* java/README:
* java/debug.sh:
* java/org/gnu/emacs/EmacsActivity.java (EmacsActivity):
* java/org/gnu/emacs/EmacsApplication.java (EmacsApplication):
* java/org/gnu/emacs/EmacsCopyArea.java (EmacsCopyArea):
* java/org/gnu/emacs/EmacsDrawLine.java (EmacsDrawLine):
* java/org/gnu/emacs/EmacsDrawPoint.java (EmacsDrawPoint):
* java/org/gnu/emacs/EmacsDrawRectangle.java
(EmacsDrawRectangle):
* java/org/gnu/emacs/EmacsDrawable.java (EmacsDrawable):
* java/org/gnu/emacs/EmacsFillPolygon.java (EmacsFillPolygon):
* java/org/gnu/emacs/EmacsFillRectangle.java
(EmacsFillRectangle):
* java/org/gnu/emacs/EmacsFontDriver.java (EmacsFontDriver):
* java/org/gnu/emacs/EmacsGC.java (EmacsGC):
* java/org/gnu/emacs/EmacsHandleObject.java (EmacsHandleObject):
* java/org/gnu/emacs/EmacsNative.java (EmacsNative):
* java/org/gnu/emacs/EmacsPaintQueue.java (EmacsPaintQueue):
* java/org/gnu/emacs/EmacsPaintReq.java (EmacsPaintReq):
* java/org/gnu/emacs/EmacsPixmap.java (EmacsPixmap):
* java/org/gnu/emacs/EmacsSdk7FontDriver.java
(EmacsSdk7FontDriver):
* java/org/gnu/emacs/EmacsService.java (class Holder<T>)
(EmacsService):
* java/org/gnu/emacs/EmacsSurfaceView.java (EmacsSurfaceView):
* java/org/gnu/emacs/EmacsThread.java (EmacsThread):
* java/org/gnu/emacs/EmacsView.java (EmacsView):
* java/org/gnu/emacs/EmacsWindow.java (EmacsWindow): New files
and classes.
* lib-src/Makefile.in (srcdir):
* lib/Makefile.in (VPATH):
(HAVE_NATIVE_COMP):
(libgnu_a_SOURCES):
(DEPFLAGS): Configure correctly for cross-compiling.
* lib/faccessat.c:
* lib/fpending.c (__fpending):
* lib/open.c:
* lib/unistd.c (_GL_UNISTD_INLINE): Temporary adjustments to
gnulib.
* lisp/frame.el (display-graphic-p):
(display-screens):
(display-pixel-height):
(display-pixel-width):
(display-mm-height):
(display-mm-width):
(display-backing-store):
(display-save-under):
(display-planes):
(display-color-cells):
(display-visual-class): Adjust for new window system `android'.
* lisp/image/wallpaper.el (x-open-connection): Add declaration.
* lisp/loadup.el (featurep): Load up files for Android.
* lisp/net/eww.el (eww-form-submit, eww-form-file)
(eww-form-checkbox, eww-form-select): Adjust faces for android.
* lisp/term/android-win.el: New file.
* src/Makefile.in: Add new targets emacs.so and android-emacs,
then adjust for cross compilation.
* src/alloc.c (cleanup_vector): Clean up Android font entities
as well.
(garbage_collect): Mark androidterm.
* src/android-emacs.c (main):
* src/android.c (ANDROID_THROW, enum android_fd_table_entry_flags)
(struct android_emacs_service, struct android_emacs_pixmap)
(struct android_graphics_point, struct android_event_container)
(struct android_event_queue, android_run_select_thread)
(android_handle_sigusr1, android_init_events, android_pending)
(android_next_event, android_write_event, android_select)
(android_run_debug_thread, android_user_full_name)
(android_get_asset_name, android_fstat, android_fstatat)
(android_file_access_p, android_hack_asset_fd, android_open)
(android_close, JNICALL, android_init_emacs_service)
(android_init_emacs_pixmap, android_init_graphics_point)
(MAX_HANDLE, struct android_handle_entry, android_alloc_id)
(android_destroy_handle, android_resolve_handle)
(android_resolve_handle2, android_change_window_attributes)
(android_create_window, android_set_window_background)
(android_destroy_window, android_init_android_rect_class)
(android_init_emacs_gc_class, android_create_gc, android_free_gc)
(android_change_gc, android_set_clip_rectangles)
(android_reparent_window, android_lookup_method)
(android_clear_window, android_map_window, android_unmap_window)
(android_resize_window, android_move_window, android_swap_buffers)
(android_get_gc_values, android_set_foreground)
(android_fill_rectangle, android_create_pixmap_from_bitmap_data)
(android_set_clip_mask, android_set_fill_style, android_copy_area)
(android_free_pixmap, android_set_background, android_fill_polygon)
(android_draw_rectangle, android_draw_point, android_draw_line)
(android_create_pixmap, android_set_ts_origin, android_clear_area):
* src/android.h (ANDROID_EXPORT):
* src/androidfns.c (android_display_info_for_name)
(check_android_display_info, check_x_display_info, gamma_correct)
(android_defined_color, android_decode_color)
(android_implicitly_set_name, android_explicitly_set_name)
(android_set_tool_bar_lines, android_change_tool_bar_height)
(android_set_tab_bar_lines, android_change_tab_bar_height)
(android_set_scroll_bar_default_height)
(android_set_scroll_bar_default_width, android_icon_verify)
(android_icon, android_make_gc, android_free_gcs)
(unwind_create_frame, do_unwind_create_frame)
(android_default_font_parameter, android_create_frame_window)
(Fx_create_frame, Fxw_color_defined_p, Fxw_color_values)
(Fxw_display_color_p, Fx_display_grayscale_p)
(Fx_display_pixel_width, Fx_display_pixel_height)
(Fx_display_planes, Fx_display_color_cells, Fx_display_screens)
(Fx_display_mm_width, Fx_display_mm_height)
(Fx_display_backing_store, Fx_display_visual_class)
(Fx_display_monitor_attributes_list, Fx_frame_geometry)
(Fx_frame_list_z_order, Fx_frame_restack)
(Fx_mouse_absolute_pixel_position)
(Fx_set_mouse_absolute_pixel_position, Fandroid_get_connection)
(Fx_display_list, Fx_show_tip, Fx_hide_tip)
(android_set_background_color, android_set_border_color)
(android_set_cursor_color, android_set_cursor_type)
(android_set_foreground_color)
(android_set_child_frame_border_width)
(android_set_internal_border_width, android_set_menu_bar_lines)
(android_set_mouse_color, android_set_title, android_set_alpha)
(android_frame_parm_handlers, syms_of_androidfns):
* src/androidfont.c (struct android_emacs_font_driver)
(struct android_emacs_font_spec, struct android_emacs_font_metrics)
(struct android_emacs_font_object, struct android_integer)
(struct androidfont_info, struct androidfont_entity)
(android_init_font_driver, android_init_font_spec)
(android_init_font_metrics, android_init_integer)
(android_init_font_object, androidfont_get_cache)
(androidfont_from_lisp, androidfont_from_java, androidfont_list)
(androidfont_match, androidfont_draw, androidfont_open_font)
(androidfont_close_font, androidfont_has_char)
(androidfont_encode_char, androidfont_text_extents)
(androidfont_list_family, androidfont_driver)
(syms_of_androidfont_for_pdumper, syms_of_androidfont)
(init_androidfont, android_finalize_font_entity):
* src/androidgui.h (_ANDROID_GUI_H_, struct android_rectangle)
(struct android_point, enum android_gc_function)
(enum android_gc_value_mask, enum android_fill_style)
(enum android_window_value_mask)
(struct android_set_window_attributes, struct android_gc_values)
(struct android_gc, enum android_swap_action, enum android_shape)
(enum android_coord_mode, struct android_swap_info)
(NativeRectangle, struct android_any_event)
(struct android_key_event, struct android_configure_event)
(union android_event):
* src/androidterm.c (android_window_to_frame, android_clear_frame)
(android_ring_bell, android_toggle_invisible_pointer)
(android_update_begin, android_update_end, show_back_buffer)
(android_flush_dirty_back_buffer_on, handle_one_android_event)
(android_read_socket, android_frame_up_to_date)
(android_buffer_flipping_unblocked_hook)
(android_query_frame_background_color, android_parse_color)
(android_alloc_nearest_color, android_query_colors)
(android_mouse_position, android_get_focus_frame)
(android_focus_frame, android_frame_rehighlight)
(android_frame_raise_lower, android_make_frame_visible)
(android_make_frame_invisible)
(android_make_frame_visible_invisible, android_fullscreen_hook)
(android_iconify_frame, android_set_window_size_1)
(android_set_window_size, android_set_offset, android_set_alpha)
(android_new_font, android_bitmap_icon, android_free_pixmap_hook)
(android_free_frame_resources, android_delete_frame)
(android_delete_terminal, android_scroll_run)
(android_after_update_window_line, android_flip_and_flush)
(android_clear_rectangle, android_reset_clip_rectangles)
(android_clip_to_row, android_draw_fringe_bitmap)
(android_set_cursor_gc, android_set_mouse_face_gc)
(android_set_mode_line_face_gc, android_set_glyph_string_gc)
(android_set_glyph_string_clipping)
(android_set_glyph_string_clipping_exactly)
(android_compute_glyph_string_overhangs)
(android_clear_glyph_string_rect)
(android_draw_glyph_string_background, android_fill_triangle)
(android_make_point, android_inside_rect_p, android_clear_point)
(android_draw_relief_rect, android_draw_box_rect)
(HIGHLIGHT_COLOR_DARK_BOOST_LIMIT, android_setup_relief_color)
(android_setup_relief_colors, android_draw_glyph_string_box)
(android_draw_glyph_string_bg_rect, android_draw_image_relief)
(android_draw_image_foreground, android_draw_image_foreground_1)
(android_draw_image_glyph_string)
(android_draw_stretch_glyph_string, android_draw_underwave)
(android_draw_glyph_string_foreground)
(android_draw_composite_glyph_string_foreground)
(android_draw_glyphless_glyph_string_foreground)
(android_draw_glyph_string, android_define_frame_cursor)
(android_clear_frame_area, android_clear_under_internal_border)
(android_draw_hollow_cursor, android_draw_bar_cursor)
(android_draw_window_cursor, android_draw_vertical_window_border)
(android_draw_window_divider, android_redisplay_interface)
(frame_set_mouse_pixel_position, get_keysym_name)
(android_create_terminal, android_term_init, syms_of_androidterm)
(mark_androidterm):
* src/androidterm.h (_ANDROID_TERM_H_, struct android_display_info)
(struct android_output, FRAME_ANDROID_OUTPUT, XSCROLL_BAR): New
files.
* src/dired.c (file_attributes): Do not use openat on Android.
* src/dispextern.h (No_Cursor): Define appropriately on Android.
(struct glyph_string, struct face): Make gc field of type struct
android_gc on Android.
* src/dispnew.c (clear_current_matrices, clear_desired_matrices)
(adjust_frame_glyphs_for_window_redisplay, free_glyphs)
(update_frame, scrolling, char_ins_del_cost, update_frame_line)
(init_display_interactive): Disable text terminal support
completely on Android. Fix non-toolkit menus for non-X systems.
* src/editfns.c (Fuser_full_name): Call android_user_full_name.
* src/emacs.c (android_emacs_init): Make main this on Android.
Prohibit argv sorting from exceeding end of argv.
* src/epaths.in: Add path definitions for Android.
* src/fileio.c (file_access_p): Call android_file_access_p.
(file_name_directory): Avoid using openat on Android.
(Fcopy_file): Adjust to call sys_fstat instead.
(file_directory_p):
(Finsert_file_contents):
(write_region): Likewise.
* src/filelock.c:
* src/fns.c (Flocale_info): Pacify warning on Android.
* src/font.c (font_make_entity_android): New function.
* src/font.h:
* src/frame.c (Fframep):
(Fwindow_system): Handle new window system `android'. Update doc strings.
(Fmake_terminal_frame): Disable on Android.
(gui_display_get_resource): Disable get_string_resource_hook on Android.
(syms_of_frame): New defsym `android'.
* src/frame.h (GCALIGNED_STRUCT): Add new output data for
Android.
(ENUM_BF): Expand enumerator size.
(FRAME_ANDROID_P, FRAME_WINDOW_P, MOUSE_HL_INFO): Add
definitions for Android.
* src/image.c (GET_PIXEL):
(image_create_bitmap_from_file):
(image_create_x_image_and_pixmap_1):
(image_get_x_image):
(slurp_file):
(lookup_rgb_color):
(image_to_emacs_colors):
(image_from_emacs_colors):
(image_pixmap_draw_cross):
(image_disable_image):
(MaskForeground):
(gif_load): Add stubs for Android.
* src/lisp.h:
* src/lread.c (safe_to_load_version, maybe_swap_for_eln1, openp):
* src/pdumper.c (pdumper_load): Call sys_fstat instead of fstat.
* src/process.c (wait_reading_process_output): Use
android_select instead of pselect.
* src/scroll.c: Disable on Android.
* src/sysdep.c (widen_foreground_group, reset_sys_modes)
(init_signals, emacs_fstatat, sys_fstat): New function.
(emacs_open, emacs_open_noquit, emacs_close): Implement
differently on Android.
(close_output_streams): Disable what is not required on Android.
* src/term.c (OUTPUT1_IF, encode_terminal_code, string_cost)
(string_cost_one_line, per_line_cost, calculate_costs)
(struct fkey_table, tty_append_glyph, produce_glyphs)
(tty_capable_p, Fsuspend_tty, Fresume_tty, device, init_tty)
(maybe_fatal, syms_of_term): Disable text terminal support on
Android.
* src/termhooks.h (enum output_method): Add android output
method.
(GCALIGNED_STRUCT, TERMINAL_FONT_CACHE): Define for Android.
* src/terminal.c (Fterminal_live_p): Implement for Android.
* src/verbose.mk.in (AM_V_GLOBALS): Add JAVAC and DX.
* src/xdisp.c (redisplay_internal): Disable text terminals on Android.
(display_menu_bar):
(display_tty_menu_item):
(draw_row_with_mouse_face):
(expose_frame): Make the non toolkit menu bar work on Android.
* src/xfaces.c (GCGraphicsExposures):
(x_create_gc):
(x_free_gc):
(Fx_load_color_file): Define for Android.
* xcompile/Makefile.in (top_srcdir):
(top_builddir):
* xcompile/README:
* xcompile/langinfo.h (nl_langinfo): New files.
Diffstat (limited to 'src/androidfont.c')
| -rw-r--r-- | src/androidfont.c | 955 |
1 files changed, 955 insertions, 0 deletions
diff --git a/src/androidfont.c b/src/androidfont.c new file mode 100644 index 00000000000..e312e55c54a --- /dev/null +++ b/src/androidfont.c | |||
| @@ -0,0 +1,955 @@ | |||
| 1 | /* Communication module for Android terminals. | ||
| 2 | |||
| 3 | Copyright (C) 2023 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | This file is part of GNU Emacs. | ||
| 6 | |||
| 7 | GNU Emacs is free software: you can redistribute it and/or modify | ||
| 8 | it under the terms of the GNU General Public License as published by | ||
| 9 | the Free Software Foundation, either version 3 of the License, or (at | ||
| 10 | your option) any later version. | ||
| 11 | |||
| 12 | GNU Emacs is distributed in the hope that it will be useful, | ||
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 15 | GNU General Public License for more details. | ||
| 16 | |||
| 17 | You should have received a copy of the GNU General Public License | ||
| 18 | along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | ||
| 19 | |||
| 20 | #include <config.h> | ||
| 21 | |||
| 22 | #include "lisp.h" | ||
| 23 | #include "dispextern.h" | ||
| 24 | #include "composite.h" | ||
| 25 | #include "blockinput.h" | ||
| 26 | #include "charset.h" | ||
| 27 | #include "frame.h" | ||
| 28 | #include "window.h" | ||
| 29 | #include "fontset.h" | ||
| 30 | #include "androidterm.h" | ||
| 31 | #include "character.h" | ||
| 32 | #include "coding.h" | ||
| 33 | #include "font.h" | ||
| 34 | #include "termchar.h" | ||
| 35 | #include "pdumper.h" | ||
| 36 | #include "android.h" | ||
| 37 | |||
| 38 | #ifndef ANDROID_STUBIFY | ||
| 39 | |||
| 40 | #include <android/log.h> | ||
| 41 | |||
| 42 | struct android_emacs_font_driver | ||
| 43 | { | ||
| 44 | jclass class; | ||
| 45 | jmethodID list; | ||
| 46 | jmethodID match; | ||
| 47 | jmethodID list_families; | ||
| 48 | jmethodID open_font; | ||
| 49 | jmethodID has_char; | ||
| 50 | jmethodID text_extents; | ||
| 51 | jmethodID encode_char; | ||
| 52 | |||
| 53 | /* Static methods. */ | ||
| 54 | jmethodID create_font_driver; | ||
| 55 | }; | ||
| 56 | |||
| 57 | struct android_emacs_font_spec | ||
| 58 | { | ||
| 59 | jclass class; | ||
| 60 | jfieldID foundry; | ||
| 61 | jfieldID family; | ||
| 62 | jfieldID adstyle; | ||
| 63 | jfieldID registry; | ||
| 64 | jfieldID width; | ||
| 65 | jfieldID weight; | ||
| 66 | jfieldID slant; | ||
| 67 | jfieldID size; | ||
| 68 | jfieldID spacing; | ||
| 69 | jfieldID avgwidth; | ||
| 70 | }; | ||
| 71 | |||
| 72 | struct android_emacs_font_metrics | ||
| 73 | { | ||
| 74 | jclass class; | ||
| 75 | jfieldID lbearing; | ||
| 76 | jfieldID rbearing; | ||
| 77 | jfieldID width; | ||
| 78 | jfieldID ascent; | ||
| 79 | jfieldID descent; | ||
| 80 | }; | ||
| 81 | |||
| 82 | struct android_emacs_font_object | ||
| 83 | { | ||
| 84 | jclass class; | ||
| 85 | jfieldID min_width; | ||
| 86 | jfieldID max_width; | ||
| 87 | jfieldID pixel_size; | ||
| 88 | jfieldID height; | ||
| 89 | jfieldID space_width; | ||
| 90 | jfieldID average_width; | ||
| 91 | jfieldID ascent; | ||
| 92 | jfieldID descent; | ||
| 93 | jfieldID underline_thickness; | ||
| 94 | jfieldID underline_position; | ||
| 95 | jfieldID baseline_offset; | ||
| 96 | jfieldID relative_compose; | ||
| 97 | jfieldID default_ascent; | ||
| 98 | jfieldID encoding_charset; | ||
| 99 | jfieldID repertory_charset; | ||
| 100 | }; | ||
| 101 | |||
| 102 | struct android_integer | ||
| 103 | { | ||
| 104 | jclass class; | ||
| 105 | jmethodID constructor; | ||
| 106 | jmethodID int_value; | ||
| 107 | }; | ||
| 108 | |||
| 109 | struct androidfont_info | ||
| 110 | { | ||
| 111 | /* The font pseudo-vector object. */ | ||
| 112 | struct font font; | ||
| 113 | |||
| 114 | /* The Java-side font. */ | ||
| 115 | jobject object; | ||
| 116 | }; | ||
| 117 | |||
| 118 | struct androidfont_entity | ||
| 119 | { | ||
| 120 | /* The font entity pvec. */ | ||
| 121 | struct font_entity font; | ||
| 122 | |||
| 123 | /* The Java-side font entity. */ | ||
| 124 | jobject object; | ||
| 125 | }; | ||
| 126 | |||
| 127 | /* Method and class identifiers associated with the EmacsFontDriver | ||
| 128 | class. */ | ||
| 129 | |||
| 130 | struct android_emacs_font_driver font_driver_class; | ||
| 131 | |||
| 132 | /* Field and class identifiers associated with the | ||
| 133 | EmacsFontDriver$FontSpec class. */ | ||
| 134 | |||
| 135 | struct android_emacs_font_spec font_spec_class; | ||
| 136 | |||
| 137 | /* Method and class identifiers associated with the Integer class. */ | ||
| 138 | |||
| 139 | struct android_integer integer_class; | ||
| 140 | |||
| 141 | /* Field and class identifiers associated with the | ||
| 142 | EmacsFontDriver$FontMetrics class. */ | ||
| 143 | |||
| 144 | struct android_emacs_font_metrics font_metrics_class; | ||
| 145 | |||
| 146 | /* Field and class identifiers associated with the | ||
| 147 | EmacsFontDriver$FontObject class. */ | ||
| 148 | |||
| 149 | struct android_emacs_font_object font_object_class; | ||
| 150 | |||
| 151 | /* The font cache. */ | ||
| 152 | |||
| 153 | static Lisp_Object font_cache; | ||
| 154 | |||
| 155 | /* The Java-side font driver. */ | ||
| 156 | |||
| 157 | static jobject font_driver; | ||
| 158 | |||
| 159 | |||
| 160 | |||
| 161 | /* Initialize the class and method identifiers for functions in the | ||
| 162 | EmacsFontDriver class, and place them in `font_driver_class'. */ | ||
| 163 | |||
| 164 | static void | ||
| 165 | android_init_font_driver (void) | ||
| 166 | { | ||
| 167 | jclass old; | ||
| 168 | |||
| 169 | font_driver_class.class | ||
| 170 | = (*android_java_env)->FindClass (android_java_env, | ||
| 171 | "org/gnu/emacs/EmacsFontDriver"); | ||
| 172 | eassert (font_driver_class.class); | ||
| 173 | |||
| 174 | old = font_driver_class.class; | ||
| 175 | font_driver_class.class | ||
| 176 | = (jclass) (*android_java_env)->NewGlobalRef (android_java_env, | ||
| 177 | (jobject) old); | ||
| 178 | ANDROID_DELETE_LOCAL_REF (old); | ||
| 179 | |||
| 180 | if (!font_driver_class.class) | ||
| 181 | emacs_abort (); | ||
| 182 | |||
| 183 | #define FIND_METHOD(c_name, name, signature) \ | ||
| 184 | font_driver_class.c_name \ | ||
| 185 | = (*android_java_env)->GetMethodID (android_java_env, \ | ||
| 186 | font_driver_class.class, \ | ||
| 187 | name, signature); \ | ||
| 188 | eassert (font_driver_class.c_name); | ||
| 189 | |||
| 190 | FIND_METHOD (list, "list", "(Lorg/gnu/emacs/EmacsFontDriver$FontSpec;)" | ||
| 191 | "[Lorg/gnu/emacs/EmacsFontDriver$FontEntity;"); | ||
| 192 | FIND_METHOD (match, "match", "(Lorg/gnu/emacs/EmacsFontDriver$FontSpec;)" | ||
| 193 | "Lorg/gnu/emacs/EmacsFontDriver$FontEntity;"); | ||
| 194 | FIND_METHOD (list_families, "listFamilies", "()[Ljava/lang/String;"); | ||
| 195 | FIND_METHOD (open_font, "openFont", "(Lorg/gnu/emacs/EmacsFontDriver$Font" | ||
| 196 | "Entity;I)Lorg/gnu/emacs/EmacsFontDriver$FontObject;"); | ||
| 197 | FIND_METHOD (has_char, "hasChar", "(Lorg/gnu/emacs/EmacsFontDriver$Font" | ||
| 198 | "Spec;C)I"); | ||
| 199 | FIND_METHOD (text_extents, "textExtents", "(Lorg/gnu/emacs/EmacsFontDriver" | ||
| 200 | "$FontObject;[I[Lorg/gnu/emacs/EmacsFontDriver$FontMetrics;)V"); | ||
| 201 | FIND_METHOD (encode_char, "encodeChar", "(Lorg/gnu/emacs/EmacsFontDriver" | ||
| 202 | "$FontObject;C)I"); | ||
| 203 | |||
| 204 | font_driver_class.create_font_driver | ||
| 205 | = (*android_java_env)->GetStaticMethodID (android_java_env, | ||
| 206 | font_driver_class.class, | ||
| 207 | "createFontDriver", | ||
| 208 | "()Lorg/gnu/emacs/" | ||
| 209 | "EmacsFontDriver;"); | ||
| 210 | eassert (font_driver_class.create_font_driver); | ||
| 211 | #undef FIND_METHOD | ||
| 212 | } | ||
| 213 | |||
| 214 | /* Initialize the class and field identifiers for functions in the | ||
| 215 | EmacsFontDriver$FontSpec class, and place them in | ||
| 216 | `font_spec_class'. */ | ||
| 217 | |||
| 218 | static void | ||
| 219 | android_init_font_spec (void) | ||
| 220 | { | ||
| 221 | jclass old; | ||
| 222 | |||
| 223 | font_spec_class.class | ||
| 224 | = (*android_java_env)->FindClass (android_java_env, | ||
| 225 | "org/gnu/emacs/EmacsFontDriver" | ||
| 226 | "$FontSpec"); | ||
| 227 | eassert (font_spec_class.class); | ||
| 228 | |||
| 229 | old = font_spec_class.class; | ||
| 230 | font_spec_class.class | ||
| 231 | = (jclass) (*android_java_env)->NewGlobalRef (android_java_env, | ||
| 232 | (jobject) old); | ||
| 233 | ANDROID_DELETE_LOCAL_REF (old); | ||
| 234 | |||
| 235 | if (!font_spec_class.class) | ||
| 236 | emacs_abort (); | ||
| 237 | |||
| 238 | #define FIND_FIELD(c_name, name, signature) \ | ||
| 239 | font_spec_class.c_name \ | ||
| 240 | = (*android_java_env)->GetFieldID (android_java_env, \ | ||
| 241 | font_spec_class.class, \ | ||
| 242 | name, signature); \ | ||
| 243 | eassert (font_spec_class.c_name); | ||
| 244 | |||
| 245 | FIND_FIELD (foundry, "foundry", "Ljava/lang/String;"); | ||
| 246 | FIND_FIELD (family, "family", "Ljava/lang/String;"); | ||
| 247 | FIND_FIELD (adstyle, "adstyle", "Ljava/lang/String;"); | ||
| 248 | FIND_FIELD (registry, "registry", "Ljava/lang/String;"); | ||
| 249 | FIND_FIELD (width, "width", "Ljava/lang/Integer;"); | ||
| 250 | FIND_FIELD (weight, "weight", "Ljava/lang/Integer;"); | ||
| 251 | FIND_FIELD (slant, "slant", "Ljava/lang/Integer;"); | ||
| 252 | FIND_FIELD (size, "size", "Ljava/lang/Integer;"); | ||
| 253 | FIND_FIELD (spacing, "spacing", "Ljava/lang/Integer;"); | ||
| 254 | FIND_FIELD (avgwidth, "avgwidth", "Ljava/lang/Integer;"); | ||
| 255 | #undef FIND_FIELD | ||
| 256 | } | ||
| 257 | |||
| 258 | static void | ||
| 259 | android_init_font_metrics (void) | ||
| 260 | { | ||
| 261 | jclass old; | ||
| 262 | |||
| 263 | font_metrics_class.class | ||
| 264 | = (*android_java_env)->FindClass (android_java_env, | ||
| 265 | "org/gnu/emacs/EmacsFontDriver" | ||
| 266 | "$FontMetrics"); | ||
| 267 | eassert (font_metrics_class.class); | ||
| 268 | |||
| 269 | old = font_metrics_class.class; | ||
| 270 | font_metrics_class.class | ||
| 271 | = (jclass) (*android_java_env)->NewGlobalRef (android_java_env, | ||
| 272 | (jobject) old); | ||
| 273 | ANDROID_DELETE_LOCAL_REF (old); | ||
| 274 | |||
| 275 | if (!font_metrics_class.class) | ||
| 276 | emacs_abort (); | ||
| 277 | |||
| 278 | #define FIND_FIELD(c_name, name, signature) \ | ||
| 279 | font_metrics_class.c_name \ | ||
| 280 | = (*android_java_env)->GetFieldID (android_java_env, \ | ||
| 281 | font_metrics_class.class, \ | ||
| 282 | name, signature); \ | ||
| 283 | eassert (font_metrics_class.c_name); | ||
| 284 | |||
| 285 | FIND_FIELD (lbearing, "lbearing", "S"); | ||
| 286 | FIND_FIELD (rbearing, "rbearing", "S"); | ||
| 287 | FIND_FIELD (width, "width", "S"); | ||
| 288 | FIND_FIELD (ascent, "ascent", "S"); | ||
| 289 | FIND_FIELD (descent, "descent", "S"); | ||
| 290 | #undef FIND_FIELD | ||
| 291 | } | ||
| 292 | |||
| 293 | static void | ||
| 294 | android_init_integer (void) | ||
| 295 | { | ||
| 296 | jclass old; | ||
| 297 | |||
| 298 | integer_class.class | ||
| 299 | = (*android_java_env)->FindClass (android_java_env, | ||
| 300 | "java/lang/Integer"); | ||
| 301 | eassert (integer_class.class); | ||
| 302 | |||
| 303 | old = integer_class.class; | ||
| 304 | integer_class.class | ||
| 305 | = (jclass) (*android_java_env)->NewGlobalRef (android_java_env, | ||
| 306 | (jobject) old); | ||
| 307 | ANDROID_DELETE_LOCAL_REF (old); | ||
| 308 | |||
| 309 | if (!integer_class.class) | ||
| 310 | emacs_abort (); | ||
| 311 | |||
| 312 | #define FIND_METHOD(c_name, name, signature) \ | ||
| 313 | integer_class.c_name \ | ||
| 314 | = (*android_java_env)->GetMethodID (android_java_env, \ | ||
| 315 | integer_class.class, \ | ||
| 316 | name, signature); \ | ||
| 317 | eassert (integer_class.c_name); | ||
| 318 | |||
| 319 | FIND_METHOD (constructor, "<init>", "(I)V"); | ||
| 320 | FIND_METHOD (int_value, "intValue", "()I"); | ||
| 321 | #undef FIND_METHOD | ||
| 322 | } | ||
| 323 | |||
| 324 | static void | ||
| 325 | android_init_font_object (void) | ||
| 326 | { | ||
| 327 | jclass old; | ||
| 328 | |||
| 329 | font_object_class.class | ||
| 330 | = (*android_java_env)->FindClass (android_java_env, | ||
| 331 | "org/gnu/emacs/EmacsFontDriver" | ||
| 332 | "$FontObject"); | ||
| 333 | eassert (font_object_class.class); | ||
| 334 | |||
| 335 | old = font_object_class.class; | ||
| 336 | font_object_class.class | ||
| 337 | = (jclass) (*android_java_env)->NewGlobalRef (android_java_env, | ||
| 338 | (jobject) old); | ||
| 339 | ANDROID_DELETE_LOCAL_REF (old); | ||
| 340 | |||
| 341 | if (!font_object_class.class) | ||
| 342 | emacs_abort (); | ||
| 343 | |||
| 344 | #define FIND_FIELD(c_name, name, signature) \ | ||
| 345 | font_object_class.c_name \ | ||
| 346 | = (*android_java_env)->GetFieldID (android_java_env, \ | ||
| 347 | font_object_class.class, \ | ||
| 348 | name, signature); \ | ||
| 349 | eassert (font_object_class.c_name); | ||
| 350 | |||
| 351 | FIND_FIELD (min_width, "minWidth", "I"); | ||
| 352 | FIND_FIELD (max_width, "maxWidth", "I"); | ||
| 353 | FIND_FIELD (pixel_size, "pixelSize", "I"); | ||
| 354 | FIND_FIELD (height, "height", "I"); | ||
| 355 | FIND_FIELD (space_width, "spaceWidth", "I"); | ||
| 356 | FIND_FIELD (average_width, "averageWidth", "I"); | ||
| 357 | FIND_FIELD (ascent, "ascent", "I"); | ||
| 358 | FIND_FIELD (descent, "descent", "I"); | ||
| 359 | FIND_FIELD (underline_thickness, "underlineThickness", "I"); | ||
| 360 | FIND_FIELD (underline_position, "underlinePosition", "I"); | ||
| 361 | FIND_FIELD (baseline_offset, "baselineOffset", "I"); | ||
| 362 | FIND_FIELD (relative_compose, "relativeCompose", "I"); | ||
| 363 | FIND_FIELD (default_ascent, "defaultAscent", "I"); | ||
| 364 | FIND_FIELD (encoding_charset, "encodingCharset", "I"); | ||
| 365 | FIND_FIELD (repertory_charset, "repertoryCharset", "I"); | ||
| 366 | #undef FIND_FIELD | ||
| 367 | } | ||
| 368 | |||
| 369 | static Lisp_Object | ||
| 370 | androidfont_get_cache (struct frame *frame) | ||
| 371 | { | ||
| 372 | return font_cache; | ||
| 373 | } | ||
| 374 | |||
| 375 | /* Return a local reference to an instance of EmacsFontDriver$FontSpec | ||
| 376 | with the same values as FONT. */ | ||
| 377 | |||
| 378 | static jobject | ||
| 379 | androidfont_from_lisp (Lisp_Object font) | ||
| 380 | { | ||
| 381 | jobject spec, integer; | ||
| 382 | jstring string; | ||
| 383 | Lisp_Object tem; | ||
| 384 | |||
| 385 | spec = (*android_java_env)->AllocObject (android_java_env, | ||
| 386 | font_spec_class.class); | ||
| 387 | |||
| 388 | if (!spec) | ||
| 389 | { | ||
| 390 | (*android_java_env)->ExceptionClear (android_java_env); | ||
| 391 | memory_full (0); | ||
| 392 | } | ||
| 393 | |||
| 394 | #define DO_SYMBOL_FIELD(field, index) \ | ||
| 395 | tem = AREF (font, index); \ | ||
| 396 | if (SYMBOLP (tem)) \ | ||
| 397 | { \ | ||
| 398 | /* Java seems to DTRT with the Emacs string encoding, so this does \ | ||
| 399 | not matter at all. */ \ | ||
| 400 | string = (*android_java_env)->NewStringUTF (android_java_env, \ | ||
| 401 | SSDATA (SYMBOL_NAME (tem))); \ | ||
| 402 | if (!string) \ | ||
| 403 | { \ | ||
| 404 | (*android_java_env)->ExceptionClear (android_java_env); \ | ||
| 405 | memory_full (0); \ | ||
| 406 | } \ | ||
| 407 | \ | ||
| 408 | (*android_java_env)->SetObjectField (android_java_env, spec, \ | ||
| 409 | font_spec_class.field, \ | ||
| 410 | string); \ | ||
| 411 | ANDROID_DELETE_LOCAL_REF (string); \ | ||
| 412 | } \ | ||
| 413 | |||
| 414 | DO_SYMBOL_FIELD (foundry, FONT_FOUNDRY_INDEX); | ||
| 415 | DO_SYMBOL_FIELD (family, FONT_FAMILY_INDEX); | ||
| 416 | DO_SYMBOL_FIELD (adstyle, FONT_ADSTYLE_INDEX); | ||
| 417 | DO_SYMBOL_FIELD (registry, FONT_REGISTRY_INDEX); | ||
| 418 | |||
| 419 | #undef DO_SYMBOL_FIELD | ||
| 420 | |||
| 421 | #define DO_CARDINAL_FIELD(field, value) \ | ||
| 422 | if (value != -1) \ | ||
| 423 | { \ | ||
| 424 | integer = (*android_java_env)->NewObject (android_java_env, \ | ||
| 425 | integer_class.class, \ | ||
| 426 | integer_class.constructor, \ | ||
| 427 | (jint) value); \ | ||
| 428 | if (!integer) \ | ||
| 429 | { \ | ||
| 430 | (*android_java_env)->ExceptionClear (android_java_env); \ | ||
| 431 | memory_full (0); \ | ||
| 432 | } \ | ||
| 433 | \ | ||
| 434 | (*android_java_env)->SetObjectField (android_java_env, spec, \ | ||
| 435 | font_spec_class.field, \ | ||
| 436 | integer); \ | ||
| 437 | ANDROID_DELETE_LOCAL_REF (integer); \ | ||
| 438 | } | ||
| 439 | |||
| 440 | DO_CARDINAL_FIELD (width, FONT_WIDTH_NUMERIC (font)); | ||
| 441 | DO_CARDINAL_FIELD (weight, FONT_WEIGHT_NUMERIC (font)); | ||
| 442 | DO_CARDINAL_FIELD (slant, FONT_SLANT_NUMERIC (font)); | ||
| 443 | DO_CARDINAL_FIELD (size, (FIXNUMP (AREF (font, FONT_SIZE_INDEX)) | ||
| 444 | ? XFIXNUM (AREF (font, FONT_SIZE_INDEX)) | ||
| 445 | : -1)); | ||
| 446 | DO_CARDINAL_FIELD (spacing, (FIXNUMP (AREF (font, FONT_SPACING_INDEX)) | ||
| 447 | ? XFIXNUM (AREF (font, FONT_SPACING_INDEX)) | ||
| 448 | : -1)); | ||
| 449 | DO_CARDINAL_FIELD (avgwidth, (FIXNUMP (AREF (font, FONT_AVGWIDTH_INDEX)) | ||
| 450 | ? XFIXNUM (AREF (font, FONT_AVGWIDTH_INDEX)) | ||
| 451 | : -1)); | ||
| 452 | |||
| 453 | #undef DO_CARDINAL_FIELD | ||
| 454 | |||
| 455 | return spec; | ||
| 456 | } | ||
| 457 | |||
| 458 | static void | ||
| 459 | androidfont_from_java (jobject spec, Lisp_Object entity) | ||
| 460 | { | ||
| 461 | jobject tem; | ||
| 462 | jint value; | ||
| 463 | const char *string; | ||
| 464 | |||
| 465 | #define DO_SYMBOL_FIELD(field, index) \ | ||
| 466 | tem = (*android_java_env)->GetObjectField (android_java_env, \ | ||
| 467 | spec, \ | ||
| 468 | font_spec_class.field); \ | ||
| 469 | if (tem) \ | ||
| 470 | { \ | ||
| 471 | string = (*android_java_env)->GetStringUTFChars (android_java_env, \ | ||
| 472 | tem, NULL); \ | ||
| 473 | if (!string) \ | ||
| 474 | memory_full (0); \ | ||
| 475 | ASET (entity, index, intern (string)); \ | ||
| 476 | (*android_java_env)->ReleaseStringUTFChars (android_java_env, \ | ||
| 477 | tem, string); \ | ||
| 478 | ANDROID_DELETE_LOCAL_REF (tem); \ | ||
| 479 | } | ||
| 480 | |||
| 481 | DO_SYMBOL_FIELD (foundry, FONT_FOUNDRY_INDEX); | ||
| 482 | DO_SYMBOL_FIELD (family, FONT_FAMILY_INDEX); | ||
| 483 | DO_SYMBOL_FIELD (adstyle, FONT_ADSTYLE_INDEX); | ||
| 484 | DO_SYMBOL_FIELD (registry, FONT_REGISTRY_INDEX); | ||
| 485 | |||
| 486 | #undef DO_SYMBOL_FIELD | ||
| 487 | #define DO_CARDINAL_FIELD(field, index, is_style) \ | ||
| 488 | tem = (*android_java_env)->GetObjectField (android_java_env, \ | ||
| 489 | spec, \ | ||
| 490 | font_spec_class.field); \ | ||
| 491 | if (tem) \ | ||
| 492 | { \ | ||
| 493 | value \ | ||
| 494 | = (*android_java_env)->CallIntMethod (android_java_env, \ | ||
| 495 | tem, \ | ||
| 496 | integer_class.int_value); \ | ||
| 497 | if (!is_style) \ | ||
| 498 | ASET (entity, index, make_fixnum (value)); \ | ||
| 499 | else \ | ||
| 500 | FONT_SET_STYLE (entity, index, make_fixnum (value)); \ | ||
| 501 | ANDROID_DELETE_LOCAL_REF (tem); \ | ||
| 502 | } | ||
| 503 | |||
| 504 | DO_CARDINAL_FIELD (width, FONT_WIDTH_INDEX, true); | ||
| 505 | DO_CARDINAL_FIELD (weight, FONT_WEIGHT_INDEX, true); | ||
| 506 | DO_CARDINAL_FIELD (slant, FONT_SLANT_INDEX, true); | ||
| 507 | DO_CARDINAL_FIELD (size, FONT_SIZE_INDEX, false); | ||
| 508 | DO_CARDINAL_FIELD (spacing, FONT_SPACING_INDEX, false); | ||
| 509 | DO_CARDINAL_FIELD (avgwidth, FONT_AVGWIDTH_INDEX, false); | ||
| 510 | #undef DO_CARDINAL_FIELD | ||
| 511 | } | ||
| 512 | |||
| 513 | /* Transfer the values from FONT, which must be some kind of font | ||
| 514 | entity, */ | ||
| 515 | |||
| 516 | static Lisp_Object | ||
| 517 | androidfont_list (struct frame *f, Lisp_Object font_spec) | ||
| 518 | { | ||
| 519 | jobject spec, array, tem; | ||
| 520 | jarray entities; | ||
| 521 | jsize i, size; | ||
| 522 | Lisp_Object value, entity; | ||
| 523 | struct androidfont_entity *info; | ||
| 524 | |||
| 525 | spec = androidfont_from_lisp (font_spec); | ||
| 526 | array = (*android_java_env)->CallObjectMethod (android_java_env, | ||
| 527 | font_driver, | ||
| 528 | font_driver_class.list, | ||
| 529 | spec); | ||
| 530 | (*android_java_env)->ExceptionClear (android_java_env); | ||
| 531 | ANDROID_DELETE_LOCAL_REF (spec); | ||
| 532 | |||
| 533 | if (!array) | ||
| 534 | memory_full (0); | ||
| 535 | |||
| 536 | entities = (jarray) array; | ||
| 537 | size = (*android_java_env)->GetArrayLength (android_java_env, | ||
| 538 | entities); | ||
| 539 | value = Qnil; | ||
| 540 | |||
| 541 | for (i = 0; i < size; ++i) | ||
| 542 | { | ||
| 543 | entity = font_make_entity_android (VECSIZE (struct androidfont_entity)); | ||
| 544 | info = (struct androidfont_entity *) XFONT_ENTITY (entity); | ||
| 545 | |||
| 546 | /* The type must be set correctly, or font_open_entity won't be | ||
| 547 | able to find the right font driver. */ | ||
| 548 | ASET (entity, FONT_TYPE_INDEX, Qandroid); | ||
| 549 | |||
| 550 | /* Clear this now in case GC happens without it set, which can | ||
| 551 | happen if androidfont_from_java runs out of memory. */ | ||
| 552 | info->object = NULL; | ||
| 553 | |||
| 554 | tem = (*android_java_env)->GetObjectArrayElement (android_java_env, | ||
| 555 | entities, i); | ||
| 556 | androidfont_from_java (tem, entity); | ||
| 557 | |||
| 558 | /* Now, make a global reference to the Java font entity. */ | ||
| 559 | info->object = (*android_java_env)->NewGlobalRef (android_java_env, | ||
| 560 | (jobject) tem); | ||
| 561 | (*android_java_env)->ExceptionClear (android_java_env); | ||
| 562 | ANDROID_DELETE_LOCAL_REF (tem); | ||
| 563 | |||
| 564 | if (!info->object) | ||
| 565 | memory_full (0); | ||
| 566 | |||
| 567 | value = Fcons (entity, value); | ||
| 568 | } | ||
| 569 | |||
| 570 | ANDROID_DELETE_LOCAL_REF (entities); | ||
| 571 | return Fnreverse (value); | ||
| 572 | } | ||
| 573 | |||
| 574 | static Lisp_Object | ||
| 575 | androidfont_match (struct frame *f, Lisp_Object font_spec) | ||
| 576 | { | ||
| 577 | jobject spec, result; | ||
| 578 | Lisp_Object entity; | ||
| 579 | struct androidfont_entity *info; | ||
| 580 | |||
| 581 | spec = androidfont_from_lisp (font_spec); | ||
| 582 | result = (*android_java_env)->CallObjectMethod (android_java_env, | ||
| 583 | font_driver, | ||
| 584 | font_driver_class.match, | ||
| 585 | spec); | ||
| 586 | (*android_java_env)->ExceptionClear (android_java_env); | ||
| 587 | ANDROID_DELETE_LOCAL_REF (spec); | ||
| 588 | |||
| 589 | if (!result) | ||
| 590 | memory_full (0); | ||
| 591 | |||
| 592 | entity = font_make_entity_android (VECSIZE (struct androidfont_entity)); | ||
| 593 | info = (struct androidfont_entity *) XFONT_ENTITY (entity); | ||
| 594 | |||
| 595 | /* The type must be set correctly, or font_open_entity won't be able | ||
| 596 | to find the right font driver. */ | ||
| 597 | ASET (entity, FONT_TYPE_INDEX, Qandroid); | ||
| 598 | |||
| 599 | info->object = NULL; | ||
| 600 | androidfont_from_java (result, entity); | ||
| 601 | info->object = (*android_java_env)->NewGlobalRef (android_java_env, | ||
| 602 | (jobject) result); | ||
| 603 | (*android_java_env)->ExceptionClear (android_java_env); | ||
| 604 | ANDROID_DELETE_LOCAL_REF (result); | ||
| 605 | |||
| 606 | if (!info->object) | ||
| 607 | memory_full (0); | ||
| 608 | |||
| 609 | return entity; | ||
| 610 | } | ||
| 611 | |||
| 612 | static int | ||
| 613 | androidfont_draw (struct glyph_string *s, int from, int to, | ||
| 614 | int x, int y, bool with_background) | ||
| 615 | { | ||
| 616 | return 0; | ||
| 617 | } | ||
| 618 | |||
| 619 | static Lisp_Object | ||
| 620 | androidfont_open_font (struct frame *f, Lisp_Object font_entity, int x) | ||
| 621 | { | ||
| 622 | struct androidfont_info *font_info; | ||
| 623 | struct androidfont_entity *entity; | ||
| 624 | struct font *font; | ||
| 625 | Lisp_Object font_object, tem; | ||
| 626 | jobject old; | ||
| 627 | jint value; | ||
| 628 | |||
| 629 | if (x <= 0) | ||
| 630 | { | ||
| 631 | /* Get pixel size from frame instead. */ | ||
| 632 | tem = get_frame_param (f, Qfontsize); | ||
| 633 | x = NILP (tem) ? 0 : XFIXNAT (tem); | ||
| 634 | } | ||
| 635 | |||
| 636 | __android_log_print (ANDROID_LOG_DEBUG, __func__, | ||
| 637 | "opening font entity %"pI"x:%d", | ||
| 638 | (EMACS_INT) font_entity, x); | ||
| 639 | |||
| 640 | entity = (struct androidfont_entity *) XFONT_ENTITY (font_entity); | ||
| 641 | |||
| 642 | block_input (); | ||
| 643 | font_object = font_make_object (VECSIZE (struct androidfont_info), | ||
| 644 | font_entity, x); | ||
| 645 | ASET (font_object, FONT_TYPE_INDEX, Qandroid); | ||
| 646 | font_info = (struct androidfont_info *) XFONT_OBJECT (font_object); | ||
| 647 | font = &font_info->font; | ||
| 648 | font->driver = &androidfont_driver; | ||
| 649 | |||
| 650 | /* Clear font_info->object early in case GC happens later on! */ | ||
| 651 | font_info->object = NULL; | ||
| 652 | unblock_input (); | ||
| 653 | |||
| 654 | font_info->object | ||
| 655 | = (*android_java_env)->CallObjectMethod (android_java_env, | ||
| 656 | font_driver, | ||
| 657 | font_driver_class.open_font, | ||
| 658 | entity->object, (jint) x); | ||
| 659 | if (!font_info->object) | ||
| 660 | { | ||
| 661 | (*android_java_env)->ExceptionClear (android_java_env); | ||
| 662 | return Qnil; | ||
| 663 | } | ||
| 664 | |||
| 665 | old = font_info->object; | ||
| 666 | font_info->object | ||
| 667 | = (*android_java_env)->NewGlobalRef (android_java_env, old); | ||
| 668 | (*android_java_env)->ExceptionClear (android_java_env); | ||
| 669 | ANDROID_DELETE_LOCAL_REF (old); | ||
| 670 | |||
| 671 | if (!font_info->object) | ||
| 672 | return Qnil; | ||
| 673 | |||
| 674 | /* Copy the font attributes from the Java object. */ | ||
| 675 | androidfont_from_java (font_info->object, font_object); | ||
| 676 | |||
| 677 | /* Copy font attributes inside EmacsFontDriver$FontObject. */ | ||
| 678 | #define DO_CARDINAL_FIELD(field) \ | ||
| 679 | value \ | ||
| 680 | = (*android_java_env)->GetIntField (android_java_env, \ | ||
| 681 | font_info->object, \ | ||
| 682 | font_object_class.field); \ | ||
| 683 | font->field = value; | ||
| 684 | |||
| 685 | DO_CARDINAL_FIELD (min_width); | ||
| 686 | DO_CARDINAL_FIELD (max_width); | ||
| 687 | DO_CARDINAL_FIELD (pixel_size); | ||
| 688 | DO_CARDINAL_FIELD (height); | ||
| 689 | DO_CARDINAL_FIELD (space_width); | ||
| 690 | DO_CARDINAL_FIELD (average_width); | ||
| 691 | DO_CARDINAL_FIELD (ascent); | ||
| 692 | DO_CARDINAL_FIELD (descent); | ||
| 693 | DO_CARDINAL_FIELD (underline_thickness); | ||
| 694 | DO_CARDINAL_FIELD (underline_position); | ||
| 695 | DO_CARDINAL_FIELD (baseline_offset); | ||
| 696 | DO_CARDINAL_FIELD (relative_compose); | ||
| 697 | DO_CARDINAL_FIELD (default_ascent); | ||
| 698 | DO_CARDINAL_FIELD (encoding_charset); | ||
| 699 | DO_CARDINAL_FIELD (repertory_charset); | ||
| 700 | |||
| 701 | #undef DO_CARDINAL_FIELD | ||
| 702 | |||
| 703 | /* This should eventually become unnecessary. */ | ||
| 704 | font->props[FONT_NAME_INDEX] = Ffont_xlfd_name (font_object, Qnil); | ||
| 705 | |||
| 706 | return font_object; | ||
| 707 | } | ||
| 708 | |||
| 709 | static void | ||
| 710 | androidfont_close_font (struct font *font) | ||
| 711 | { | ||
| 712 | struct androidfont_info *info; | ||
| 713 | |||
| 714 | info = (struct androidfont_info *) font; | ||
| 715 | |||
| 716 | /* If info->object is NULL, then FONT was unsuccessfully created, | ||
| 717 | and there is no global reference that has to be deleted. */ | ||
| 718 | |||
| 719 | if (!info->object) | ||
| 720 | return; | ||
| 721 | |||
| 722 | (*android_java_env)->DeleteGlobalRef (android_java_env, | ||
| 723 | info->object); | ||
| 724 | } | ||
| 725 | |||
| 726 | static int | ||
| 727 | androidfont_has_char (Lisp_Object font, int c) | ||
| 728 | { | ||
| 729 | struct androidfont_info *info; | ||
| 730 | struct androidfont_entity *entity; | ||
| 731 | |||
| 732 | if (FONT_ENTITY_P (font)) | ||
| 733 | { | ||
| 734 | entity = (struct androidfont_entity *) XFONT_ENTITY (font); | ||
| 735 | |||
| 736 | return (*android_java_env)->CallIntMethod (android_java_env, | ||
| 737 | font_driver, | ||
| 738 | font_driver_class.has_char, | ||
| 739 | entity->object, (jint) c); | ||
| 740 | } | ||
| 741 | else | ||
| 742 | { | ||
| 743 | info = (struct androidfont_info *) XFONT_OBJECT (font); | ||
| 744 | |||
| 745 | return (*android_java_env)->CallIntMethod (android_java_env, | ||
| 746 | font_driver, | ||
| 747 | font_driver_class.has_char, | ||
| 748 | info->object, (jint) c); | ||
| 749 | } | ||
| 750 | } | ||
| 751 | |||
| 752 | static unsigned | ||
| 753 | androidfont_encode_char (struct font *font, int c) | ||
| 754 | { | ||
| 755 | struct androidfont_info *info; | ||
| 756 | |||
| 757 | info = (struct androidfont_info *) font; | ||
| 758 | |||
| 759 | return (*android_java_env)->CallIntMethod (android_java_env, | ||
| 760 | font_driver, | ||
| 761 | font_driver_class.encode_char, | ||
| 762 | info->object, (jchar) c); | ||
| 763 | } | ||
| 764 | |||
| 765 | static void | ||
| 766 | androidfont_text_extents (struct font *font, const unsigned int *code, | ||
| 767 | int nglyphs, struct font_metrics *metrics) | ||
| 768 | { | ||
| 769 | struct androidfont_info *info; | ||
| 770 | jarray codepoint_array, metrics_array; | ||
| 771 | jobject metrics_object; | ||
| 772 | int i; | ||
| 773 | short value; | ||
| 774 | |||
| 775 | info = (struct androidfont_info *) font; | ||
| 776 | |||
| 777 | /* Allocate the arrays of code points and font metrics. */ | ||
| 778 | codepoint_array | ||
| 779 | = (*android_java_env)->NewIntArray (android_java_env, | ||
| 780 | nglyphs); | ||
| 781 | if (!codepoint_array) | ||
| 782 | { | ||
| 783 | (*android_java_env)->ExceptionClear (android_java_env); | ||
| 784 | memory_full (0); | ||
| 785 | } | ||
| 786 | |||
| 787 | metrics_array | ||
| 788 | = (*android_java_env)->NewObjectArray (android_java_env, | ||
| 789 | nglyphs, | ||
| 790 | font_metrics_class.class, | ||
| 791 | NULL); | ||
| 792 | if (!metrics_array) | ||
| 793 | { | ||
| 794 | (*android_java_env)->ExceptionClear (android_java_env); | ||
| 795 | ANDROID_DELETE_LOCAL_REF (metrics_array); | ||
| 796 | memory_full (0); | ||
| 797 | } | ||
| 798 | |||
| 799 | if (sizeof (unsigned int) == sizeof (jint)) | ||
| 800 | /* Always true on every Android device. */ | ||
| 801 | (*android_java_env)->SetIntArrayRegion (android_java_env, | ||
| 802 | codepoint_array, | ||
| 803 | 0, nglyphs, | ||
| 804 | (jint *) code); | ||
| 805 | else | ||
| 806 | emacs_abort (); | ||
| 807 | |||
| 808 | for (i = 0; i < nglyphs; ++i) | ||
| 809 | { | ||
| 810 | metrics_object | ||
| 811 | = (*android_java_env)->AllocObject (android_java_env, | ||
| 812 | font_metrics_class.class); | ||
| 813 | |||
| 814 | if (!metrics_object) | ||
| 815 | { | ||
| 816 | (*android_java_env)->ExceptionClear (android_java_env); | ||
| 817 | ANDROID_DELETE_LOCAL_REF (metrics_array); | ||
| 818 | ANDROID_DELETE_LOCAL_REF (codepoint_array); | ||
| 819 | memory_full (0); | ||
| 820 | } | ||
| 821 | |||
| 822 | (*android_java_env)->SetObjectArrayElement (android_java_env, | ||
| 823 | metrics_array, i, | ||
| 824 | metrics_object); | ||
| 825 | ANDROID_DELETE_LOCAL_REF (metrics_object); | ||
| 826 | } | ||
| 827 | |||
| 828 | (*android_java_env)->CallVoidMethod (android_java_env, | ||
| 829 | font_driver, | ||
| 830 | font_driver_class.text_extents, | ||
| 831 | info->object, codepoint_array, | ||
| 832 | metrics_array); | ||
| 833 | |||
| 834 | if ((*android_java_env)->ExceptionCheck (android_java_env)) | ||
| 835 | { | ||
| 836 | (*android_java_env)->ExceptionClear (android_java_env); | ||
| 837 | ANDROID_DELETE_LOCAL_REF (metrics_array); | ||
| 838 | ANDROID_DELETE_LOCAL_REF (codepoint_array); | ||
| 839 | memory_full (0); | ||
| 840 | } | ||
| 841 | |||
| 842 | for (i = 0; i < nglyphs; ++i) | ||
| 843 | { | ||
| 844 | metrics_object | ||
| 845 | = (*android_java_env)->GetObjectArrayElement (android_java_env, | ||
| 846 | metrics_array, i); | ||
| 847 | #define DO_CARDINAL_FIELD(field) \ | ||
| 848 | value \ | ||
| 849 | = (*android_java_env)->GetShortField (android_java_env, \ | ||
| 850 | metrics_object, \ | ||
| 851 | font_metrics_class.field); \ | ||
| 852 | metrics[i].field = value; | ||
| 853 | |||
| 854 | DO_CARDINAL_FIELD (lbearing); | ||
| 855 | DO_CARDINAL_FIELD (rbearing); | ||
| 856 | DO_CARDINAL_FIELD (width); | ||
| 857 | DO_CARDINAL_FIELD (ascent); | ||
| 858 | DO_CARDINAL_FIELD (descent); | ||
| 859 | |||
| 860 | #undef DO_CARDINAL_FIELD | ||
| 861 | |||
| 862 | ANDROID_DELETE_LOCAL_REF (metrics_object); | ||
| 863 | } | ||
| 864 | |||
| 865 | ANDROID_DELETE_LOCAL_REF (metrics_array); | ||
| 866 | ANDROID_DELETE_LOCAL_REF (codepoint_array); | ||
| 867 | } | ||
| 868 | |||
| 869 | static Lisp_Object | ||
| 870 | androidfont_list_family (struct frame *f) | ||
| 871 | { | ||
| 872 | return Qnil; | ||
| 873 | } | ||
| 874 | |||
| 875 | struct font_driver androidfont_driver = | ||
| 876 | { | ||
| 877 | .type = LISPSYM_INITIALLY (Qandroid), | ||
| 878 | .case_sensitive = true, | ||
| 879 | .get_cache = androidfont_get_cache, | ||
| 880 | .list = androidfont_list, | ||
| 881 | .match = androidfont_match, | ||
| 882 | .draw = androidfont_draw, | ||
| 883 | .open_font = androidfont_open_font, | ||
| 884 | .close_font = androidfont_close_font, | ||
| 885 | .has_char = androidfont_has_char, | ||
| 886 | .encode_char = androidfont_encode_char, | ||
| 887 | .text_extents = androidfont_text_extents, | ||
| 888 | .list_family = androidfont_list_family, | ||
| 889 | }; | ||
| 890 | |||
| 891 | static void | ||
| 892 | syms_of_androidfont_for_pdumper (void) | ||
| 893 | { | ||
| 894 | register_font_driver (&androidfont_driver, NULL); | ||
| 895 | } | ||
| 896 | |||
| 897 | void | ||
| 898 | syms_of_androidfont (void) | ||
| 899 | { | ||
| 900 | DEFSYM (Qfontsize, "fontsize"); | ||
| 901 | |||
| 902 | pdumper_do_now_and_after_load (syms_of_androidfont_for_pdumper); | ||
| 903 | |||
| 904 | font_cache = list (Qnil); | ||
| 905 | staticpro (&font_cache); | ||
| 906 | } | ||
| 907 | |||
| 908 | void | ||
| 909 | init_androidfont (void) | ||
| 910 | { | ||
| 911 | jmethodID method; | ||
| 912 | jobject old; | ||
| 913 | |||
| 914 | android_init_font_driver (); | ||
| 915 | android_init_font_spec (); | ||
| 916 | android_init_font_metrics (); | ||
| 917 | android_init_font_object (); | ||
| 918 | android_init_integer (); | ||
| 919 | |||
| 920 | method = font_driver_class.create_font_driver; | ||
| 921 | |||
| 922 | /* Initialize the font driver on the Java side. */ | ||
| 923 | font_driver | ||
| 924 | = (*android_java_env)->CallStaticObjectMethod (android_java_env, | ||
| 925 | font_driver_class.class, | ||
| 926 | method); | ||
| 927 | |||
| 928 | if (!font_driver) | ||
| 929 | memory_full (0); | ||
| 930 | |||
| 931 | old = font_driver; | ||
| 932 | font_driver | ||
| 933 | = (*android_java_env)->NewGlobalRef (android_java_env, font_driver); | ||
| 934 | ANDROID_DELETE_LOCAL_REF (old); | ||
| 935 | |||
| 936 | if (!font_driver) | ||
| 937 | memory_full (0); | ||
| 938 | } | ||
| 939 | |||
| 940 | void | ||
| 941 | android_finalize_font_entity (struct font_entity *entity) | ||
| 942 | { | ||
| 943 | struct androidfont_entity *info; | ||
| 944 | |||
| 945 | info = (struct androidfont_entity *) entity; | ||
| 946 | |||
| 947 | if (info->object) | ||
| 948 | (*android_java_env)->DeleteGlobalRef (android_java_env, | ||
| 949 | info->object); | ||
| 950 | |||
| 951 | /* Not sure if this can be called twice. */ | ||
| 952 | info->object = NULL; | ||
| 953 | } | ||
| 954 | |||
| 955 | #endif | ||