Modify it to adjust Tizen IVI enviroment
[platform/upstream/kmscon.git] / src / font.h
index 0fa9142..f7e4b01 100644 (file)
@@ -1,8 +1,7 @@
 /*
- * kmscon - Font Management
+ * kmscon - Font Renderer
  *
- * Copyright (c) 2011-2012 David Herrmann <dh.herrmann@googlemail.com>
- * Copyright (c) 2011 University of Tuebingen
+ * Copyright (c) 2012-2013 David Herrmann <dh.herrmann@googlemail.com>
  *
  * Permission is hereby granted, free of charge, to any person obtaining
  * a copy of this software and associated documentation files
  */
 
 /*
- * Font Management
- * The output of a console is a fixed-size table. That is, it consists of many
- * cells where each character is printed either into a single cell or spread
- * across multiple cells. However, there will never be multiple characters in a
- * single cell so cell indexes are the smallest position information.
- * The classic console uses one character per cell. Newer consoles may allow
- * widened characters, though. Common are characters that are double-width and
- * characters that are double-width+double-height.
- * If you mix many different widths/heights then this might get very
- * memory-consuming as we need to have one loaded font for each size to get
- * decent results. Therefore, avoid widths/heights other than the ones
- * mentioned.
- *
- * Therefore, this layer does not provide the classic font APIs, instead it
- * offers a font_screen object which represents the whole screen. You specify
- * the x/y coordinates of your framebuffer/target and the font plus point-size
- * that you want to use. This layer automatically computes the pixel size and
- * resulting row/column counts.
- * For reversed logic you can also specify row/column counts and the API
- * calculates the required font-point-size.
- * In both situations you never have to deal with font related details! The only
- * thing you need to know is the row/column count of the resulting table and
- * all the characters in the table.
- *
- * When drawing a screen you need to tell the font layer where to draw the
- * characters. For performance reasons this is split into several tasks:
- *   1: Start a drawing operation. This resets the screen and prepares the font
- *      for drawing. It clears all previous entries.
- *   2: Add each character you want to draw to the font_screen object with its
- *      cell position and cell width. The width is probably always 1/1 but for
- *      multi-cell characters you can specify other widths/heights.
- *   3: Perform the drawing operation. This instructs the font-layer to actually
- *      draw all the added characters to your surface.
- * You need to perform all 3 steps for every frame you render.
+ * Font Renderer
  */
 
-#ifndef FONT_FONT_H
-#define FONT_FONT_H
+#ifndef KMSCON_FONT_H
+#define KMSCON_FONT_H
 
+#include <errno.h>
 #include <stdlib.h>
-#include "gl.h"
-#include "unicode.h"
-#include "uterm.h"
-
-struct kmscon_font_factory;
-struct kmscon_font;
+#include "kmscon_module.h"
+#include "uterm_video.h"
 
-int kmscon_font_factory_new(struct kmscon_font_factory **out);
-void kmscon_font_factory_ref(struct kmscon_font_factory *ff);
-void kmscon_font_factory_unref(struct kmscon_font_factory *ff);
+/* fonts */
 
-int kmscon_font_factory_load(struct kmscon_font_factory *ff,
-       struct kmscon_font **out, unsigned int width, unsigned int height);
+struct kmscon_font_attr;
+struct kmscon_glyph;
+struct kmscon_font;
+struct kmscon_font_ops;
 
-void kmscon_font_ref(struct kmscon_font *font);
-void kmscon_font_unref(struct kmscon_font *font);
+#define KMSCON_FONT_MAX_NAME 128
+#define KMSCON_FONT_DEFAULT_NAME "monospace"
+#define KMSCON_FONT_DEFAULT_PPI 72
 
-unsigned int kmscon_font_get_height(struct kmscon_font *font);
-unsigned int kmscon_font_get_width(struct kmscon_font *font);
-int kmscon_font_draw(struct kmscon_font *font, kmscon_symbol_t ch, float *m,
-                       struct gl_shader *shader);
+struct kmscon_font_attr {
+       char name[KMSCON_FONT_MAX_NAME];
+       unsigned int ppi;
+       unsigned int points;
+       bool bold;
+       bool italic;
+       unsigned int height;
+       unsigned int width;
+};
 
-/* font attributes */
+void kmscon_font_attr_normalize(struct kmscon_font_attr *attr);
+bool kmscon_font_attr_match(const struct kmscon_font_attr *a1,
+                           const struct kmscon_font_attr *a2);
 
-enum font_style {
-       FONT_NORMAL,
-       FONT_ITALIC,
+struct kmscon_glyph {
+       struct uterm_video_buffer buf;
+       unsigned int width;
+       void *data;
 };
 
-struct font_attr {
-       const char *name;       /* use NULL for default */
-       unsigned int points;
-       unsigned int dpi;       /* use 0 for default */
-       bool bold;
-       enum font_style style;
+struct kmscon_font {
+       unsigned long ref;
+       struct shl_register_record *record;
+       const struct kmscon_font_ops *ops;
+       struct kmscon_font_attr attr;
+       unsigned int baseline;
+       void *data;
 };
 
-#define FONT_ATTR(_name, _points, _dpi) &(const struct font_attr){ \
-               .name = (_name), \
-               .points = (_points), \
-               .dpi = (_dpi), \
-               .bold = false, \
-               .style = FONT_NORMAL, \
-       }
-
-struct font_char_attr {
-       uint8_t fr;                     /* foreground red */
-       uint8_t fg;                     /* foreground green */
-       uint8_t fb;                     /* foreground blue */
-       uint8_t br;                     /* background red */
-       uint8_t bg;                     /* background green */
-       uint8_t bb;                     /* background blue */
-       unsigned int bold : 1;          /* bold character */
-       unsigned int underline : 1;     /* underlined character */
-       unsigned int inverse : 1;       /* inverse colors */
-       unsigned int protect : 1;       /* cannot be erased */
+struct kmscon_font_ops {
+       const char *name;
+       struct kmscon_module *owner;
+       int (*init) (struct kmscon_font *out,
+                    const struct kmscon_font_attr *attr);
+       void (*destroy) (struct kmscon_font *font);
+       int (*render) (struct kmscon_font *font,
+                      uint32_t id, const uint32_t *ch, size_t len,
+                      const struct kmscon_glyph **out);
+       int (*render_empty) (struct kmscon_font *font,
+                            const struct kmscon_glyph **out);
+       int (*render_inval) (struct kmscon_font *font,
+                            const struct kmscon_glyph **out);
 };
 
-/* font draw/assemble buffers */
+int kmscon_font_register(const struct kmscon_font_ops *ops);
+void kmscon_font_unregister(const char *name);
 
-struct font_buffer {
-       unsigned int width;
-       unsigned int stride;
-       unsigned int height;
-       char *data;
-};
+int kmscon_font_find(struct kmscon_font **out,
+                    const struct kmscon_font_attr *attr,
+                    const char *backend);
+void kmscon_font_ref(struct kmscon_font *font);
+void kmscon_font_unref(struct kmscon_font *font);
+
+int kmscon_font_render(struct kmscon_font *font,
+                      uint32_t id, const uint32_t *ch, size_t len,
+                      const struct kmscon_glyph **out);
+int kmscon_font_render_empty(struct kmscon_font *font,
+                            const struct kmscon_glyph **out);
+int kmscon_font_render_inval(struct kmscon_font *font,
+                            const struct kmscon_glyph **out);
+
+/* modularized backends */
+
+extern struct kmscon_font_ops kmscon_font_8x16_ops;
+extern struct kmscon_font_ops kmscon_font_unifont_ops;
+extern struct kmscon_font_ops kmscon_font_pango_ops;
 
-int font_buffer_new(struct font_buffer **out, unsigned int width,
-                       unsigned int height);
-void font_buffer_free(struct font_buffer *buf);
-
-/* font screens */
-
-struct font_screen;
-
-int font_screen_new(struct font_screen **out, struct font_buffer *buf,
-                       const struct font_attr *attr,
-                       struct uterm_screen *scr, struct gl_shader *shader);
-int font_screen_new_fixed(struct font_screen **out, struct font_buffer *buf,
-                       const struct font_attr *attr,
-                       unsigned int cols, unsigned int rows,
-                       struct uterm_screen *scr, struct gl_shader *shader);
-void font_screen_free(struct font_screen *screen);
-
-unsigned int font_screen_columns(struct font_screen *screen);
-unsigned int font_screen_rows(struct font_screen *screen);
-unsigned int font_screen_points(struct font_screen *screen);
-unsigned int font_screen_width(struct font_screen *screen);
-unsigned int font_screen_height(struct font_screen *screen);
-
-int font_screen_draw_start(struct font_screen *screen);
-int font_screen_draw_char(struct font_screen *screen, kmscon_symbol_t ch,
-                               const struct font_char_attr *attr,
-                               unsigned int cellx, unsigned int celly,
-                               unsigned int width, unsigned int height);
-int font_screen_draw_perform(struct font_screen *screen, float *m);
-
-#endif /* FONT_FONT_H */
+#endif /* KMSCON_FONT_H */