<commit_before># encoding: utf-8
require 'RMagick'

module MagicCloud
  # Thin wrapper around RMagick, incapsulating ALL the real drawing.
  # As it's only class that "knows" about underlying graphics library,
  # it should be possible to replace it with another canvas with same
  # interface, not using RMagick.
  class Canvas
    def initialize(w, h, back = 'transparent')
      @width, @height = w, h
      @internal = Magick::Image.new(w, h){|i| i.background_color =  back}
    end

    attr_reader :internal, :width, :height

    RADIANS = Math::PI / 180

    def draw_text(text, options = {})
      draw = Magick::Draw.new # FIXME: is it necessary every time?
      
      x = options.fetch(:x, 0)
      y = options.fetch(:y, 0)
      rotate = options.fetch(:rotate, 0)

      set_text_options(draw, options)

      rect = _measure_text(draw, text, rotate)

      draw.
        translate(x + rect.width/2, y + rect.height/2).
        rotate(rotate).
        translate(0, rect.height/8). # RMagick text_align seems really weird
        text(0, 0, text).
        draw(@internal)

      rect
    end

    def measure_text(text, options)
      draw = Magick::Draw.new
      set_text_options(draw, options)<commit_msg>Updated the require statement to avoid deprecation warnings. (#10)<commit_after># encoding: utf-8
require 'rmagick'

module MagicCloud
  # Thin wrapper around RMagick, incapsulating ALL the real drawing.
  # As it's only class that "knows" about underlying graphics library,
  # it should be possible to replace it with another canvas with same
  # interface, not using RMagick.
  class Canvas
    def initialize(w, h, back = 'transparent')
      @width, @height = w, h
      @internal = Magick::Image.new(w, h){|i| i.background_color =  back}
    end

    attr_reader :internal, :width, :height

    RADIANS = Math::PI / 180

    def draw_text(text, options = {})
      draw = Magick::Draw.new # FIXME: is it necessary every time?

      x = options.fetch(:x, 0)
      y = options.fetch(:y, 0)
      rotate = options.fetch(:rotate, 0)

      set_text_options(draw, options)

      rect = _measure_text(draw, text, rotate)

      draw.
        translate(x + rect.width/2, y + rect.height/2).
        rotate(rotate).
        translate(0, rect.height/8). # RMagick text_align seems really weird
        text(0, 0, text).
        draw(@internal)

      rect
    end

    def measure_text(text, options)
      draw = Magick::Draw.new
      set_text_options(draw, options)
{'fraction_non_alphanumeric': 0.10856453558504221, 'fraction_numerical': 0.011258544431041415, 'mean_word_length': 2.7696969696969695, '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': '7428578', 'n_tokens_mistral': 813, 'n_tokens_neox': 768, 'n_words': 243}