root/java/org/gnu/emacs/EmacsSdk23FontDriver.java

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. textExtents1
  2. textExtents
  3. hasChar

     1 /* Font backend 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.Paint;
    23 import android.graphics.Rect;
    24 
    25 public final class EmacsSdk23FontDriver extends EmacsSdk7FontDriver
    26 {
    27   private void
    28   textExtents1 (Sdk7FontObject font, int code, FontMetrics metrics,
    29                 Paint paint, Rect bounds)
    30   {
    31     char[] text;
    32 
    33     text = new char[2];
    34     text[0] = (char) code;
    35     text[1] = 'c';
    36 
    37     paint.getTextBounds (text, 0, 1, bounds);
    38 
    39     metrics.lbearing = (short) bounds.left;
    40     metrics.rbearing = (short) bounds.right;
    41     metrics.ascent = (short) -bounds.top;
    42     metrics.descent = (short) bounds.bottom;
    43     metrics.width
    44       = (short) paint.getRunAdvance (text, 0, 1, 0, 1, false, 1);
    45   }
    46 
    47   @Override
    48   public void
    49   textExtents (FontObject font, int code[], FontMetrics fontMetrics)
    50   {
    51     int i;
    52     Paint paintCache;
    53     Rect boundsCache;
    54     Sdk7FontObject fontObject;
    55     char[] text;
    56     float width;
    57 
    58     fontObject = (Sdk7FontObject) font;
    59     paintCache = fontObject.typeface.typefacePaint;
    60     paintCache.setTextSize (fontObject.pixelSize);
    61     boundsCache = new Rect ();
    62 
    63     if (code.length == 0)
    64       {
    65         fontMetrics.lbearing = 0;
    66         fontMetrics.rbearing = 0;
    67         fontMetrics.ascent = 0;
    68         fontMetrics.descent = 0;
    69         fontMetrics.width = 0;
    70       }
    71     else if (code.length == 1)
    72       textExtents1 ((Sdk7FontObject) font, code[0], fontMetrics,
    73                     paintCache, boundsCache);
    74     else
    75       {
    76         text = new char[code.length + 1];
    77 
    78         for (i = 0; i < code.length; ++i)
    79           text[i] = (char) code[i];
    80 
    81         text[code.length] = 'c';
    82 
    83         paintCache.getTextBounds (text, 0, code.length,
    84                                   boundsCache);
    85         width = paintCache.getRunAdvance (text, 0, code.length, 0,
    86                                           code.length,
    87                                           false, code.length);
    88 
    89         fontMetrics.lbearing = (short) boundsCache.left;
    90         fontMetrics.rbearing = (short) boundsCache.right;
    91         fontMetrics.ascent = (short) -boundsCache.top;
    92         fontMetrics.descent = (short) boundsCache.bottom;
    93         fontMetrics.width = (short) width;
    94       }
    95   }
    96 
    97   @Override
    98   public int
    99   hasChar (FontSpec font, char charCode)
   100   {
   101     Sdk7FontObject fontObject;
   102     Paint paint;
   103 
   104     if (font instanceof Sdk7FontObject)
   105       {
   106         fontObject = (Sdk7FontObject) font;
   107         paint = fontObject.typeface.typefacePaint;
   108       }
   109     else
   110       paint = ((Sdk7FontEntity) font).typeface.typefacePaint;
   111 
   112     return paint.hasGlyph (String.valueOf (charCode)) ? 1 : 0;
   113   }
   114 };

/* [<][>][^][v][top][bottom][index][help] */