<commit_before>package org.pentaho.reporting.engine.classic.core.layout.model;

import java.awt.font.TextLayout;

import org.pentaho.reporting.engine.classic.core.ReportAttributeMap;
import org.pentaho.reporting.engine.classic.core.layout.model.context.NodeLayoutProperties;
import org.pentaho.reporting.engine.classic.core.layout.process.util.RichTextSpec;
import org.pentaho.reporting.engine.classic.core.metadata.ElementType;
import org.pentaho.reporting.engine.classic.core.style.StyleSheet;
import org.pentaho.reporting.engine.classic.core.util.InstanceID;

public class RenderableComplexText extends RenderNode
{
  private RichTextSpec richText;
  private String text;
  private TextLayout textLayout;
  private boolean forceLinebreak;

  public RenderableComplexText(final StyleSheet styleSheet,
                               final InstanceID instanceID,
                               final ElementType elementType,
                               final ReportAttributeMap attributes,
                               final RichTextSpec text)
  {
    super(new NodeLayoutProperties(styleSheet, attributes, instanceID, elementType));
    this.text = text.getText();
    this.richText = text;
    this.forceLinebreak = false;
  }

  public RenderableComplexText(final StyleSheet styleSheet,
                               final InstanceID instanceID,
                               final ElementType elementType,
                               final ReportAttributeMap attributes,
                               final String text)
  {
    super(new NodeLayoutProperties(styleSheet, attributes, instanceID, elementType));
    this.text = text;
    this.richText = null;
    this.forceLinebreak = false;
  }

  public int getNodeType()
  {
    return LayoutNodeTypes.TYPE_NODE_COMPLEX_TEXT;
  }

  public String getRawText()
  {
    return text;
  }

  public RichTextSpec getRichText()
  {
    if (richText == null){
      // code-smell - we probably should introduce a "ProcessedComplexText" type to distinguish between
      // raw text and text that has been processed by the CanvasMinor-step.
      throw new IllegalStateException("Calling 'getRichText' is only valid after layouting is complete.");
    }
    return richText;
  }

  public TextLayout getTextLayout()
  {
    return textLayout;
  }

  public void setTextLayout(final TextLayout textLayout)
  {
    this.textLayout = textLayout;
  }

  public void setForceLinebreak(final boolean forceLinebreak)
  {
    this.forceLinebreak = forceLinebreak;
  }

  public boolean isForceLinebreak()
  {
    return forceLinebreak;
  }

}
<commit_msg>Compute MCW for RenderableComplexText<commit_after>package org.pentaho.reporting.engine.classic.core.layout.model;

import java.awt.font.TextLayout;
import java.text.BreakIterator;

import org.pentaho.reporting.engine.classic.core.ReportAttributeMap;
import org.pentaho.reporting.engine.classic.core.layout.model.context.NodeLayoutProperties;
import org.pentaho.reporting.engine.classic.core.layout.process.util.RichTextSpec;
import org.pentaho.reporting.engine.classic.core.metadata.ElementType;
import org.pentaho.reporting.engine.classic.core.style.StyleSheet;
import org.pentaho.reporting.engine.classic.core.util.InstanceID;

public class RenderableComplexText extends RenderNode
{
  private RichTextSpec richText;
  private String text;
  private TextLayout textLayout;
  private boolean forceLinebreak;

  public RenderableComplexText(final StyleSheet styleSheet,
                               final InstanceID instanceID,
                               final ElementType elementType,
                               final ReportAttributeMap attributes,
                               final RichTextSpec text)
  {
    super(new NodeLayoutProperties(styleSheet, attributes, instanceID, elementType));
    this.text = text.getText();
    this.richText = text;
    this.forceLinebreak = false;
    initialize(this.text);
  }

  public RenderableComplexText(final StyleSheet styleSheet,
                               final InstanceID instanceID,
                               final ElementType elementType,
                               final ReportAttributeMap attributes,
                               final String text)
  {
    super(new NodeLayoutProperties(styleSheet, attributes, instanceID, elementType));
    this.text = text;
    this.richText = null;
    this.forceLinebreak = false;
    initialize(this.text);
  }

  /**
   * Compute the 'minimum chunk width' (MCW)
   * @param source
   */
  protected void initialize(String source) {
    long minimumChunkWidth = 0;
    BreakIterator wordInstance = BreakIterator.getWordInstance();
    wordInstance.setText(source);

    int start = wordInstance.first();
    for (int end = wordInstance.next(); end != BreakIterator.DONE; start = end, end = wordInstance.next()) {
       long wordMinChunkWidth = source.substring(start,end).length();
       minimumChunkWidth = Math.max(minimumChunkWidth, wordMinChunkWidth);
    }

    setMinimumChunkWidth(minimumChunkWidth);
  }

  public int getNodeType()
  {
    return LayoutNodeTypes.TYPE_NODE_COMPLEX_TEXT;
  }

  public String getRawText()
  {
    return text;
  }

  public RichTextSpec getRichText()
  {
    if (richText == null){
      // code-smell - we probably should introduce a "ProcessedComplexText" type to distinguish between
      // raw text and text that has been processed by the CanvasMinor-step.
      throw new IllegalStateException("Calling 'getRichText' is only valid after layouting is complete.");
    }
    return richText;
  }

  public TextLayout getTextLayout()
  {
    return textLayout;
  }

  public void setTextLayout(final TextLayout textLayout)
  {
    this.textLayout = textLayout;
  }

  public void setForceLinebreak(final boolean forceLinebreak)
  {
    this.forceLinebreak = forceLinebreak;
  }

  public boolean isForceLinebreak()
  {
    return forceLinebreak;
  }

}

{'fraction_non_alphanumeric': 0.07729957805907173, 'fraction_numerical': 0.00016877637130801687, 'mean_word_length': 2.942781104457751, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3408634', 'n_tokens_mistral': 1610, 'n_tokens_neox': 1582, 'n_words': 370}