Debian Codegraph @

node/@xterm/addon-webgl/src/CharAtlasUtils.ts

raw
1 /**
2 * Copyright (c) 2017 The xterm.js authors. All rights reserved.
3 * @license MIT
4 */
5
6 import { ICharAtlasConfig } from './Types';
7 import { Attributes } from 'common/buffer/Constants';
8 import { ITerminalOptions } from '@xterm/xterm';
9 import { IColorSet, ReadonlyColorSet } from 'browser/Types';
10 import { NULL_COLOR } from 'common/Color';
11
12 export function generateConfig(deviceCellWidth: number, deviceCellHeight: number, deviceCharWidth: number, deviceCharHeight: number, options: Required<ITerminalOptions>, colors: ReadonlyColorSet, devicePixelRatio: number, deviceMaxTextureSize: number): ICharAtlasConfig {
13 // null out some fields that don't matter
14 const clonedColors: IColorSet = {
15 foreground: colors.foreground,
16 background: colors.background,
17 cursor: NULL_COLOR,
18 cursorAccent: NULL_COLOR,
19 selectionForeground: NULL_COLOR,
20 selectionBackgroundTransparent: NULL_COLOR,
21 selectionBackgroundOpaque: NULL_COLOR,
22 selectionInactiveBackgroundTransparent: NULL_COLOR,
23 selectionInactiveBackgroundOpaque: NULL_COLOR,
24 overviewRulerBorder: NULL_COLOR,
25 scrollbarSliderBackground: NULL_COLOR,
26 scrollbarSliderHoverBackground: NULL_COLOR,
27 scrollbarSliderActiveBackground: NULL_COLOR,
28 // For the static char atlas, we only use the first 16 colors, but we need all 256 for the
29 // dynamic character atlas.
30 ansi: colors.ansi.slice(),
31 contrastCache: colors.contrastCache,
32 halfContrastCache: colors.halfContrastCache
33 };
34 return {
35 customGlyphs: options.customGlyphs,
36 devicePixelRatio,
37 deviceMaxTextureSize,
38 letterSpacing: options.letterSpacing,
39 lineHeight: options.lineHeight,
40 deviceCellWidth: deviceCellWidth,
41 deviceCellHeight: deviceCellHeight,
42 deviceCharWidth: deviceCharWidth,
43 deviceCharHeight: deviceCharHeight,
44 fontFamily: options.fontFamily,
45 fontSize: options.fontSize,
46 fontWeight: options.fontWeight,
47 fontWeightBold: options.fontWeightBold,
48 allowTransparency: options.allowTransparency,
49 drawBoldTextInBrightColors: options.drawBoldTextInBrightColors,
50 minimumContrastRatio: options.minimumContrastRatio,
51 colors: clonedColors
52 };
53 }
54
55 export function configEquals(a: ICharAtlasConfig, b: ICharAtlasConfig): boolean {
56 for (let i = 0; i < a.colors.ansi.length; i++) {
57 if (a.colors.ansi[i].rgba !== b.colors.ansi[i].rgba) {
58 return false;
59 }
60 }
61 return a.devicePixelRatio === b.devicePixelRatio &&
62 a.customGlyphs === b.customGlyphs &&
63 a.lineHeight === b.lineHeight &&
64 a.letterSpacing === b.letterSpacing &&
65 a.fontFamily === b.fontFamily &&
66 a.fontSize === b.fontSize &&
67 a.fontWeight === b.fontWeight &&
68 a.fontWeightBold === b.fontWeightBold &&
69 a.allowTransparency === b.allowTransparency &&
70 a.deviceCharWidth === b.deviceCharWidth &&
71 a.deviceCharHeight === b.deviceCharHeight &&
72 a.drawBoldTextInBrightColors === b.drawBoldTextInBrightColors &&
73 a.minimumContrastRatio === b.minimumContrastRatio &&
74 a.colors.foreground.rgba === b.colors.foreground.rgba &&
75 a.colors.background.rgba === b.colors.background.rgba;
76 }
77
78 export function is256Color(colorCode: number): boolean {
79 return (colorCode & Attributes.CM_MASK) === Attributes.CM_P16 || (colorCode & Attributes.CM_MASK) === Attributes.CM_P256;
80 }