diff options
Diffstat (limited to 'java/org/gnu/emacs/EmacsCopyArea.java')
| -rw-r--r-- | java/org/gnu/emacs/EmacsCopyArea.java | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/java/org/gnu/emacs/EmacsCopyArea.java b/java/org/gnu/emacs/EmacsCopyArea.java new file mode 100644 index 00000000000..f34d1ecde01 --- /dev/null +++ b/java/org/gnu/emacs/EmacsCopyArea.java | |||
| @@ -0,0 +1,131 @@ | |||
| 1 | /* Communication module for Android terminals. -*- c-file-style: "GNU" -*- | ||
| 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 | package org.gnu.emacs; | ||
| 21 | |||
| 22 | import android.graphics.Bitmap; | ||
| 23 | import android.graphics.Canvas; | ||
| 24 | import android.graphics.Paint; | ||
| 25 | import android.graphics.PorterDuff.Mode; | ||
| 26 | import android.graphics.PorterDuffXfermode; | ||
| 27 | import android.graphics.Rect; | ||
| 28 | import android.graphics.Xfermode; | ||
| 29 | |||
| 30 | public class EmacsCopyArea implements EmacsPaintReq | ||
| 31 | { | ||
| 32 | private int src_x, src_y, dest_x, dest_y, width, height; | ||
| 33 | private EmacsDrawable destination, source; | ||
| 34 | private EmacsGC immutableGC; | ||
| 35 | private static Xfermode xorAlu, srcInAlu; | ||
| 36 | |||
| 37 | static | ||
| 38 | { | ||
| 39 | xorAlu = new PorterDuffXfermode (Mode.XOR); | ||
| 40 | srcInAlu = new PorterDuffXfermode (Mode.SRC_IN); | ||
| 41 | }; | ||
| 42 | |||
| 43 | public | ||
| 44 | EmacsCopyArea (EmacsDrawable destination, EmacsDrawable source, | ||
| 45 | int src_x, int src_y, int width, int height, | ||
| 46 | int dest_x, int dest_y, EmacsGC immutableGC) | ||
| 47 | { | ||
| 48 | this.destination = destination; | ||
| 49 | this.source = source; | ||
| 50 | this.src_x = src_x; | ||
| 51 | this.src_y = src_y; | ||
| 52 | this.width = width; | ||
| 53 | this.height = height; | ||
| 54 | this.dest_x = dest_x; | ||
| 55 | this.dest_y = dest_y; | ||
| 56 | this.immutableGC = immutableGC; | ||
| 57 | } | ||
| 58 | |||
| 59 | @Override | ||
| 60 | public Rect | ||
| 61 | getRect () | ||
| 62 | { | ||
| 63 | return new Rect (dest_x, dest_y, dest_x + width, | ||
| 64 | dest_y + height); | ||
| 65 | } | ||
| 66 | |||
| 67 | @Override | ||
| 68 | public EmacsDrawable | ||
| 69 | getDrawable () | ||
| 70 | { | ||
| 71 | return destination; | ||
| 72 | } | ||
| 73 | |||
| 74 | @Override | ||
| 75 | public EmacsGC | ||
| 76 | getGC () | ||
| 77 | { | ||
| 78 | return immutableGC; | ||
| 79 | } | ||
| 80 | |||
| 81 | @Override | ||
| 82 | public void | ||
| 83 | paintTo (Canvas canvas, Paint paint, EmacsGC immutableGC) | ||
| 84 | { | ||
| 85 | int alu; | ||
| 86 | Bitmap bitmap; | ||
| 87 | Paint maskPaint; | ||
| 88 | Canvas maskCanvas; | ||
| 89 | Bitmap maskBitmap; | ||
| 90 | Rect rect, srcRect; | ||
| 91 | |||
| 92 | /* TODO implement stippling. */ | ||
| 93 | if (immutableGC.fill_style == EmacsGC.GC_FILL_OPAQUE_STIPPLED) | ||
| 94 | return; | ||
| 95 | |||
| 96 | alu = immutableGC.function; | ||
| 97 | rect = getRect (); | ||
| 98 | bitmap = source.getBitmap (); | ||
| 99 | |||
| 100 | if (alu == EmacsGC.GC_COPY) | ||
| 101 | paint.setXfermode (null); | ||
| 102 | else | ||
| 103 | paint.setXfermode (xorAlu); | ||
| 104 | |||
| 105 | if (immutableGC.clip_mask == null) | ||
| 106 | canvas.drawBitmap (bitmap, new Rect (src_x, src_y, | ||
| 107 | src_x + width, | ||
| 108 | src_y + height), | ||
| 109 | rect, paint); | ||
| 110 | else | ||
| 111 | { | ||
| 112 | maskPaint = new Paint (); | ||
| 113 | srcRect = new Rect (0, 0, rect.width (), | ||
| 114 | rect.height ()); | ||
| 115 | maskBitmap | ||
| 116 | = immutableGC.clip_mask.bitmap.copy (Bitmap.Config.ARGB_8888, | ||
| 117 | true); | ||
| 118 | |||
| 119 | if (maskBitmap == null) | ||
| 120 | return; | ||
| 121 | |||
| 122 | maskPaint.setXfermode (srcInAlu); | ||
| 123 | maskCanvas = new Canvas (maskBitmap); | ||
| 124 | maskCanvas.drawBitmap (bitmap, new Rect (src_x, src_y, | ||
| 125 | src_x + width, | ||
| 126 | src_y + height), | ||
| 127 | srcRect, maskPaint); | ||
| 128 | canvas.drawBitmap (maskBitmap, srcRect, rect, paint); | ||
| 129 | } | ||
| 130 | } | ||
| 131 | } | ||