Commit 9bca55b5 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

improved documentation of the text layout code

parent 5d0fd782
Loading
Loading
Loading
Loading
+24 −7
Original line number Diff line number Diff line
@@ -59,16 +59,13 @@ Status text_layout_hrun(
}

Status text_layout_hline(
    const std::string& text_logical,
    const TextDirection base_text_direction,
    const TextLine& text_line,
    const TextDirection text_direction_base,
    const FontInfo& font_info,
    double font_size,
    double dpi,
    std::vector<GlyphSpan>* glyph_spans,
    Rectangle* bbox) {
  TextLine text_line;
  text_analyze_bidi_line(text_logical, base_text_direction, &text_line);

  double line_top = 0.0;
  double line_bottom = 0.0;
  double line_length = 0;
@@ -92,7 +89,7 @@ Status text_layout_hline(
    }

    for (auto& gi : span_glyphs) {
      switch (base_text_direction) {
      switch (text_direction_base) {
        case TextDirection::LTR:
          gi.x += line_length;
          break;
@@ -116,7 +113,7 @@ Status text_layout_hline(
  }

  double line_left = 0.0;
  switch (base_text_direction) {
  switch (text_direction_base) {
    case TextDirection::LTR:
      line_left = 0;
      break;
@@ -134,6 +131,26 @@ Status text_layout_hline(
  return OK;
}

Status text_layout_hline(
    const std::string& text_logical,
    const TextDirection base_text_direction,
    const FontInfo& font_info,
    double font_size,
    double dpi,
    std::vector<GlyphSpan>* glyph_spans,
    Rectangle* bbox) {
  TextLine text_line;
  text_analyze_bidi_line(text_logical, base_text_direction, &text_line);

  return text_layout_hline(
      text_line,
      base_text_direction,
      font_info,
      font_size,
      dpi,
      glyph_spans,
      bbox);
}

Status text_measure_span(
    const std::string& text,
+29 −9
Original line number Diff line number Diff line
@@ -40,6 +40,10 @@ struct TextLine {
  std::vector<TextDirection> text_directions;
};

/**
 * The output of the text layout stack is a list of glyph placements. The
 * coordinates are absolute screen positions
 */
struct GlyphPlacement {
  FontRef font;
  uint32_t codepoint;
@@ -53,28 +57,44 @@ struct GlyphSpan {
};

/**
 * Measure the size of a horizontal span of text where (0, 0) is the baseline of
 * the first glyph
 * Layout a horizontal line of text. The input text must be provided in UTF-8
 * encoding and in logical character order. The `text_direction_base` argument
 * controls the base writing direction of the line
 */
Status text_measure_span(
    const std::string& text,
    const FontInfo& font_info,
Status text_layout_hline(
    const TextLine& line,
    TextDirection base_direction,
    const FontInfo& font,
    double font_size,
    double dpi,
    Rectangle* rect);
    std::vector<GlyphSpan>* spans,
    Rectangle* bbox);

/**
 * Layout a horizontal line of text
 * Layout a horizontal line of text. The input text must be provided in UTF-8
 * encoding and in logical character order. The `text_direction_base` argument
 * controls the base writing direction of the line
 */
Status text_layout_hline(
    const std::string& text,
    TextDirection direction,
    const std::string& text_logical,
    TextDirection base_direction,
    const FontInfo& font,
    double font_size,
    double dpi,
    std::vector<GlyphSpan>* spans,
    Rectangle* bbox);

/**
 * Measure the size of a horizontal span of text where (0, 0) is the baseline of
 * the first glyph
 */
Status text_measure_span(
    const std::string& text,
    const FontInfo& font_info,
    double font_size,
    double dpi,
    Rectangle* rect);

} // namespace text
} // namespace fviz
+3 −21
Original line number Diff line number Diff line
@@ -30,10 +30,9 @@ struct GlyphInfo {
  double metrics_descender;
};

using GlyphRun = std::vector<GlyphInfo>;

/**
 * Shape a "run" of text with a given font
 * Shape a "run" of text with a given font and a given text direction. The
 * text must be provided as a UTF-8 string in logical character order.
 */
Status text_shape_run(
    const std::string& text,
@@ -44,7 +43,7 @@ Status text_shape_run(
    std::vector<GlyphInfo>* glyphs);

/**
 * Shape a "run" of text with font fallback. 
 * Shape a "run" of UTF-8 text in logical character order with font fallback
 */
Status text_shape_run_with_font_fallback(
    const std::string& text,
@@ -54,23 +53,6 @@ Status text_shape_run_with_font_fallback(
    double dpi,
    std::vector<GlyphInfo>* glyphs);

/**
 * "Shape" a non-breakable span of text. Input is a UTF8 string in logical order
 * and the intended text rendering direction. Output is a "glyph run", i.e. a
 * list of glyphs in the order in which they should be displayed. Note that this
 * method performs bidi reordering to 'visual' order, so the output of this
 * method is not suitable for line breaking. If line breaking is desired, it
 * must be handled by a mechanism higher up in the stack that only calls `text_shape`
 * for non-breakable spans of text (i.e. words).
 */
Status text_shape(
    const std::string& text,
    TextDirection text_direction,
    FontRef font,
    double font_size,
    double dpi,
    std::vector<GlyphInfo>* glyphs);

} // namespace text
} // namespace fviz