Commit 3f193047 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

simplify the TextLine struct

parent 61c0e055
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ ReturnCode text_analyze_bidi_line(
    const TextSpan* text_end,
    TextDirection text_direction_base,
    TextLine* text_line) {
  text_line->text_direction_base = text_direction_base;
  text_line->base_direction = text_direction_base;

  FriBidiParType fb_basedir;
  switch (text_direction_base) {
@@ -105,9 +105,9 @@ ReturnCode text_analyze_bidi_line(
        run_len,
        run.data()));

    text_line->text_runs.emplace_back(run);
    text_line->text_spans.emplace_back(fb_to_span_map[run_begin]);
    text_line->text_bidi_levels.emplace_back(int(fb_levels[run_begin]));
    text_line->runs.emplace_back(run);
    text_line->span_map.emplace_back(fb_to_span_map[run_begin]);
    text_line->bidi_levels.emplace_back(int(fb_levels[run_begin]));
  }

  return OK;
+13 −13
Original line number Diff line number Diff line
@@ -78,17 +78,17 @@ Status text_layout_hline(
  double line_length = 0;
  for (auto i : visual_order) {
    TextDirection text_direction_run =
        text_line.text_bidi_levels[i] & 1 ?
        text_line.bidi_levels[i] & 1 ?
            TextDirection::RTL :
            TextDirection::LTR;

    double span_length = 0.0;
    std::vector<GlyphPlacement> span_glyphs;
    auto rc = text_layout_hrun(
        text_line.text_runs[i],
        text_line.runs[i],
        text_direction_run,
        text_line.text_spans[i]->language,
        text_line.text_spans[i]->script,
        text_line.span_map[i]->language,
        text_line.span_map[i]->script,
        font_info,
        font_size,
        dpi,
@@ -102,7 +102,7 @@ Status text_layout_hline(
    }

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

  double line_left = 0.0;
  switch (text_line.text_direction_base) {
  switch (text_line.base_direction) {
    case TextDirection::LTR:
      line_left = 0;
      break;
@@ -193,7 +193,7 @@ Status text_measure_span(
//    higher."
//
std::vector<size_t> text_get_visual_order(const TextLine& line) {
  std::vector<size_t> visual_order(line.text_runs.size(), 0);
  std::vector<size_t> visual_order(line.runs.size(), 0);

  std::iota(
      visual_order.begin(),
@@ -201,17 +201,17 @@ std::vector<size_t> text_get_visual_order(const TextLine& line) {
      0);

  size_t level_max = *std::max_element(
      line.text_bidi_levels.begin(),
      line.text_bidi_levels.end());
      line.bidi_levels.begin(),
      line.bidi_levels.end());

  for (size_t level_cur = level_max; level_cur >= 1; --level_cur) {
    for (size_t range_begin = 0; range_begin < line.text_runs.size(); ) {
    for (size_t range_begin = 0; range_begin < line.runs.size(); ) {
      // find the next contiguous range where level >= level_cur starting at
      // begin
      auto range_end = range_begin;
      for (;
          line.text_bidi_levels[range_end] >= level_cur &&
          range_end != line.text_runs.size();
          line.bidi_levels[range_end] >= level_cur &&
          range_end != line.runs.size();
          ++range_end);

      // if no such sequence starts at begin, try searching from the next index
@@ -233,7 +233,7 @@ std::vector<size_t> text_get_visual_order(const TextLine& line) {
  // if the base direction is RTL, reverse the direction of all runs so that
  // the "first" element in the visual order array is the one at the begining
  // of the line in our base writing direction
  switch (line.text_direction_base) {
  switch (line.base_direction) {
    case TextDirection::LTR:
      break;
    case TextDirection::RTL:
+15 −7
Original line number Diff line number Diff line
@@ -20,7 +20,8 @@ namespace fviz::text {

/**
 * A text span represents a discrete, non-breakable piece of text. Text spans are
 * the smallest unit of text for layout.
 * the smallest unit of text for layout. Text spans are the input to the text
 * layout process.
 *
 * 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.
@@ -57,7 +58,7 @@ struct TextSpan {


/**
 * A line of text
 * A line of text that has been prepared for final layout.
 *
 * 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
@@ -66,17 +67,24 @@ struct TextSpan {
 * 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.
 *
 * The `base_direction` contains the inteded display writing direction for this
 * line.
 *
 * The `span_map` contains a pointer to the source span for each of the text run
 * and the `bidi_levels` property contains the Unicode BiDi embedding levels for
 * each text run in the line.
 */
struct TextLine {
  std::vector<std::string> text_runs;
  TextDirection text_direction_base;
  std::vector<const TextSpan*> text_spans;
  std::vector<int> text_bidi_levels;
  std::vector<std::string> runs;
  TextDirection base_direction;
  std::vector<const TextSpan*> span_map;
  std::vector<int> bidi_levels;
};


/**
 * The output of the text layouting process is a list of glyph placements. The
 * The output of the text layout process is a list of glyph placements. The
 * coordinates are absolute screen positions
 */
struct GlyphPlacement {