Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. /**************************************************************************
  2.  *
  3.  * Copyright 2009 VMware, Inc.  All Rights Reserved.
  4.  *
  5.  * Permission is hereby granted, free of charge, to any person obtaining a
  6.  * copy of this software and associated documentation files (the
  7.  * "Software"), to deal in the Software without restriction, including
  8.  * without limitation the rights to use, copy, modify, merge, publish,
  9.  * distribute, sub license, and/or sell copies of the Software, and to
  10.  * permit persons to whom the Software is furnished to do so, subject to
  11.  * the following conditions:
  12.  *
  13.  * The above copyright notice and this permission notice (including the
  14.  * next paragraph) shall be included in all copies or substantial portions
  15.  * of the Software.
  16.  *
  17.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  18.  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19.  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
  20.  * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
  21.  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  22.  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  23.  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24.  *
  25.  **************************************************************************/
  26.  
  27. #include "VG/openvg.h"
  28.  
  29. #include "vg_context.h"
  30. #include "text.h"
  31. #include "api.h"
  32. #include "handle.h"
  33.  
  34. #include "util/u_memory.h"
  35.  
  36. #ifdef OPENVG_VERSION_1_1
  37.  
  38. VGFont vegaCreateFont(VGint glyphCapacityHint)
  39. {
  40.    struct vg_context *ctx = vg_current_context();
  41.  
  42.    if (glyphCapacityHint < 0) {
  43.       vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
  44.       return VG_INVALID_HANDLE;
  45.    }
  46.  
  47.    return font_to_handle(font_create(glyphCapacityHint));
  48. }
  49.  
  50. void vegaDestroyFont(VGFont f)
  51. {
  52.    struct vg_font *font = handle_to_font(f);
  53.    struct vg_context *ctx = vg_current_context();
  54.  
  55.    if (f == VG_INVALID_HANDLE) {
  56.       vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
  57.       return;
  58.    }
  59.    if (!vg_object_is_valid(f, VG_OBJECT_FONT)) {
  60.       vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
  61.       return;
  62.    }
  63.  
  64.    font_destroy(font);
  65. }
  66.  
  67. void vegaSetGlyphToPath(VGFont font,
  68.                         VGuint glyphIndex,
  69.                         VGPath path,
  70.                         VGboolean isHinted,
  71.                         const VGfloat glyphOrigin[2],
  72.                         const VGfloat escapement[2])
  73. {
  74.    struct vg_context *ctx = vg_current_context();
  75.    struct path *pathObj;
  76.    struct vg_font *f;
  77.  
  78.    if (font == VG_INVALID_HANDLE ||
  79.        !vg_context_is_object_valid(ctx, VG_OBJECT_FONT, font)) {
  80.       vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
  81.       return;
  82.    }
  83.    if (!glyphOrigin || !escapement ||
  84.        !is_aligned(glyphOrigin) || !is_aligned(escapement)) {
  85.       vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
  86.       return;
  87.    }
  88.    if (path != VG_INVALID_HANDLE &&
  89.        !vg_context_is_object_valid(ctx, VG_OBJECT_PATH, path)) {
  90.       vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
  91.       return;
  92.    }
  93.  
  94.    pathObj = handle_to_path(path);
  95.    f = handle_to_font(font);
  96.  
  97.    font_set_glyph_to_path(f, glyphIndex, pathObj,
  98.          isHinted, glyphOrigin, escapement);
  99. }
  100.  
  101. void vegaSetGlyphToImage(VGFont font,
  102.                          VGuint glyphIndex,
  103.                          VGImage image,
  104.                          const VGfloat glyphOrigin[2],
  105.                          const VGfloat escapement[2])
  106. {
  107.    struct vg_context *ctx = vg_current_context();
  108.    struct vg_image *img_obj;
  109.    struct vg_font *f;
  110.  
  111.    if (font == VG_INVALID_HANDLE ||
  112.        !vg_context_is_object_valid(ctx, VG_OBJECT_FONT, font)) {
  113.       vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
  114.       return;
  115.    }
  116.    if (!glyphOrigin || !escapement ||
  117.        !is_aligned(glyphOrigin) || !is_aligned(escapement)) {
  118.       vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
  119.       return;
  120.    }
  121.    if (image != VG_INVALID_HANDLE &&
  122.        !vg_context_is_object_valid(ctx, VG_OBJECT_IMAGE, image)) {
  123.       vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
  124.       return;
  125.    }
  126.  
  127.    img_obj = handle_to_image(image);
  128.    f = handle_to_font(font);
  129.  
  130.    font_set_glyph_to_image(f, glyphIndex, img_obj, glyphOrigin, escapement);
  131. }
  132.  
  133. void vegaClearGlyph(VGFont font,
  134.                     VGuint glyphIndex)
  135. {
  136.    struct vg_context *ctx = vg_current_context();
  137.    struct vg_font *f;
  138.  
  139.    if (font == VG_INVALID_HANDLE) {
  140.       vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
  141.       return;
  142.    }
  143.  
  144.    f = handle_to_font(font);
  145.  
  146.    font_clear_glyph(f, glyphIndex);
  147. }
  148.  
  149. void vegaDrawGlyph(VGFont font,
  150.                    VGuint glyphIndex,
  151.                    VGbitfield paintModes,
  152.                    VGboolean allowAutoHinting)
  153. {
  154.    struct vg_context *ctx = vg_current_context();
  155.    struct vg_font *f;
  156.  
  157.    if (font == VG_INVALID_HANDLE) {
  158.       vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
  159.       return;
  160.    }
  161.    if (paintModes & (~(VG_STROKE_PATH|VG_FILL_PATH))) {
  162.       vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
  163.       return;
  164.    }
  165.    f = handle_to_font(font);
  166.  
  167.    font_draw_glyph(f, glyphIndex, paintModes, allowAutoHinting);
  168. }
  169.  
  170. void vegaDrawGlyphs(VGFont font,
  171.                     VGint glyphCount,
  172.                     const VGuint *glyphIndices,
  173.                     const VGfloat *adjustments_x,
  174.                     const VGfloat *adjustments_y,
  175.                     VGbitfield paintModes,
  176.                     VGboolean allowAutoHinting)
  177. {
  178.    struct vg_context *ctx = vg_current_context();
  179.    struct vg_font *f;
  180.  
  181.    if (font == VG_INVALID_HANDLE) {
  182.       vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
  183.       return;
  184.    }
  185.    if (glyphCount <= 0) {
  186.       vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
  187.       return;
  188.    }
  189.    if (!glyphIndices || !is_aligned(glyphIndices)) {
  190.       vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
  191.       return;
  192.    }
  193.    if ((adjustments_x && !is_aligned(adjustments_x)) ||
  194.        (adjustments_y && !is_aligned(adjustments_y))) {
  195.       vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
  196.       return;
  197.    }
  198.    if (paintModes & (~(VG_STROKE_PATH|VG_FILL_PATH))) {
  199.       vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
  200.       return;
  201.    }
  202.  
  203.    f = handle_to_font(font);
  204.  
  205.    font_draw_glyphs(f, glyphCount, glyphIndices,
  206.          adjustments_x, adjustments_y, paintModes, allowAutoHinting);
  207. }
  208.  
  209. #endif /* OPENVG_VERSION_1_1 */
  210.