lib/browser/GraphBrowser/DefaultFontMetrics.java
author nipkow
Mon, 11 Jun 2018 16:29:27 +0200
changeset 68413 b56ed5010e69
parent 50473 ca4088bf8365
permissions -rw-r--r--
tuned order of arguments
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11799
533a95523f61 Font metrics used for batch mode layout (without X11 connection).
berghofe
parents:
diff changeset
     1
/***************************************************************************
533a95523f61 Font metrics used for batch mode layout (without X11 connection).
berghofe
parents:
diff changeset
     2
  Title:      GraphBrowser/DefaultFontMetrics.java
533a95523f61 Font metrics used for batch mode layout (without X11 connection).
berghofe
parents:
diff changeset
     3
  Author:     Stefan Berghofer, TU Muenchen
50473
ca4088bf8365 added speculative options for jEdit;
wenzelm
parents: 33686
diff changeset
     4
  Options:    :tabSize=2:
11799
533a95523f61 Font metrics used for batch mode layout (without X11 connection).
berghofe
parents:
diff changeset
     5
533a95523f61 Font metrics used for batch mode layout (without X11 connection).
berghofe
parents:
diff changeset
     6
  Default font metrics which is used when no graphics context
13970
4aef7117817b cleanup, comments
kleing
parents: 13968
diff changeset
     7
  is available (batch mode).
11799
533a95523f61 Font metrics used for batch mode layout (without X11 connection).
berghofe
parents:
diff changeset
     8
***************************************************************************/
533a95523f61 Font metrics used for batch mode layout (without X11 connection).
berghofe
parents:
diff changeset
     9
533a95523f61 Font metrics used for batch mode layout (without X11 connection).
berghofe
parents:
diff changeset
    10
package GraphBrowser;
533a95523f61 Font metrics used for batch mode layout (without X11 connection).
berghofe
parents:
diff changeset
    11
13968
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents: 11874
diff changeset
    12
public class DefaultFontMetrics implements AbstractFontMetrics {
11799
533a95523f61 Font metrics used for batch mode layout (without X11 connection).
berghofe
parents:
diff changeset
    13
13968
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents: 11874
diff changeset
    14
  private static int[] chars =
11810
4768258b29a5 Inserted table for character widths.
berghofe
parents: 11799
diff changeset
    15
	{13, 13, 17, 27, 27, 43, 32, 11, 16, 16, 19, 28, 13, 28, 13, 13, 27,
4768258b29a5 Inserted table for character widths.
berghofe
parents: 11799
diff changeset
    16
	 27, 27, 27, 27, 27, 27, 27, 27, 27, 13, 13, 28, 28, 28, 27, 49, 32,
4768258b29a5 Inserted table for character widths.
berghofe
parents: 11799
diff changeset
    17
	 32, 35, 35, 32, 29, 37, 35, 13, 24, 32, 27, 40, 35, 37, 32, 37, 35,
4768258b29a5 Inserted table for character widths.
berghofe
parents: 11799
diff changeset
    18
	 32, 29, 35, 32, 45, 32, 32, 29, 13, 13, 13, 22, 27, 11, 27, 27, 24,
4768258b29a5 Inserted table for character widths.
berghofe
parents: 11799
diff changeset
    19
	 27, 27, 13, 27, 27, 11, 11, 24, 11, 40, 27, 27, 27, 27, 16, 24, 13,
4768258b29a5 Inserted table for character widths.
berghofe
parents: 11799
diff changeset
    20
	 27, 24, 35, 24, 24, 24, 16, 12, 16, 28};
11799
533a95523f61 Font metrics used for batch mode layout (without X11 connection).
berghofe
parents:
diff changeset
    21
13968
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents: 11874
diff changeset
    22
  private int size;
11799
533a95523f61 Font metrics used for batch mode layout (without X11 connection).
berghofe
parents:
diff changeset
    23
13968
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents: 11874
diff changeset
    24
  public DefaultFontMetrics(int size)
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents: 11874
diff changeset
    25
  { this.size = size; }
11810
4768258b29a5 Inserted table for character widths.
berghofe
parents: 11799
diff changeset
    26
13968
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents: 11874
diff changeset
    27
  public int getLeading()
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents: 11874
diff changeset
    28
  { return 1; }
11799
533a95523f61 Font metrics used for batch mode layout (without X11 connection).
berghofe
parents:
diff changeset
    29
13968
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents: 11874
diff changeset
    30
  public int getAscent()
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents: 11874
diff changeset
    31
  { return (int)(Math.round(size * 46.0 / 48.0)); }
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents: 11874
diff changeset
    32
  
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents: 11874
diff changeset
    33
  public int getDescent() 
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents: 11874
diff changeset
    34
  { return (int)(Math.round(size * 10.0 / 48.0)); }
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents: 11874
diff changeset
    35
  
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents: 11874
diff changeset
    36
  public int charWidth(char c) {
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents: 11874
diff changeset
    37
    if (c < 32 || c > 126) { return 0; }
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents: 11874
diff changeset
    38
    else {
11874
83c97febc828 Constructor no longer takes font as an argument.
berghofe
parents: 11810
diff changeset
    39
	    return (int)(Math.round(chars[c - 32] * size / 48.0));
11810
4768258b29a5 Inserted table for character widths.
berghofe
parents: 11799
diff changeset
    40
    }
13968
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents: 11874
diff changeset
    41
  }
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents: 11874
diff changeset
    42
  
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents: 11874
diff changeset
    43
  public int stringWidth(String s) {
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents: 11874
diff changeset
    44
    int l=0, i;
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents: 11874
diff changeset
    45
    for (i=0; i < s.length(); i++) { l += charWidth(s.charAt(i)); }
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents: 11874
diff changeset
    46
    return l;
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents: 11874
diff changeset
    47
  }
11799
533a95523f61 Font metrics used for batch mode layout (without X11 connection).
berghofe
parents:
diff changeset
    48
}