Example #1
0
  function dropShadow(paintFn) {
    var success;

    var saveBlendMode = vg.getI(vg.VGParamType.VG_BLEND_MODE);

    vg.getMatrix(shadowTransform);

    success = vg.egl.makeCurrent(shadowSurface, shadowContext);

    vg.loadMatrix(shadowTransform);

    vg.clear(0, 0, width, height);

    vg.translate(shadowOffsetX, shadowOffsetY);
    paintFn();
    vg.translate(-shadowOffsetX, -shadowOffsetY);

    vg.setI(vg.VGParamType.VG_BLEND_MODE, vg.VGBlendMode.VG_BLEND_SRC_IN);
    vg.setParameterI(shadowPaint, vg.VGPaintParamType.VG_PAINT_TYPE,
                                  vg.VGPaintType.VG_PAINT_TYPE_COLOR);
    vg.setParameterFV(shadowPaint, vg.VGPaintParamType.VG_PAINT_COLOR,
                                   shadowColor);
    vg.setPaint(shadowPaint, vg.VGPaintMode.VG_FILL_PATH);

    vg.getMatrix(shadowTransform);
    vg.loadIdentity();


    var vgPath = vg.createPath(vg.VG_PATH_FORMAT_STANDARD,
                               vg.VGPathDatatype.VG_PATH_DATATYPE_F,
                               1.0 /* scale */ , 0.0 /* bias */,
                               5 /* segCapacityHint */,
                               5 /* coordCapacityHint */,
                               vg.VGPathCapabilities.VG_PATH_CAPABILITY_APPEND_TO);

    vg.vgu.rect(vgPath, 0, 0, width, height);
    vg.drawPath(vgPath, vg.VGPaintMode.VG_FILL_PATH);
    vg.destroyPath(vgPath);

    vg.loadMatrix(shadowTransform);

    vg.setI(vg.VGParamType.VG_BLEND_MODE, vg.VGBlendMode.VG_BLEND_SRC_OVER);

    if (shadowBlur !== 0) {
      var sigma = shadowBlur / 2;
      vg.gaussianBlur(shadowDstImage, shadowSrcImage,
                      sigma, sigma,
                      vg.VGTilingMode.VG_TILE_PAD);
    }

    success = vg.egl.makeCurrent(vg.screen.surface, vg.screen.context);

    vg.setI(vg.VGParamType.VG_BLEND_MODE, vg.VGBlendMode.VG_BLEND_SRC_OVER);

    vg.getMatrix(shadowTransform);
    vg.loadIdentity();
    vg.drawImage(shadowBlur !== 0 ? shadowDstImage : shadowSrcImage);
    vg.loadMatrix(shadowTransform);

    vg.setI(vg.VGParamType.VG_BLEND_MODE, saveBlendMode);
  }
Example #2
0
                                        function (textPath, idx, character) {

    var glyph = typeface.characterMap[character];

    //     1. Let dx be the x-coordinate of the horizontal center of the
    //        bounding box of the shape described by glyph, in CSS pixels.
    var bbox = typeface.glyphBBoxes[glyph];
    var hCenter = (bbox.minX + (bbox.maxX - bbox.minX) / 2) * size / 65536.0;
    var dx = renderInfo.glyphPositions[idx].x + hCenter;

    //     2. If dx is negative or greater than width, skip the remainder or
    //        these substeps for this glyph.
    if (dx < 0 || dx > width) return false;

    //     3. Recast dx to coordinate spaces units in path. (This just changes
    //        the dimensionality of dx, not its numeric value.)
    // WAT !?

    //     4. Find the point p on path (or implied closing lines in path) that
    //        corresponds to the position dx on the coordinate line L.
    vg.pointAlongPath(path.vgPath, 0, pathNumSegments, dx, pointInfo);

    //     5. Let θ be the clockwise angle from the positive x-axis to the side
    //        of the line that is tangential to path at the point p that is
    //        going in the same direction as the line at point p.
    var theta = Math.atan2(pointInfo.ty, pointInfo.tx);

    //     6. Rotate the shape described by glyph clockwise by θ about the
    //        point that is at the dx coordinate horizontally and the zero
    //        coordinate vertically.
    //     7. Let (x, y) be the coordinate of the point p.
    //     8. Move the shape described by glyph to the right by x and down by
    //        y.
    // This operations must be run in reverse order.

    vg.translate(pointInfo.x, pointInfo.y);
    vg.rotate(theta * 180 / Math.PI);
    vg.translate(-hCenter, renderInfo.anchor.y);
    vg.scale(size * renderInfo.scaleX, -size);

    //     9. Let glyph subpaths be a list of subpaths describing the shape
    //        given in glyph, with each CSS pixel in the coordinate space of
    //        glyph mapped to one coordinate space unit in glyph subpaths.
    //        Subpaths in glyph subpaths must wind clockwise, regardless of
    //        how the user agent's font subsystem renders fonts and
    //        regardless of how the fonts themselves are defined.
    // Nothing to do here (maybe?)

    //    10. If the method is addPathByStrokingText(), replace glyph
    //        subpaths by the result of tracing glyph subpaths, using the
    //        CanvasDrawingStyles object argument for the line styles.
    // Nothing to do here (no support for addPathByStrokingText for now)

    //    11. Transform all the coordinates and lines in glyph subpaths by
    //        the transformation matrix transform, if it is not null.
    // See 9. below

    //    12. Let (xfinal, yfinal) be the last point in the last subpath of
    //        glyph subpaths. (This coordinate is only used if this is the
    //        last glyph processed.)
    // TODO Complement loading so that this point is stored

    //    13. Add all the subpaths in glyph subpaths to target.
    vg.transformPath(textPath, typeface.glyphs[glyph]);
  });
Example #3
0
 result.translate = function (x, y) {
   vg.translate(x, y);
 };