<commit_before>/*
 * STLL Simple Text Layouting Library
 *
 * STLL is the legal property of its developers, whose
 * names are listed in the COPYRIGHT file, which is included
 * within the source distribution.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2.1
 * of the License, or (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
#ifndef __LAYOUTER_H__
#define __LAYOUTER_H__

/** \file
 *  \brief the paragraph layouter and its helpers
 */

#include "layouterFont.h"

#include "color.h"

#include <boost/icl/split_interval_map.hpp>
#include <boost/icl/closed_interval.hpp>

#include <string>
#include <vector>
#include <memory>

/** \brief The namespace for the library.
 *  Every function and class is within this namespace.
 */
namespace STLL {

/** \brief encapsulates a finished layout.
 *
 * This class encapsulates a layout, it is a list of drawing commands.
 */
class textLayout_c
{
  private:
    uint32_t height; // position where you can add additional text after this ...
    int32_t left, right;

  public:

    /** \brief This structure encapsulates a drawing command
     */
    typedef struct
    {
      enum
      {
        CMD_GLYPH,  ///< draw a glyph from a font
        CMD_RECT,   ///< draw a rectangle
        CMD_IMAGE   ///< draw an image
      } command;    ///< specifies what to draw

      /** \name position of the glyph, or upper left corner of rectangle or image
       *  @{ */
      int32_t x;  ///< x position
      int32_t y;  ///< y position
      /** @} */

      /** \brief which glyph to draw */
      FT_UInt glyphIndex;

      /** \brief which front to take the glyph from */
      std::shared_ptr<fontFace_c> font;

      /** \name width and height of the rectangle to draw
       *  @{ */
      uint32_t w;  ///< width of block
      uint32_t h;  ///< height of block
      /** @} */

      /** \brief colour of the glyph or the rectangle */
      color_c c;

      std::string imageURL; ///< URL of image to draw

    } commandData;

    // order is the logical order, so when you do copy and paste we copy out of this using the order
    // within the vector
    // TODO find better solution instead of public vector
    std::vector<commandData> data;

    /** \brief add a single drawing command to the end of the command list
     *  \param d the command to add
     */
    void addCommand(const commandData & d)
    {
      data.push_back(d);
    }

    /** \brief add a single drawing command to the start of the command list
     *  \param d the command to add
     */
    void addCommandStart(const commandData & d)
    {
      data.insert(data.begin(), d);
    }

    /** \brief add whole vector of commands to the layout, the commands are offset
     *         by a certain amount to shift everything that is drawn
     *  \param d the commands to add
     *  \param dx the x offset
     *  \param dy the y offset
     */
    void addCommandVector(const std::vector<commandData> & d, int dx, int dy)
    {
      for (auto a : d)
      {
        a.x += dx;
        a.y += dy;
        data.emplace_back(a);
      }
    }

    /** \brief append a layout to this layout, which means that the drawing
     *         commands of the 2nd layout are copied into this layout
     *  \param l the layout to append
     */
    void append(const textLayout_c & l)
    {
      for (auto & a : l.data)
        data.push_back(a);

      height = std::max(height, l.height);
    }

    /** \brief move assignment
     */
    void operator=(textLayout_c && l)
    {
      data.swap(l.data);
      height = l.height;
    }

    /** \brief copy assignment
     */
    void operator=(const textLayout_c & l)
    {
      data = l.data;
      height = l.height;
    }

    ~textLayout_c(void) { }

    /** \brief create empty layout
     */
    textLayout_c(void) : height(0) { }

    /** \brief copy constructor
     */
    textLayout_c(const textLayout_c & src) : height(src.height), left(src.left),
                                             right(src.right), data(src.data)  {  }
<commit_msg>fix a lot of copy-problems with the left and right edge of a layout<commit_after>/*
 * STLL Simple Text Layouting Library
 *
 * STLL is the legal property of its developers, whose
 * names are listed in the COPYRIGHT file, which is included
 * within the source distribution.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2.1
 * of the License, or (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
#ifndef __LAYOUTER_H__
#define __LAYOUTER_H__

/** \file
 *  \brief the paragraph layouter and its helpers
 */

#include "layouterFont.h"

#include "color.h"

#include <boost/icl/split_interval_map.hpp>
#include <boost/icl/closed_interval.hpp>

#include <string>
#include <vector>
#include <memory>

/** \brief The namespace for the library.
 *  Every function and class is within this namespace.
 */
namespace STLL {

/** \brief encapsulates a finished layout.
 *
 * This class encapsulates a layout, it is a list of drawing commands.
 */
class textLayout_c
{
  private:
    uint32_t height; // position where you can add additional text after this ...
    int32_t left, right;

  public:

    /** \brief This structure encapsulates a drawing command
     */
    typedef struct
    {
      enum
      {
        CMD_GLYPH,  ///< draw a glyph from a font
        CMD_RECT,   ///< draw a rectangle
        CMD_IMAGE   ///< draw an image
      } command;    ///< specifies what to draw

      /** \name position of the glyph, or upper left corner of rectangle or image
       *  @{ */
      int32_t x;  ///< x position
      int32_t y;  ///< y position
      /** @} */

      /** \brief which glyph to draw */
      FT_UInt glyphIndex;

      /** \brief which front to take the glyph from */
      std::shared_ptr<fontFace_c> font;

      /** \name width and height of the rectangle to draw
       *  @{ */
      uint32_t w;  ///< width of block
      uint32_t h;  ///< height of block
      /** @} */

      /** \brief colour of the glyph or the rectangle */
      color_c c;

      std::string imageURL; ///< URL of image to draw

    } commandData;

    // order is the logical order, so when you do copy and paste we copy out of this using the order
    // within the vector
    // TODO find better solution instead of public vector
    std::vector<commandData> data;

    /** \brief add a single drawing command to the end of the command list
     *  \param d the command to add
     */
    void addCommand(const commandData & d)
    {
      data.push_back(d);
    }

    /** \brief add a single drawing command to the start of the command list
     *  \param d the command to add
     */
    void addCommandStart(const commandData & d)
    {
      data.insert(data.begin(), d);
    }

    /** \brief add whole vector of commands to the layout, the commands are offset
     *         by a certain amount to shift everything that is drawn
     *  \param d the commands to add
     *  \param dx the x offset
     *  \param dy the y offset
     */
    void addCommandVector(const std::vector<commandData> & d, int dx, int dy)
    {
      for (auto a : d)
      {
        a.x += dx;
        a.y += dy;
        data.emplace_back(a);
      }
    }

    /** \brief append a layout to this layout, which means that the drawing
     *         commands of the 2nd layout are copied into this layout
     *  \param l the layout to append
     */
    void append(const textLayout_c & l)
    {
      for (auto & a : l.data)
        data.push_back(a);

      height = std::max(height, l.height);
      left = std::min(left, l.left);
      right = std::max(right, l.right);
    }

    /** \brief move assignment
     */
    void operator=(textLayout_c && l)
    {
      data.swap(l.data);
      height = l.height;
      left = l.left;
      right = l.right;
    }

    /** \brief copy assignment
     */
    void operator=(const textLayout_c & l)
    {
      data = l.data;
      height = l.height;
      left = l.left;
      right = l.right;
    }

    ~textLayout_c(void) { }

    /** \brief create empty layout
     */
    textLayout_c(void) : height(0), left(0), right(0) { }

    /** \brief copy constructor
     */
    textLayout_c(const textLayout_c & src) : height(src.height), left(src.left),
                                             right(src.right), data(src.data)  {  }

{'fraction_non_alphanumeric': 0.09701492537313433, 'fraction_numerical': 0.006516712213579987, 'mean_word_length': 2.2047827551364096, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3649309', 'n_tokens_mistral': 2822, 'n_tokens_neox': 2712, 'n_words': 1109}