Плохо! Плохо!:  0
Показано с 1 по 2 из 2

Тема: Text Cache & Custom Font Junk Symbol Fix

  1. #1
    Маститый Аватар для HopeBree
    Информация о пользователе
    Регистрация
    27.03.2013
    Сообщений
    1,204
    Записей в дневнике
    6
    Репутация: 38 Добавить или отнять репутацию

    [VXACE] Text Cache & Custom Font Junk Symbol Fix

    Text Cache & Custom Font Junk Symbol Fix
    Авторы: Mithran & Lone Wolf
    Версия: 1.0
    Тип: Исправление багов




    Описание:

    Исправляет кривое отображение текста и заменяет "квадратики" на пробелы.

    Особенности:


    • Исправляет кривое отображение текст
    • Кэширует текстовые данные, улучшая производительность


    Использование:

    Скрипты работают автоматически. Вставить между ▼ Materials и ▼ Main Process

    Скрипт:

    Код:
      
    class Bitmap
      TEXT_TOP_BUFFER = 2
      TEXT_SIDE_BUFFER = 8 # buffer in pixels to draw text away from 
      # the edge of the bitmap, to prevent certain characters from being cut off
      SIMPLE_FIX = false # just adds the two pixels to prevent unnecessary squeeze
      MAX_TEXT_DRAW_WIDTH = 640 # tests have shown the draw fails at around 640px
      # if nil, no max width
      NO_FIX = false # completely disables the fix, for testing comparison
      
      
      alias draw_text_vxa draw_text
      def draw_text(*args)
        return draw_text_vxa(*args) if NO_FIX
        if args[0].is_a?(Rect)
          rect = args[0]
          x, y, width, height = rect.x, rect.y, rect.width, rect.height
          text = args[1].to_s.clone || ""
          align = args[2] || 0
        else
          x, y, width, height = *args[0..3]
          text = args[4].to_s.clone || ""
          align = args[5] || 0
        end
        text_rect = self.text_size(text)
        text_width = text_rect.width
        text_height = text_rect.height
        squeeze = text_width > width
        if SIMPLE_FIX or (squeeze and (MAX_TEXT_DRAW_WIDTH and width <= MAX_TEXT_DRAW_WIDTH))
          x -= align
          # shift one pixels to the left if centering 
          # two if right right justified
          # to offset the extra width given
          return draw_text_vxa(x, y, width + 2, height, text, align)
        else
          # TextCache.canvas(font) # passing the font slows this down extremly, changed it to later
          fontkey = self.font.to_a
          case align
          when 1; x += (width - text_width) / 2
          when 2; x += width - text_width
          end
          y += (height - text_height) / 2 # horizontal center
          buf = -TEXT_SIDE_BUFFER
          text.each_char { |char|
            letter = TextCache.letters(fontkey, char)
            draw_text_vxa(x + buf, y, letter.rect.width + 2, letter.height, char) if SIMPLE_FIX
            # swap with original method for debugging and simple fix
            self.blt(x + buf, y, letter, letter.rect) unless SIMPLE_FIX
            buf += letter.rect.width - TEXT_SIDE_BUFFER * 2
          }      
        end
      end
    end
    
    module TextCache
      BUFFER_DRAW = 300 # for drawing characters, to make sure there is enough room
      
      def self.canvas(font = nil)
        @canvas = Bitmap.new(32, 32) if @canvas.nil? || @canvas.disposed?
        #@canvas.font = font if font and font != @canvas.font
        @canvas
      end
      
      def self.letters(font, char)
        @cache ||= {}
        key = font + [char]
        if include?(key)
          return @cache[key]
        elsif char.empty?
          return empty_bitmap
        else
          return new_letter(font, char)
        end
      end
      
      def self.empty_bitmap # not used, added for completness in case the cache is accessed directly
        @cache[:empty] = Bitmap.new(32, 32) unless include?(:empty)
        @cache[:empty]
      end 
      
      def self.new_letter(fontary, char)
        font = create_font(fontary)
        # get the font
        canvas.font = font
        rect = canvas.text_size(char * 3) 
        # get size of character between two other characters (for better kerning)
        b = Bitmap.new((rect.width / 3) + Bitmap::TEXT_SIDE_BUFFER * 2, rect.height)
        # create bitmap just big enough for one character
        b.font = font
        # get the font
        b.draw_text_vxa(rect.x - b.text_size(" ").width + Bitmap::TEXT_SIDE_BUFFER, rect.y - Bitmap::TEXT_TOP_BUFFER, BUFFER_DRAW, rect.height + Bitmap::TEXT_TOP_BUFFER * 2, " #{char} ", 0)
        # draw blank spaces before and after character, fix for cutting off the 
        # first pixel using draw_text
        key = fontary + [char]
        @cache[key] = b    
      end
      
      def self.create_font(fontary)
        font = Font.new(*fontary[0..1])
        font.bold = fontary[2]
        font.italic = fontary[3]
        font.outline = fontary[4]
        font.shadow = fontary[5]
        font.color.set(*fontary[6..9])
        font.out_color.set(*fontary[10..13])
        font
      end
    
      
      def self.include?(key)
        @cache[key] && !@cache[key].disposed?
      end
    
      def self.clear
        @cache ||= {}
        @cache.clear
        GC.start
      end
      
    end
    
    class Window_Base
      alias :process_normal_character_vxa :process_normal_character
      def process_normal_character(c, pos)
        return unless c >= ' '
        process_normal_character_vxa(c, pos)
      end
    end
    
    class Font
      # font's instance variables are not reflective, so this has to be defined explicitly
      def to_a
        [name, size, bold, italic, outline, shadow, color.red, color.green, color.blue, color.alpha, out_color.red, out_color.green, out_color.blue, out_color.alpha]
      end
      
    end
    Скриншоты:


    До.


    После.

    Дополнительная информация:

    Это 2 отдельных скрипта, но объединил в один.
    Последний раз редактировалось Arnon; 04.06.2013 в 14:20.

  2. #2
    Хранитель Аватар для Темный
    Информация о пользователе
    Регистрация
    13.05.2011
    Сообщений
    2,449
    Записей в дневнике
    20
    Репутация: 50 Добавить или отнять репутацию

    По умолчанию

    Нужный скрипт, а то приходилось в ручную бороться с этими квадратами)



Информация о теме

Пользователи, просматривающие эту тему

Эту тему просматривают: 1 (пользователей: 0 , гостей: 1)

Социальные закладки

Социальные закладки

Ваши права

  • Вы не можете создавать новые темы
  • Вы не можете отвечать в темах
  • Вы не можете прикреплять вложения
  • Вы не можете редактировать свои сообщения
  •  
Text Cache &amp; Custom Font Junk Symbol Fix