Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add character dimensions API #702

Open
Tyriar opened this issue Jun 13, 2017 · 3 comments
Open

Add character dimensions API #702

Tyriar opened this issue Jun 13, 2017 · 3 comments
Labels
area/api type/enhancement Features or improvements to existing features

Comments

@Tyriar
Copy link
Member

Tyriar commented Jun 13, 2017

VS Code has it's own character measure implementation for example. @parisk thoughts?

Related: #696

@Tyriar Tyriar added the type/proposal A proposal that needs some discussion before proceeding label Jun 13, 2017
@Tyriar Tyriar closed this as completed Jun 3, 2018
@Tyriar Tyriar added the area/api label Jul 6, 2018
@Tyriar Tyriar reopened this Jul 6, 2018
@Tyriar
Copy link
Member Author

Tyriar commented Jul 6, 2018

Just did a bit of research into what we actually want here, this is what I came up with.

  • VS Code:
    • TerminalConfigHelper.getFont
      • Uses charMeasure.width and charMeasure.height
      • Bug: Panes don't take line height and letter spacing into account
    • TerminalInstance._evaluateColsAndRows
      • Uses getFont
      • Calculates scaledCharWidth (with letter spacing for canvas) and scaledLineHeight. These are used to set cols and rows. These are scaledCellWidth/Height
      • Could use actualCellHeight/Width
      • Dimensions is not ready when we need it in _evaluateColsAndRows. Related to Handle terminal.open on an element that is not (yet) attached to the dom #1158, vscode actually calls open before it's attached and while it's probably possible to attach earlier I don't think I could make it visible which breaks CharMeasure.measure as well.
  • fit
    • Uses actualCellWidth
    • Uses actualCellHeight
  • Hyper
    • Calls CharMeasure.measure manually (possibly for the same open issue as vscode)
    • Uses fit addon
interface IDimensions {
  width: number;
  height: number;
}

export class Terminal {
  dimensions: {
    // dimensions.actualCellWidth/Height
    cell: IDimensions;
    // Convenience: container.width = cell.width*terminal.cols = dimensions.canvasWidth
    // Generic language
    container: IDimensions;
  }
}

My proposal to fix the .open issue is to allow a helper container to be passed into the constructor as an option.

export interface ITerminalOptions {
  /**
   * Specifying this option will use the container for the element that
   * enabled character measurement. The idea is to provide a container that is
   * always visible to host the _offscreen_ element such that even if you call
   * Terminal.open on an element that is not yet visible on the page, it can
   * still get character measurements and initialize the terminal. If you do
   * not set this, Terminal.dimensions will not be available until shortly
   * after Terminal.open is called. This element will not be removed when
   * Terminal.dispose is called.
   *
   * NOTE: It's important that the CSS styles don't differ from that of the
   * element that is passed to Terminal.open, otherwise the measurements could
   * be off.
   *
   * NOTE: Setting this will also enable sharing of the character measurement
   * element across multiple terminals. However, because of this it's not
   * recommended to use the same measureContainer across multiple terminals
   * that have differing font settings.
   */
  measureContainer: HTMLElement;
}

measureContainer could be used as a container to host (and share) the .xterm-char-measure-element. Allowing characters to be measured during the call to open. The only thing to worry about here is CSS styles that differ on measureContainer and Terminal.element. We will probably want to be very explicit in the comment for measureContainer as well as adding and needed styles to .xterm-char-measure-element in xterm.css.

@Tyriar Tyriar changed the title Should character dimensions via the charMeasure object be public API? Should character dimensions via the CharMeasureService object be public API? Oct 7, 2019
@Tyriar Tyriar changed the title Should character dimensions via the CharMeasureService object be public API? Should character dimensions be public API? Oct 7, 2019
@Tyriar
Copy link
Member Author

Tyriar commented Oct 7, 2019

We probably actually want to expose the dimensions on the renderer and eventually phase out CharSizeService all together if possible. We definitely should do this as pretty much every project I look at looks at the dimenisons via private API.

@Tyriar Tyriar added type/enhancement Features or improvements to existing features and removed type/proposal A proposal that needs some discussion before proceeding labels Oct 14, 2019
@Tyriar
Copy link
Member Author

Tyriar commented Dec 27, 2019

To clarify, this should not expose char measure but rather the dimensions of a cell for the specific renderer. The dom renderer cells are < 1px larger than canvas/webgl since they always render on the a round integer x coord. See microsoft/vscode#87153 for more context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/api type/enhancement Features or improvements to existing features
Projects
None yet
Development

No branches or pull requests

1 participant