Commit e32115df authored by Paul Asmuth's avatar Paul Asmuth
Browse files

rename TextSpan -> TextLine

parent e2b8042b
Loading
Loading
Loading
Loading
+0 −44
Original line number Diff line number Diff line
@@ -26,50 +26,6 @@ enum class TextDirection {
  LTR, RTL
};

/**
 * A text span represents a discrete, non-breakable piece of text. Text spans are
 * the smallest unit of text for layout.
 *
 * If any kind of line wrapping is desired, the input text must be split into
 * text spans so that line breaking can be performed on a per span basis. One
 * important caveat of this is that text shaping will also be performed on a
 * per-span basis, so the spans should be as large as possible for the best text
 * shaping results.
 *
 * In latin scripts, text spans should probably correspond to word boundaries.
 * In other scripts, text spans should correspond to whatever unit of text is
 * small enough to allow for text breaking on span-level but large enough so that
 * per-span shaping of text is sufficient.
 *
 * It is allowed to break the line after or before each text span, i.e. spans
 * must be given so that it is legal to place each text span at the beginning of
 * a new line. However it is *not* allowed to break a span itself into smaller
 * pieces; all text runs within the span must be put onto the same line.
 *
 * This interface should enable us to have a high degree of decoupling between
 * the text shaping and layout parts. However, one tradeoff is that it does not
 * allow users to implement some advanced features such as line breaking at
 * character boundaries (i.e breaking and hyphenization of words).
 *
 */
struct TextSpan {
  /**
   * The `text_runs` member contains the spans text runs as a UTF-8 strings.
   * Note that the runs are given in logical order and the characters within
   * the runs are also stored in logical order.
   *
   * Non-bidirectional text spans should usually have exactly one text run while
   * bidirectional text should have N + 1 runs where N is the number of writing
   * direction boundaries in the text span.
   */
  std::vector<std::string> text_runs;

  /**
   * Stores the bidi text direction for each run
   */
  std::vector<TextDirection> text_directions;
};

struct TextStyle {
  TextStyle();
  TextDirection direction;
+5 −4
Original line number Diff line number Diff line
@@ -17,22 +17,23 @@
#include <functional>

#include "text.h"
#include "text_layout.h"

namespace fviz::text {

/**
 * Analyze a UTF-8 input string in logical character order and produce a text
 * span. The output text span will contain all text runs within the span in
 * line. The output text span will contain all text runs within the span in
 * logical order together with their corresponding directionality information.
 *
 * Note that this method returns a single text span, i.e. a non-breakable unit
 * Note that this method returns a single text line, i.e. a non-breakable unit
 * of text. If line breaking is desired, identification of possible breakpoints
 * (spans) must be handled by a mechanism higher up in the stack.
 */
ReturnCode text_analyze_bidi_span(
ReturnCode text_analyze_bidi_line(
    const std::string& text,
    TextDirection text_direction,
    TextSpan* text_span);
    TextLine* text_span);

} // namespace fviz::text
+4 −4
Original line number Diff line number Diff line
@@ -17,10 +17,10 @@

namespace fviz::text {

ReturnCode text_analyze_bidi_span(
ReturnCode text_analyze_bidi_line(
    const std::string& text,
    TextDirection text_direction,
    TextSpan* text_span) {
    TextLine* text_line) {
  FriBidiParType fb_basedir;
  switch (text_direction) {
    case TextDirection::LTR:
@@ -79,8 +79,8 @@ ReturnCode text_analyze_bidi_span(
            TextDirection::RTL :
            TextDirection::LTR;

    text_span->text_runs.emplace_back(run);
    text_span->text_directions.emplace_back(run_direction);
    text_line->text_runs.emplace_back(run);
    text_line->text_directions.emplace_back(run_direction);
  }

  return OK;
+2 −20
Original line number Diff line number Diff line
@@ -27,26 +27,8 @@ Status text_layout_hspan(
    double dpi,
    std::vector<GlyphSpan>* glyph_spans,
    Rectangle* bbox) {
  TextSpan text_span;
  text_analyze_bidi_span(text_logical, text_direction, &text_span);

  for (size_t i = 0; i < text_span.text_runs.size(); ++i) {
    std::string text_run_dir;
    switch (text_span.text_directions[i]) {
      case TextDirection::LTR:
        text_run_dir = "ltr";
        break;
      case TextDirection::RTL:
        text_run_dir = "rtl";
        break;
    }

    std::cerr
        << "t=" << text_span.text_runs[i]
        << " "
        << "d=" << text_run_dir
        << std::endl;
  }
  TextLine text_line;
  text_analyze_bidi_line(text_logical, text_direction, &text_line);

  std::vector<GlyphInfo> glyph_list;
  auto shaping_rc = text_shape_run_with_font_fallback(
+21 −0
Original line number Diff line number Diff line
@@ -19,6 +19,27 @@ namespace fviz {
namespace text {
class TextShaper;

/**
 * A line of text
 */
struct TextLine {
  /**
   * The `text_runs` member contains the line's text runs as a UTF-8 strings.
   * Note that the runs are given in logical order and the characters within
   * the runs are also stored in logical order.
   *
   * Non-bidirectional text spans should usually have exactly one text run while
   * bidirectional text should have N + 1 runs where N is the number of writing
   * direction boundaries in the text span.
   */
  std::vector<std::string> text_runs;

  /**
   * Stores the bidi text direction for each run
   */
  std::vector<TextDirection> text_directions;
};

struct GlyphPlacement {
  uint32_t codepoint;
  double x;