aboutsummaryrefslogtreecommitdiffstats
path: root/java/org/gnu/emacs/EmacsCopyArea.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/org/gnu/emacs/EmacsCopyArea.java')
-rw-r--r--java/org/gnu/emacs/EmacsCopyArea.java131
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
3Copyright (C) 2023 Free Software Foundation, Inc.
4
5This file is part of GNU Emacs.
6
7GNU Emacs is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation, either version 3 of the License, or (at
10your option) any later version.
11
12GNU Emacs is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
19
20package org.gnu.emacs;
21
22import android.graphics.Bitmap;
23import android.graphics.Canvas;
24import android.graphics.Paint;
25import android.graphics.PorterDuff.Mode;
26import android.graphics.PorterDuffXfermode;
27import android.graphics.Rect;
28import android.graphics.Xfermode;
29
30public 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}