mirror of
git://git.sv.gnu.org/emacs.git
synced 2026-01-10 05:30:45 -08:00
Update Android port
* Makefile.in (java): Depend on info. (MAKEFILE_NAME): (config.status): Remove unneeded changes. * configure.ac (BUILD_DETAILS, ANDROID_STUBIFY): Don't require a C++ compiler on Android. * java/AndroidManifest.xml: <EmacsActivity>: Set launchMode appropriately. <EmacsMultitaskActivity>: New activity. * java/Makefile.in (CROSS_BINS): Add EmacsClient. * java/org/gnu/emacs/EmacsActivity.java (EmacsActivity) (onCreate): Use the window attachment manager. * java/org/gnu/emacs/EmacsCopyArea.java (EmacsCopyArea) (paintTo): Implement clip masks correctly. * java/org/gnu/emacs/EmacsDrawRectangle.java (getRect, paintTo): Fix damage tracking rectangles. * java/org/gnu/emacs/EmacsFontDriver.java (FontSpec, toString): New function. (FontMetrics, EmacsFontDriver): Fix signature of textExtents. * java/org/gnu/emacs/EmacsMultitaskActivity.java (EmacsMultitaskActivity): New file. * java/org/gnu/emacs/EmacsNative.java (EmacsNative): New functions sendFocusIn, sendFocusOut, sendWindowAction. * java/org/gnu/emacs/EmacsPaintQueue.java (run): Fix clipping handling. * java/org/gnu/emacs/EmacsPixmap.java (EmacsPixmap): Add constructor for mutable pixmaps. * java/org/gnu/emacs/EmacsSdk23FontDriver.java (EmacsSdk23FontDriver): New file. * java/org/gnu/emacs/EmacsSdk7FontDriver.java (EmacsSdk7FontDriver, Sdk7Typeface, Sdk7FontEntity, Sdk7FontObject) (checkMatch, hasChar, encodeChar): Implement text display and fix font metrics semantics. * java/org/gnu/emacs/EmacsService.java (EmacsService): Remove availableChildren. (getLibraryDirectory, onCreate): Pass pixel density to Emacs. (clearArea): Fix arguments. Switch to using the window attachment manager. * java/org/gnu/emacs/EmacsSurfaceView.java (surfaceChanged) (surfaceCreated): Flip buffers on surface attachment. * java/org/gnu/emacs/EmacsView.java (EmacsView, swapBuffers): New argument FORCE. Always swap if it is true. (onKeyMultiple, onFocusChanged): New functions. * java/org/gnu/emacs/EmacsWindow.java (EmacsWindow, destroyHandle) (run): Switch to using the window attachment manager. * java/org/gnu/emacs/EmacsWindowAttachmentManager.java (EmacsWindowAttachmentManager): New file. * lisp/cus-edit.el (custom-button, custom-button-mouse) (custom-button-pressed): * lisp/faces.el (tool-bar): Define faces correctly on Android. * src/android.c (struct android_emacs_pixmap): Add mutable constructor. (struct android_emacs_drawable): New structure. (android_write_event): Check if event queue hasn't yet been initialized. (android_select): Set errno to EINTR if pselect fails. (android_close): Remove unused debugging code. (android_get_home_directory): New function. (Java_org_gnu_emacs_EmacsNative_setEmacsParams): Set pixel density and compute game path. (android_init_emacs_drawable): New function. (Java_org_gnu_emacs_EmacsNative_sendKeyPress): New argument `unicode_char'. Pass it in events. (Java_org_gnu_emacs_EmacsNative_sendKeyRelease): Likewise. (Java_org_gnu_emacs_EmacsNative_sendFocusIn) (Java_org_gnu_emacs_EmacsNative_sendFocusOut) (Java_org_gnu_emacs_EmacsNative_sendWindowAction): New functions. (android_resolve_handle): Export function. (android_change_gc): Clear clip rects under the right circumstances. Set right clip mask field. (android_create_pixmap_from_bitmap_data): Use correct alpha channels. (android_create_pixmap): Create mutable pixmap and avoid redundant color array allocation. (android_create_bitmap_from_data, android_create_image) (android_destroy_image, android_put_pixel, android_get_pixel) (android_get_image, android_put_image, faccessat): New functions. * src/android.h: Update prototypes. * src/androidfns.c (android_default_font_parameter): Prefer monospace to Droid Sans Mono. * src/androidfont.c (struct android_emacs_font_driver): New method `draw'. (struct android_emacs_font_spec): New field `dpi'. (struct androidfont_info): Add font metrics cache. (android_init_font_driver, android_init_font_spec): Adjust accordingly. (androidfont_from_lisp, androidfont_from_java): Handle new fields. (androidfont_draw): Implement function. (androidfont_open_font): Set pixel size correctly. (androidfont_close_font): Free metrics cache. (androidfont_cache_text_extents) (androidfont_check_cached_extents): New functions. (androidfont_text_extents): Cache glyph metrics somewhere for future use. (androidfont_list_family): Implement function. * src/androidgui.h (enum android_event_type): New focus and window action events. (enum android_modifier_mask): New masks. (struct android_key_event): New field `unicode_char'. (ANDROID_IS_MODIFIER_KEY): Newmacro. (struct android_focus_event, struct android_window_action_event): New structs. (union android_event): Add new fields. (enum android_image_format, struct android_image): New enums and structs. * src/androidterm.c (android_android_to_emacs_modifiers) (android_emacs_to_android_modifiers, android_lower_frame) (android_raise_frame, android_new_focus_frame) (android_focus_changed, android_detect_focus_change): New functions. (handle_one_android_event): Implement focus and key event handling. (android_frame_rehighlight): New function. (android_frame_raise_lower): Implement accordingly. (android_make_frame_invisible): Clear highlight_frame if required. (android_free_frame_resources): Clear x_focus_event_frame if required. (android_draw_fringe_bitmap, android_draw_image_foreground) (android_draw_image_foreground_1) (android_draw_image_glyph_string): Remove unnecessary code. (android_create_terminal, android_term_init): Set the baud rate to something sensible. * src/androidterm.h (struct android_bitmap_record): Make structure the same as on X. (struct android_display_info): New focus tracking fields. (struct android_output): Likewise. * src/dispextern.h (struct image): Add ximg and mask_img on Android. * src/emacs.c (android_emacs_init): Fix argc sorting iteration. * src/fileio.c (user_homedir): (get_homedir): Implement correctly on Android. * src/font.h (PT_PER_INCH): Define correctly on Android. * src/fringe.c (X, swap_nibble, init_fringe_bitmap): Swap fringe bitmaps correctly on Android. * src/image.c (GET_PIXEL, image_create_bitmap_from_data) (image_create_bitmap_from_file, free_bitmap_record) (image_unget_x_image_or_dc, struct image_type) (prepare_image_for_display, image_clear_image_1) (image_size_in_bytes, x_check_image_size) (x_create_x_image_and_pixmap, x_destroy_x_image) (image_check_image_size, image_create_x_image_and_pixmap_1) (image_destroy_x_image, gui_put_x_image, image_put_x_image) (image_get_x_image, image_unget_x_image) (Create_Pixmap_From_Bitmap_Data, image_pixmap_draw_cross) (MaskForeground, image_types, syms_of_image): Implement all of the above on Android in terms of an API very similar to X. * src/keyboard.c (FUNCTION_KEY_OFFSET, lispy_function_keys): Define on Android to something sensible. * src/lread.c (build_load_history): Fix problem.
This commit is contained in:
parent
fd074f3133
commit
a32963e11f
36 changed files with 2435 additions and 693 deletions
|
|
@ -28,16 +28,19 @@ import java.util.List;
|
|||
import android.graphics.Paint;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.Canvas;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import android.os.Build;
|
||||
|
||||
public class EmacsSdk7FontDriver extends EmacsFontDriver
|
||||
{
|
||||
private static final String TOFU_STRING = "\uDB3F\uDFFD";
|
||||
private static final String EM_STRING = "m";
|
||||
private static final String TAG = "EmacsSdk7FontDriver";
|
||||
|
||||
private class Sdk7Typeface
|
||||
protected class Sdk7Typeface
|
||||
{
|
||||
/* The typeface and paint. */
|
||||
public Typeface typeface;
|
||||
|
|
@ -57,7 +60,10 @@ public class EmacsSdk7FontDriver extends EmacsFontDriver
|
|||
width = UNSPECIFIED;
|
||||
spacing = PROPORTIONAL;
|
||||
|
||||
this.typeface = typeface;
|
||||
|
||||
typefacePaint = new Paint ();
|
||||
typefacePaint.setAntiAlias (true);
|
||||
typefacePaint.setTypeface (typeface);
|
||||
|
||||
/* For the calls to measureText below. */
|
||||
|
|
@ -160,7 +166,7 @@ public class EmacsSdk7FontDriver extends EmacsFontDriver
|
|||
}
|
||||
};
|
||||
|
||||
private class Sdk7FontEntity extends FontEntity
|
||||
protected class Sdk7FontEntity extends FontEntity
|
||||
{
|
||||
/* The typeface. */
|
||||
public Sdk7Typeface typeface;
|
||||
|
|
@ -177,19 +183,17 @@ public class EmacsSdk7FontDriver extends EmacsFontDriver
|
|||
slant = typeface.slant;
|
||||
spacing = typeface.spacing;
|
||||
width = typeface.width;
|
||||
dpi = Math.round (EmacsService.SERVICE.metrics.scaledDensity * 160f);
|
||||
|
||||
this.typeface = typeface;
|
||||
}
|
||||
};
|
||||
|
||||
private class Sdk7FontObject extends FontObject
|
||||
protected class Sdk7FontObject extends FontObject
|
||||
{
|
||||
/* The typeface. */
|
||||
public Sdk7Typeface typeface;
|
||||
|
||||
/* The text size. */
|
||||
public int pixelSize;
|
||||
|
||||
public
|
||||
Sdk7FontObject (Sdk7Typeface typeface, int pixelSize)
|
||||
{
|
||||
|
|
@ -205,6 +209,7 @@ public class EmacsSdk7FontDriver extends EmacsFontDriver
|
|||
slant = typeface.slant;
|
||||
spacing = typeface.spacing;
|
||||
width = typeface.width;
|
||||
dpi = Math.round (EmacsService.SERVICE.metrics.scaledDensity * 160f);
|
||||
|
||||
/* Compute the ascent and descent. */
|
||||
typeface.typefacePaint.setTextSize (pixelSize);
|
||||
|
|
@ -238,6 +243,93 @@ public class EmacsSdk7FontDriver extends EmacsFontDriver
|
|||
}
|
||||
};
|
||||
|
||||
private class Sdk7DrawString implements EmacsPaintReq
|
||||
{
|
||||
private boolean drawBackground;
|
||||
private Sdk7FontObject fontObject;
|
||||
private char[] chars;
|
||||
private EmacsGC immutableGC;
|
||||
private EmacsDrawable drawable;
|
||||
private Rect rect;
|
||||
private int originX, originY;
|
||||
|
||||
public
|
||||
Sdk7DrawString (Sdk7FontObject fontObject, char[] chars,
|
||||
EmacsGC immutableGC, EmacsDrawable drawable,
|
||||
boolean drawBackground, Rect rect,
|
||||
int originX, int originY)
|
||||
{
|
||||
this.fontObject = fontObject;
|
||||
this.chars = chars;
|
||||
this.immutableGC = immutableGC;
|
||||
this.drawable = drawable;
|
||||
this.drawBackground = drawBackground;
|
||||
this.rect = rect;
|
||||
this.originX = originX;
|
||||
this.originY = originY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EmacsDrawable
|
||||
getDrawable ()
|
||||
{
|
||||
return drawable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EmacsGC
|
||||
getGC ()
|
||||
{
|
||||
return immutableGC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void
|
||||
paintTo (Canvas canvas, Paint paint, EmacsGC immutableGC)
|
||||
{
|
||||
int scratch;
|
||||
|
||||
paint.setStyle (Paint.Style.FILL);
|
||||
|
||||
if (drawBackground)
|
||||
{
|
||||
paint.setColor (immutableGC.background | 0xff000000);
|
||||
canvas.drawRect (rect, paint);
|
||||
}
|
||||
|
||||
paint.setTextSize (fontObject.pixelSize);
|
||||
paint.setColor (immutableGC.foreground | 0xff000000);
|
||||
paint.setTypeface (fontObject.typeface.typeface);
|
||||
paint.setAntiAlias (true);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)
|
||||
/* Disable hinting as that leads to displayed text not
|
||||
matching the computed metrics. */
|
||||
paint.setHinting (Paint.HINTING_OFF);
|
||||
|
||||
canvas.drawText (chars, 0, chars.length, originX, originY, paint);
|
||||
paint.setAntiAlias (false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rect
|
||||
getRect ()
|
||||
{
|
||||
Rect rect;
|
||||
|
||||
rect = new Rect ();
|
||||
|
||||
fontObject.typeface.typefacePaint.setTextSize (fontObject.pixelSize);
|
||||
fontObject.typeface.typefacePaint.getTextBounds (chars, 0, chars.length,
|
||||
rect);
|
||||
|
||||
/* Add the background rect to the damage as well. */
|
||||
rect.union (this.rect);
|
||||
|
||||
return rect;
|
||||
}
|
||||
};
|
||||
|
||||
private String[] fontFamilyList;
|
||||
private Sdk7Typeface[] typefaceList;
|
||||
private Sdk7Typeface fallbackTypeface;
|
||||
|
|
@ -252,7 +344,7 @@ public class EmacsSdk7FontDriver extends EmacsFontDriver
|
|||
systemFontsDirectory = new File ("/system/fonts");
|
||||
|
||||
fontFamilyList = systemFontsDirectory.list ();
|
||||
typefaceList = new Sdk7Typeface[fontFamilyList.length];
|
||||
typefaceList = new Sdk7Typeface[fontFamilyList.length + 3];
|
||||
|
||||
/* It would be nice to avoid opening each and every font upon
|
||||
startup. But that doesn't seem to be possible on
|
||||
|
|
@ -267,8 +359,18 @@ public class EmacsSdk7FontDriver extends EmacsFontDriver
|
|||
typeface);
|
||||
}
|
||||
|
||||
/* Initialize the default monospace and serif typefaces. */
|
||||
fallbackTypeface = new Sdk7Typeface ("monospace",
|
||||
Typeface.MONOSPACE);
|
||||
typefaceList[fontFamilyList.length] = fallbackTypeface;
|
||||
|
||||
fallbackTypeface = new Sdk7Typeface ("Monospace",
|
||||
Typeface.MONOSPACE);
|
||||
typefaceList[fontFamilyList.length + 1] = fallbackTypeface;
|
||||
|
||||
fallbackTypeface = new Sdk7Typeface ("Sans Serif",
|
||||
Typeface.DEFAULT);
|
||||
typefaceList[fontFamilyList.length + 2] = fallbackTypeface;
|
||||
}
|
||||
|
||||
private boolean
|
||||
|
|
@ -278,11 +380,6 @@ public class EmacsSdk7FontDriver extends EmacsFontDriver
|
|||
&& !fontSpec.family.equals (typeface.familyName))
|
||||
return false;
|
||||
|
||||
|
||||
if (fontSpec.adstyle != null
|
||||
&& !fontSpec.adstyle.isEmpty ())
|
||||
/* return false; */;
|
||||
|
||||
if (fontSpec.slant != null
|
||||
&& !fontSpec.weight.equals (typeface.weight))
|
||||
return false;
|
||||
|
|
@ -393,7 +490,7 @@ public class EmacsSdk7FontDriver extends EmacsFontDriver
|
|||
paint.getTextBounds (TOFU_STRING, 0, TOFU_STRING.length (),
|
||||
rect1);
|
||||
paint.getTextBounds ("" + charCode, 0, 1, rect2);
|
||||
return rect1.equals (rect2) ? 1 : 0;
|
||||
return rect1.equals (rect2) ? 0 : 1;
|
||||
}
|
||||
|
||||
private void
|
||||
|
|
@ -434,21 +531,47 @@ public class EmacsSdk7FontDriver extends EmacsFontDriver
|
|||
|
||||
@Override
|
||||
public void
|
||||
textExtents (FontObject font, int code[], FontMetrics fontMetrics[])
|
||||
textExtents (FontObject font, int code[], FontMetrics fontMetrics)
|
||||
{
|
||||
int i;
|
||||
Paint paintCache;
|
||||
Rect boundsCache;
|
||||
Sdk7FontObject fontObject;
|
||||
char[] text;
|
||||
float width;
|
||||
|
||||
fontObject = (Sdk7FontObject) font;
|
||||
paintCache = fontObject.typeface.typefacePaint;
|
||||
paintCache.setTextSize (fontObject.pixelSize);
|
||||
boundsCache = new Rect ();
|
||||
|
||||
for (i = 0; i < code.length; ++i)
|
||||
textExtents1 ((Sdk7FontObject) font, code[i], fontMetrics[i],
|
||||
if (code.length == 0)
|
||||
{
|
||||
fontMetrics.lbearing = 0;
|
||||
fontMetrics.rbearing = 0;
|
||||
fontMetrics.ascent = 0;
|
||||
fontMetrics.descent = 0;
|
||||
fontMetrics.width = 0;
|
||||
}
|
||||
else if (code.length == 1)
|
||||
textExtents1 ((Sdk7FontObject) font, code[0], fontMetrics,
|
||||
paintCache, boundsCache);
|
||||
else
|
||||
{
|
||||
text = new char[code.length];
|
||||
|
||||
for (i = 0; i < code.length; ++i)
|
||||
text[i] = (char) code[i];
|
||||
|
||||
paintCache.getTextBounds (text, 0, 1, boundsCache);
|
||||
width = paintCache.measureText (text, 0, code.length);
|
||||
|
||||
fontMetrics.lbearing = (short) boundsCache.left;
|
||||
fontMetrics.rbearing = (short) boundsCache.right;
|
||||
fontMetrics.ascent = (short) -boundsCache.top;
|
||||
fontMetrics.descent = (short) boundsCache.bottom;
|
||||
fontMetrics.width = (short) Math.round (width);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -457,4 +580,37 @@ public class EmacsSdk7FontDriver extends EmacsFontDriver
|
|||
{
|
||||
return charCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int
|
||||
draw (FontObject fontObject, EmacsGC gc, EmacsDrawable drawable,
|
||||
int[] chars, int x, int y, int backgroundWidth,
|
||||
boolean withBackground)
|
||||
{
|
||||
Rect backgroundRect;
|
||||
Sdk7FontObject sdk7FontObject;
|
||||
Sdk7DrawString op;
|
||||
char[] charsArray;
|
||||
int i;
|
||||
|
||||
sdk7FontObject = (Sdk7FontObject) fontObject;
|
||||
charsArray = new char[chars.length];
|
||||
|
||||
for (i = 0; i < chars.length; ++i)
|
||||
charsArray[i] = (char) chars[i];
|
||||
|
||||
backgroundRect = new Rect ();
|
||||
backgroundRect.top = y - sdk7FontObject.ascent;
|
||||
backgroundRect.left = x;
|
||||
backgroundRect.right = x + backgroundWidth;
|
||||
backgroundRect.bottom = y + sdk7FontObject.descent;
|
||||
|
||||
op = new Sdk7DrawString (sdk7FontObject, charsArray,
|
||||
gc.immutableGC (), drawable,
|
||||
withBackground,
|
||||
backgroundRect, x, y);
|
||||
|
||||
EmacsService.SERVICE.appendPaintOperation (op);
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue