cairo_surface_t * _cairo_type3_glyph_surface_create (cairo_scaled_font_t *scaled_font, cairo_output_stream_t *stream, cairo_type3_glyph_surface_emit_image_t emit_image, cairo_scaled_font_subsets_t *font_subsets) { cairo_type3_glyph_surface_t *surface; cairo_matrix_t invert_y_axis; surface = malloc (sizeof (cairo_type3_glyph_surface_t)); if (surface == NULL) return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); _cairo_surface_init (&surface->base, &cairo_type3_glyph_surface_backend, CAIRO_CONTENT_COLOR_ALPHA); surface->scaled_font = scaled_font; surface->stream = stream; surface->emit_image = emit_image; /* Setup the transform from the user-font device space to Type 3 * font space. The Type 3 font space is defined by the FontMatrix * entry in the Type 3 dictionary. In the PDF backend this is an * identity matrix. */ surface->cairo_to_pdf = scaled_font->scale_inverse; cairo_matrix_init_scale (&invert_y_axis, 1, -1); cairo_matrix_multiply (&surface->cairo_to_pdf, &surface->cairo_to_pdf, &invert_y_axis); _cairo_pdf_operators_init (&surface->pdf_operators, surface->stream, &surface->cairo_to_pdf, font_subsets); return &surface->base; }
cairo_surface_t* Win32UIBinding::ScaleCairoSurface( cairo_surface_t* oldSurface, int newWidth, int newHeight) { cairo_matrix_t scaleMatrix; cairo_matrix_init_scale(&scaleMatrix, (double) cairo_image_surface_get_width(oldSurface) / (double) newWidth, (double) cairo_image_surface_get_height(oldSurface) / (double) newHeight); cairo_pattern_t* surfacePattern = cairo_pattern_create_for_surface(oldSurface); cairo_pattern_set_matrix(surfacePattern, &scaleMatrix); cairo_pattern_set_filter(surfacePattern, CAIRO_FILTER_BEST); cairo_surface_t* newSurface = cairo_surface_create_similar( oldSurface, CAIRO_CONTENT_COLOR_ALPHA, newWidth, newHeight); cairo_t* cr = cairo_create(newSurface); cairo_set_source(cr, surfacePattern); /* To avoid getting the edge pixels blended with 0 alpha, which would * occur with the default EXTEND_NONE. Use EXTEND_PAD for 1.2 or newer (2) */ cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REFLECT); /* Replace the destination with the source instead of overlaying */ cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); /* Do the actual drawing */ cairo_paint(cr); cairo_destroy(cr); return newSurface; }
static void redraw_command(I7Node *self, double width, double height) { I7_NODE_USE_PRIVATE; cairo_matrix_t matrix; char *path; /* Calculate the scale for the pattern gradients */ cairo_matrix_init_scale(&matrix, 0.5 / width, 1.0 / height); cairo_pattern_set_matrix(priv->node_pattern[NODE_UNPLAYED_UNBLESSED], &matrix); cairo_pattern_set_matrix(priv->node_pattern[NODE_UNPLAYED_BLESSED], &matrix); cairo_pattern_set_matrix(priv->node_pattern[NODE_PLAYED_UNBLESSED], &matrix); cairo_pattern_set_matrix(priv->node_pattern[NODE_PLAYED_BLESSED], &matrix); /* Draw the text background */ path = g_strdup_printf( "M %.1f -%.1f " /* Move-to (w/2, -h/2) */ "a %.1f,%.1f 0 0,1 0,%.1f " /* Arc r=(h/2, h/2) rot=0 large=0 dir=1 rel-to (0, h) */ "h -%.1f " /* Horizontal-line-rel-to (-w) */ "a %.1f,%.1f 0 0,1 0,-%.1f " /* Arc r=(h/2, h/2) rot=0 large=0 dir=1 rel-to (0, -h) */ "Z", /* Close-path */ width / 2, height / 2, height / 2, height / 2, height, width, height / 2, height / 2, height); g_object_set(priv->command_shape_item, "data", path, NULL); g_free(path); priv->command_width = width; priv->command_height = height; }
FontPlatformData::FontPlatformData(cairo_font_face_t* fontFace, float size, bool bold, bool oblique) : m_font(0) , m_size(size) , m_fontFace(fontFace) , m_scaledFont(0) , m_syntheticBold(bold) , m_syntheticOblique(oblique) , m_useGDI(false) { cairo_matrix_t fontMatrix; cairo_matrix_init_scale(&fontMatrix, size, size); cairo_matrix_t ctm; cairo_matrix_init_identity(&ctm); cairo_font_options_t* options = cairo_font_options_create(); // We force antialiasing and disable hinting to provide consistent // typographic qualities for custom fonts on all platforms. #if PLATFORM(APOLLO) // In Apollo use the anti-aliasing mode selected by the user. See bug 2404418. cairo_font_options_set_antialias(options, CAIRO_ANTIALIAS_DEFAULT); #else cairo_font_options_set_hint_style(options, CAIRO_HINT_STYLE_NONE); cairo_font_options_set_antialias(options, CAIRO_ANTIALIAS_GRAY); #endif m_scaledFont = cairo_scaled_font_create(fontFace, &fontMatrix, &ctm, options); cairo_font_options_destroy(options); }
FontPlatformData::FontPlatformData(cairo_font_face_t* fontFace, float size, bool bold, bool oblique) : m_font(0) , m_size(size) , m_orientation(Horizontal) , m_textOrientation(TextOrientationVerticalRight) , m_widthVariant(RegularWidth) , m_scaledFont(0) , m_isColorBitmapFont(false) , m_syntheticBold(bold) , m_syntheticOblique(oblique) , m_useGDI(false) { cairo_matrix_t fontMatrix; cairo_matrix_init_scale(&fontMatrix, size, size); cairo_matrix_t ctm; cairo_matrix_init_identity(&ctm); cairo_font_options_t* options = cairo_font_options_create(); // We force antialiasing and disable hinting to provide consistent // typographic qualities for custom fonts on all platforms. cairo_font_options_set_hint_style(options, CAIRO_HINT_STYLE_NONE); cairo_font_options_set_antialias(options, CAIRO_ANTIALIAS_GRAY); m_scaledFont = cairo_scaled_font_create(fontFace, &fontMatrix, &ctm, options); cairo_font_options_destroy(options); }
static void redraw_label(I7Node *self, double width, double height) { I7_NODE_USE_PRIVATE; cairo_matrix_t matrix; char *path; /* Calculate the scale for the pattern gradient */ cairo_matrix_init_scale(&matrix, 0.5 / width, -1.0 / height); cairo_pattern_set_matrix(priv->label_pattern, &matrix); path = g_strdup_printf( "M %.1f,%.1f " /* Move-to (w/2+h, h/2) */ "a %.1f,%.1f 0 0,0 -%.1f,-%.1f " /* Arc r=(h, h) rot=0 large=0 dir=0 rel-to (-h, -h) */ "h -%.1f " /* Horizontal-line-rel-to (-w) */ "a %.1f,%.1f 0 0,0 -%.1f,%.1f " /* Arc r=(h, h) rot=0 large=0 dir=0 rel-to (-h, h) */ "Z", width / 2 + height, height / 2, height, height, height, height, width, height, height, height, height); g_object_set(priv->label_shape_item, "data", path, "visibility", GOO_CANVAS_ITEM_VISIBLE, NULL); g_free(path); priv->label_width = width; priv->label_height = height; }
FontPlatformData::FontPlatformData(GDIObject<HFONT> font, cairo_font_face_t* fontFace, float size, bool bold, bool oblique) : m_font(SharedGDIObject<HFONT>::create(WTFMove(font))) , m_size(size) , m_syntheticOblique(oblique) { cairo_matrix_t fontMatrix; cairo_matrix_init_scale(&fontMatrix, size, size); cairo_matrix_t ctm; cairo_matrix_init_identity(&ctm); cairo_font_options_t* options = cairo_font_options_create(); // We force antialiasing and disable hinting to provide consistent // typographic qualities for custom fonts on all platforms. cairo_font_options_set_hint_style(options, CAIRO_HINT_STYLE_NONE); cairo_font_options_set_antialias(options, CAIRO_ANTIALIAS_BEST); if (syntheticOblique()) { static const float syntheticObliqueSkew = -tanf(14 * acosf(0) / 90); cairo_matrix_t skew = {1, 0, syntheticObliqueSkew, 1, 0, 0}; cairo_matrix_multiply(&fontMatrix, &skew, &fontMatrix); } m_scaledFont = adoptRef(cairo_scaled_font_create(fontFace, &fontMatrix, &ctm, options)); cairo_font_options_destroy(options); }
void FontPlatformData::initializeWithFontFace(cairo_font_face_t* fontFace) { cairo_font_options_t* options = getDefaultFontOptions(); cairo_matrix_t ctm; cairo_matrix_init_identity(&ctm); // Scaling a font with width zero size leads to a failed cairo_scaled_font_t instantiations. // Instead we scale we scale the font to a very tiny size and just abort rendering later on. float realSize = m_size ? m_size : 1; cairo_matrix_t fontMatrix; if (!m_pattern) cairo_matrix_init_scale(&fontMatrix, realSize, realSize); else { setCairoFontOptionsFromFontConfigPattern(options, m_pattern.get()); // FontConfig may return a list of transformation matrices with the pattern, for instance, // for fonts that are oblique. We use that to initialize the cairo font matrix. FcMatrix fontConfigMatrix, *tempFontConfigMatrix; FcMatrixInit(&fontConfigMatrix); // These matrices may be stacked in the pattern, so it's our job to get them all and multiply them. for (int i = 0; FcPatternGetMatrix(m_pattern.get(), FC_MATRIX, i, &tempFontConfigMatrix) == FcResultMatch; i++) FcMatrixMultiply(&fontConfigMatrix, &fontConfigMatrix, tempFontConfigMatrix); cairo_matrix_init(&fontMatrix, fontConfigMatrix.xx, -fontConfigMatrix.yx, -fontConfigMatrix.xy, fontConfigMatrix.yy, 0, 0); // The matrix from FontConfig does not include the scale. cairo_matrix_scale(&fontMatrix, realSize, realSize); } m_scaledFont = cairo_scaled_font_create(fontFace, &fontMatrix, &ctm, options); cairo_font_options_destroy(options); }
explicit font_fc(cairo_t* cairo, FcPattern* pattern, double offset, double dpi_x, double dpi_y) : font(cairo, offset), m_pattern(pattern) { cairo_matrix_t fm; cairo_matrix_t ctm; cairo_matrix_init_scale(&fm, size(dpi_x), size(dpi_y)); cairo_get_matrix(m_cairo, &ctm); auto fontface = cairo_ft_font_face_create_for_pattern(m_pattern); auto opts = cairo_font_options_create(); m_scaled = cairo_scaled_font_create(fontface, &fm, &ctm, opts); cairo_font_options_destroy(opts); cairo_font_face_destroy(fontface); auto status = cairo_scaled_font_status(m_scaled); if (status != CAIRO_STATUS_SUCCESS) { throw application_error(sstream() << "cairo_scaled_font_create(): " << cairo_status_to_string(status)); } auto lock = make_unique<utils::ft_face_lock>(m_scaled); auto face = static_cast<FT_Face>(*lock); if (FT_Select_Charmap(face, FT_ENCODING_UNICODE) == FT_Err_Ok) { return; } else if (FT_Select_Charmap(face, FT_ENCODING_BIG5) == FT_Err_Ok) { return; } else if (FT_Select_Charmap(face, FT_ENCODING_SJIS) == FT_Err_Ok) { return; } lock.reset(); }
void FontPlatformData::initializeWithFontFace(cairo_font_face_t* fontFace) { cairo_font_options_t* options = cairo_font_options_copy(getDefaultFontOptions()); cairo_matrix_t ctm; cairo_matrix_init_identity(&ctm); cairo_matrix_t fontMatrix; if (!m_pattern) cairo_matrix_init_scale(&fontMatrix, m_size, m_size); else { setCairoFontOptionsFromFontConfigPattern(options, m_pattern.get()); // FontConfig may return a list of transformation matrices with the pattern, for instance, // for fonts that are oblique. We use that to initialize the cairo font matrix. FcMatrix fontConfigMatrix, *tempFontConfigMatrix; FcMatrixInit(&fontConfigMatrix); // These matrices may be stacked in the pattern, so it's our job to get them all and multiply them. for (int i = 0; FcPatternGetMatrix(m_pattern.get(), FC_MATRIX, i, &tempFontConfigMatrix) == FcResultMatch; i++) FcMatrixMultiply(&fontConfigMatrix, &fontConfigMatrix, tempFontConfigMatrix); cairo_matrix_init(&fontMatrix, fontConfigMatrix.xx, -fontConfigMatrix.yx, -fontConfigMatrix.xy, fontConfigMatrix.yy, 0, 0); // The matrix from FontConfig does not include the scale. cairo_matrix_scale(&fontMatrix, m_size, m_size); } m_scaledFont = adoptPlatformRef(cairo_scaled_font_create(fontFace, &fontMatrix, &ctm, options)); cairo_font_options_destroy(options); }
static void gnm_soi_draw_cairo (SheetObject const *so, cairo_t *cr, double width, double height) { GdkPixbuf *pixbuf; GOImage *img; cairo_pattern_t *cr_pattern; int w, h; cairo_matrix_t cr_matrix; pixbuf = soi_get_pixbuf (SHEET_OBJECT_IMAGE (so), 1.); if (!pixbuf || width == 0. || height == 0.) return; cairo_save (cr); img = go_image_new_from_pixbuf (pixbuf); cr_pattern = go_image_create_cairo_pattern (img); w = gdk_pixbuf_get_width (pixbuf); h = gdk_pixbuf_get_height (pixbuf); cairo_matrix_init_scale (&cr_matrix, w / width, h / height); cairo_pattern_set_matrix (cr_pattern, &cr_matrix); cairo_rectangle (cr, 0., 0., width, height); cairo_set_source (cr, cr_pattern); cairo_fill (cr); /* * We need to unset the source before we destroy the pattern. * cairo_restore will do that. See #632439. */ cairo_restore (cr); cairo_pattern_destroy (cr_pattern); g_object_unref (img); g_object_unref (pixbuf); }
void wxGISDisplay::DrawRaster(cairo_surface_t *surface, const OGREnvelope& Envelope, bool bDrawEnvelope) { wxCriticalSectionLocker locker(m_CritSect); cairo_pattern_t *pattern = cairo_pattern_create_for_surface (surface); cairo_matrix_t matrix; cairo_matrix_init_scale (&matrix, m_dScale, -m_dScale); cairo_matrix_translate(&matrix, -Envelope.MinX, -Envelope.MaxY); cairo_pattern_set_matrix (pattern, &matrix); cairo_set_source (m_saLayerCaches[m_nCurrentLayer].pCairoContext, pattern); cairo_paint (m_saLayerCaches[m_nCurrentLayer].pCairoContext); if(bDrawEnvelope) { //TODO: //SetLineWidth( m_dLineWidth ); //SetColor(m_FillColour); cairo_move_to(m_saLayerCaches[m_nCurrentLayer].pCairoContext, Envelope.MinX, Envelope.MinY); cairo_line_to(m_saLayerCaches[m_nCurrentLayer].pCairoContext, Envelope.MaxX, Envelope.MinY); cairo_line_to(m_saLayerCaches[m_nCurrentLayer].pCairoContext, Envelope.MaxX, Envelope.MaxY); cairo_line_to(m_saLayerCaches[m_nCurrentLayer].pCairoContext, Envelope.MinX, Envelope.MaxY); cairo_line_to(m_saLayerCaches[m_nCurrentLayer].pCairoContext, Envelope.MinX, Envelope.MinY); cairo_stroke (m_saLayerCaches[m_nCurrentLayer].pCairoContext); } cairo_pattern_destroy (pattern); }
bool GlyphLayerBitmap::render( cairo_t* c, cairo_glyph_t* glyph, unsigned int width, unsigned int height ) { if(cairo_status(c) || !glyph || !_bitmap || cairo_pattern_status(_pattern)) return false; double bw = _bitmap->getSurfaceWidth(); double bh = _bitmap->getSurfaceHeight(); if(_repeatX > 1 || _repeatY > 1) cairo_pattern_set_extend(_pattern, CAIRO_EXTEND_REPEAT); else cairo_pattern_set_extend(_pattern, CAIRO_EXTEND_PAD); cairo_matrix_t matrix; cairo_matrix_init_scale(&matrix, bw / width * _repeatX, bh / height * _repeatY); cairo_pattern_set_matrix(_pattern, &matrix); cairo_set_source(c, _pattern); cairo_glyph_path(c, glyph, 1); cairo_fill(c); return true; }
static cairo_surface_t * draw_from_gradient (cairo_pattern_t *pattern) { cairo_surface_t *surface; cairo_matrix_t matrix; cairo_t *cr; surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, DEFAULT_SURFACE_SIZE, DEFAULT_SURFACE_SIZE); cr = cairo_create (surface); /* scale the gradient points to the user space coordinates */ cairo_matrix_init_scale (&matrix, 1. / (double) DEFAULT_SURFACE_SIZE, 1. / (double) DEFAULT_SURFACE_SIZE); cairo_pattern_set_matrix (pattern, &matrix); cairo_arc (cr, DEFAULT_SURFACE_SIZE / 2., DEFAULT_SURFACE_SIZE / 2., DEFAULT_RADIUS, 0., 2 * G_PI); cairo_set_source (cr, pattern); cairo_fill (cr); cairo_destroy (cr); return surface; }
static gboolean pattern_value_parse (GtkCssParser *parser, GFile *base, GValue *value) { if (_gtk_css_parser_begins_with (parser, '-')) { g_value_unset (value); g_value_init (value, GTK_TYPE_GRADIENT); return gradient_value_parse (parser, base, value); } else { GError *error = NULL; gchar *path; GdkPixbuf *pixbuf; GFile *file; cairo_surface_t *surface; cairo_pattern_t *pattern; cairo_t *cr; cairo_matrix_t matrix; file = _gtk_css_parse_url (parser, base); if (file == NULL) return FALSE; path = g_file_get_path (file); g_object_unref (file); pixbuf = gdk_pixbuf_new_from_file (path, &error); g_free (path); if (pixbuf == NULL) { _gtk_css_parser_take_error (parser, error); return FALSE; } surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, gdk_pixbuf_get_width (pixbuf), gdk_pixbuf_get_height (pixbuf)); cr = cairo_create (surface); gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0); cairo_paint (cr); pattern = cairo_pattern_create_for_surface (surface); cairo_matrix_init_scale (&matrix, gdk_pixbuf_get_width (pixbuf), gdk_pixbuf_get_height (pixbuf)); cairo_pattern_set_matrix (pattern, &matrix); cairo_surface_destroy (surface); cairo_destroy (cr); g_object_unref (pixbuf); g_value_take_boxed (value, pattern); } return TRUE; }
static cairo_int_status_t _paint_page (cairo_paginated_surface_t *surface) { cairo_surface_t *analysis; cairo_surface_t *image; cairo_pattern_t *pattern; cairo_status_t status; analysis = _cairo_analysis_surface_create (surface->target, surface->width, surface->height); if (analysis == NULL) return CAIRO_STATUS_NO_MEMORY; surface->backend->set_paginated_mode (surface->target, CAIRO_PAGINATED_MODE_ANALYZE); status = _cairo_meta_surface_replay (surface->meta, analysis); surface->backend->set_paginated_mode (surface->target, CAIRO_PAGINATED_MODE_RENDER); if (status || analysis->status) { if (status == CAIRO_STATUS_SUCCESS) status = analysis->status; cairo_surface_destroy (analysis); return status; } if (_cairo_analysis_surface_has_unsupported (analysis)) { double x_scale = surface->base.x_fallback_resolution / 72.0; double y_scale = surface->base.y_fallback_resolution / 72.0; cairo_matrix_t matrix; image = _cairo_paginated_surface_create_image_surface (surface, surface->width * x_scale, surface->height * y_scale); _cairo_surface_set_device_scale (image, x_scale, y_scale); status = _cairo_meta_surface_replay (surface->meta, image); if (status) goto CLEANUP_IMAGE; pattern = cairo_pattern_create_for_surface (image); cairo_matrix_init_scale (&matrix, x_scale, y_scale); cairo_pattern_set_matrix (pattern, &matrix); status = _cairo_surface_paint (surface->target, CAIRO_OPERATOR_SOURCE, pattern); cairo_pattern_destroy (pattern); CLEANUP_IMAGE: cairo_surface_destroy (image); } else { status = _cairo_meta_surface_replay (surface->meta, surface->target); } cairo_surface_destroy (analysis); return status; }
static void _doc_page_get_matrix (CtkDocPage *self, gdouble scale, gint rotation, cairo_matrix_t *ctm) { cairo_matrix_init_scale (ctm, scale, scale); cairo_matrix_rotate (ctm, rotation * G_PI / 180.0); }
static int m_cairo_matrix_init_scale(lua_State * L) { cairo_matrix_t * matrix = luaL_checkudata(L, 1, MT_NAME_CAIRO_MATRIX); double sx = luaL_checknumber(L, 2); double sy = luaL_checknumber(L, 3); cairo_matrix_init_scale(matrix, sx, sy); return 0; }
static void redraw_handler(struct widget *widget, void *data) { struct image *image = data; struct rectangle allocation; cairo_t *cr; cairo_surface_t *surface; double width, height, doc_aspect, window_aspect, scale; cairo_matrix_t matrix; cairo_matrix_t translate; surface = window_get_surface(image->window); cr = cairo_create(surface); widget_get_allocation(image->widget, &allocation); cairo_rectangle(cr, allocation.x, allocation.y, allocation.width, allocation.height); cairo_clip(cr); cairo_push_group(cr); cairo_translate(cr, allocation.x, allocation.y); cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); cairo_set_source_rgba(cr, 0, 0, 0, 1); cairo_paint(cr); if (!image->initialized) { image->initialized = true; width = cairo_image_surface_get_width(image->image); height = cairo_image_surface_get_height(image->image); doc_aspect = width / height; window_aspect = (double) allocation.width / allocation.height; if (doc_aspect < window_aspect) scale = allocation.height / height; else scale = allocation.width / width; image->width = width; image->height = height; cairo_matrix_init_scale(&image->matrix, scale, scale); clamp_view(image); } matrix = image->matrix; cairo_matrix_init_translate(&translate, allocation.x, allocation.y); cairo_matrix_multiply(&matrix, &matrix, &translate); cairo_set_matrix(cr, &matrix); cairo_set_source_surface(cr, image->image, 0, 0); cairo_set_operator(cr, CAIRO_OPERATOR_OVER); cairo_paint(cr); cairo_pop_group_to_source(cr); cairo_paint(cr); cairo_destroy(cr); cairo_surface_destroy(surface); }
/** * cairo_matrix_scale: * @matrix: a #cairo_matrix_t * @sx: scale factor in the X direction * @sy: scale factor in the Y direction * * Applies scaling by @sx, @sy to the transformation in @matrix. The * effect of the new transformation is to first scale the coordinates * by @sx and @sy, then apply the original transformation to the coordinates. **/ void cairo_matrix_scale (cairo_matrix_t *matrix, double sx, double sy) { cairo_matrix_t tmp; cairo_matrix_init_scale (&tmp, sx, sy); cairo_matrix_multiply (matrix, &tmp, matrix); }
void rala_glyph_set_arrow_cb_night(void* v, affine_t t) { struct cl* cl = (struct cl*)(((set_cell_cb_t*)v)->cl); cairo_t *cr = cl->cr; static cairo_pattern_t* memoized_pattern[ARROW_TYPE_MAX]; static int cell_width, cell_height; //in pixels static cairo_matrix_t scale_matrix; //Make sure width and height are the same as before double temp_width = 1.0, temp_height = 1.0; cairo_user_to_device_distance(cr, &temp_width, &temp_height); if((int)temp_width != cell_width || (int)temp_height != cell_height) { cell_width = (int)temp_width; cell_height = (int)temp_height; memset(memoized_pattern, 0, sizeof(cairo_pattern_t*)*ARROW_TYPE_MAX); cairo_matrix_init_scale(&scale_matrix, temp_width, temp_height); } //Mark dirty if(cl->w == 0) { cl->x = 2*t.wx-1; cl->y = -(2*t.wy)-1; cl->w = 3; cl->h = 3; } else { cl->w = -1; } cairo_save(cr); cairo_translate(cr,2*t.wx, -2*t.wy); setup_arrow(cr,arrow_rotate(t, ((set_arrow_cb_t*)v)->arrow_dir)); arrow_type_t arrow_type = ((set_arrow_cb_t*)v)->arrow_type; if(!memoized_pattern[arrow_type]) { cairo_surface_t* memoizer_surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, cell_width, cell_height); cairo_t* m_cr = cairo_create(memoizer_surface); cairo_scale(m_cr, cell_width, cell_height); switch(arrow_type) { case ARROW_TYPE_NONE: arrow_none_glyph_night(m_cr); break; case ARROW_TYPE_X: arrow_x_glyph_night(m_cr); break; case ARROW_TYPE_0: arrow_0_glyph_night(m_cr); break; case ARROW_TYPE_1: arrow_1_glyph_night(m_cr); break; } memoized_pattern[arrow_type] = cairo_pattern_create_for_surface(memoizer_surface); cairo_pattern_set_matrix(memoized_pattern[arrow_type], &scale_matrix); } cairo_set_source(cr, memoized_pattern[arrow_type]); cairo_paint(cr); cairo_restore(cr); }
static cairo_status_t cairo_type1_font_create (cairo_scaled_font_subset_t *scaled_font_subset, cairo_type1_font_t **subset_return, cairo_bool_t hex_encode) { cairo_type1_font_t *font; cairo_font_face_t *font_face; cairo_matrix_t font_matrix; cairo_matrix_t ctm; cairo_font_options_t font_options; cairo_status_t status; font = calloc (1, sizeof (cairo_type1_font_t)); if (font == NULL) return _cairo_error (CAIRO_STATUS_NO_MEMORY); font->widths = calloc (scaled_font_subset->num_glyphs, sizeof (int)); if (font->widths == NULL) { free (font); return _cairo_error (CAIRO_STATUS_NO_MEMORY); } font->scaled_font_subset = scaled_font_subset; font->hex_encode = hex_encode; font_face = cairo_scaled_font_get_font_face (scaled_font_subset->scaled_font); cairo_matrix_init_scale (&font_matrix, 1000, -1000); cairo_matrix_init_identity (&ctm); _cairo_font_options_init_default (&font_options); cairo_font_options_set_hint_style (&font_options, CAIRO_HINT_STYLE_NONE); cairo_font_options_set_hint_metrics (&font_options, CAIRO_HINT_METRICS_OFF); font->type1_scaled_font = cairo_scaled_font_create (font_face, &font_matrix, &ctm, &font_options); status = font->type1_scaled_font->status; if (status) goto fail; _cairo_array_init (&font->contents, sizeof (unsigned char)); font->output = NULL; *subset_return = font; return CAIRO_STATUS_SUCCESS; fail: free (font->widths); free (font); return status; }
/** * adg_path_reflect: * @path: an #AdgPath * @vector: (allow-none): the slope of the axis * * Reflects the first segment or @path around the axis passing * throught (0, 0) and with a @vector slope. The internal segment * is duplicated and the proper transformation (computed from * @vector) to mirror the segment is applied on all its points. * The result is then reversed with cpml_segment_reverse() and * appended to the original path with adg_path_append_segment(). * * For convenience, if @vector is <constant>NULL</constant> the * path is reversed around the x axis <constant>(y = 0)</constant>. * * Since: 1.0 **/ void adg_path_reflect(AdgPath *path, const CpmlVector *vector) { AdgModel *model; cairo_matrix_t matrix; CpmlSegment segment, *dup_segment; g_return_if_fail(ADG_IS_PATH(path)); g_return_if_fail(vector == NULL || vector->x != 0 || vector->y != 0); model = (AdgModel *) path; if (vector == NULL) { cairo_matrix_init_scale(&matrix, 1, -1); } else { CpmlVector slope; gdouble cos2angle, sin2angle; cpml_pair_copy(&slope, vector); cpml_vector_set_length(&slope, 1); if (slope.x == 0 && slope.y == 0) { g_warning(_("%s: the axis of the reflection is not known"), G_STRLOC); return; } sin2angle = 2. * vector->x * vector->y; cos2angle = 2. * vector->x * vector->x - 1; cairo_matrix_init(&matrix, cos2angle, sin2angle, sin2angle, -cos2angle, 0, 0); } if (!adg_trail_put_segment((AdgTrail *) path, 1, &segment)) return; /* No need to reverse an empty segment */ if (segment.num_data == 0 || segment.num_data == 0) return; dup_segment = cpml_segment_deep_dup(&segment); if (dup_segment == NULL) return; cpml_segment_reverse(dup_segment); cpml_segment_transform(dup_segment, &matrix); dup_segment->data[0].header.type = CPML_LINE; adg_path_append_segment(path, dup_segment); g_free(dup_segment); _adg_dup_reverse_named_pairs(model, &matrix); }
RubberbandInfo * rubberband_info_new (Sheet *sheet) { RubberbandInfo *rubberband_info; cairo_pattern_t *pattern; cairo_matrix_t matrix; NG_DEBUG ("0x%x A", COLOR_A); NG_DEBUG ("0x%x B", COLOR_B); NG_DEBUG ("0x%x A PRE", COLOR_A_PRE); NG_DEBUG ("0x%x B PRE", COLOR_B_PRE); static guint32 stipple_data[8*8] = { COLOR_A_PRE, COLOR_A_PRE, COLOR_A_PRE, COLOR_B_PRE, COLOR_B_PRE, COLOR_B_PRE,COLOR_B_PRE,COLOR_A_PRE, COLOR_A_PRE, COLOR_A_PRE, COLOR_B_PRE, COLOR_B_PRE, COLOR_B_PRE, COLOR_B_PRE,COLOR_A_PRE,COLOR_A_PRE, COLOR_A_PRE, COLOR_B_PRE, COLOR_B_PRE, COLOR_B_PRE, COLOR_B_PRE, COLOR_A_PRE,COLOR_A_PRE,COLOR_A_PRE, COLOR_B_PRE, COLOR_B_PRE, COLOR_B_PRE, COLOR_B_PRE, COLOR_A_PRE, COLOR_A_PRE,COLOR_A_PRE,COLOR_A_PRE, COLOR_B_PRE, COLOR_B_PRE, COLOR_B_PRE, COLOR_A_PRE, COLOR_A_PRE, COLOR_A_PRE,COLOR_A_PRE,COLOR_B_PRE, COLOR_B_PRE, COLOR_B_PRE, COLOR_A_PRE, COLOR_A_PRE, COLOR_A_PRE, COLOR_A_PRE,COLOR_B_PRE,COLOR_B_PRE, COLOR_B_PRE, COLOR_A_PRE, COLOR_A_PRE, COLOR_A_PRE, COLOR_A_PRE, COLOR_B_PRE,COLOR_B_PRE,COLOR_B_PRE, COLOR_A_PRE, COLOR_A_PRE, COLOR_A_PRE, COLOR_A_PRE, COLOR_B_PRE, COLOR_B_PRE,COLOR_B_PRE,COLOR_B_PRE}; /* the stipple patten should look like that * 1 1 1 0 0 0 0 1 * 1 1 0 0 0 0 1 1 * 1 0 0 0 0 1 1 1 * 0 0 0 0 1 1 1 1 * * 0 0 0 1 1 1 1 0 * 0 0 1 1 1 1 0 0 * 0 1 1 1 1 0 0 0 * 1 1 1 1 0 0 0 0 */ rubberband_info = g_new (RubberbandInfo, 1); rubberband_info->state = RUBBERBAND_START; pattern = create_stipple ("lightgrey", (guchar*)stipple_data); //scale 5x, see http://cairographics.org/manual/cairo-cairo-pattern-t.html#cairo-pattern-t cairo_matrix_init_scale (&matrix, 1.0, 1.0); cairo_pattern_set_matrix (pattern, &matrix); rubberband_info->rectangle = GOO_CANVAS_RECT (goo_canvas_rect_new ( GOO_CANVAS_ITEM (sheet->object_group), 10.0, 10.0, 10.0, 10.0, "stroke-color", "black", "line-width", 0.2, "fill-pattern", pattern, "visibility", GOO_CANVAS_ITEM_INVISIBLE, NULL)); cairo_pattern_destroy (pattern); return rubberband_info; }
//================================================================================= // mark_paint_group //================================================================================= void mark_paint_group(Qdr *qdr, cairo_t *cr, cairo_pattern_t *pattern, int _x, int _y) { int idx = qdr->group.data[_x][_y]; if(qdr->group.attr[idx].count==1 && qdr->group.image){ int x = (_x + qdr->margin) * qdr->msize; int y = (_y + qdr->margin) * qdr->msize; if(!pattern){ struct QDRBindImage b; //cairo_surface_t *surface = cairo_image_surface_create_from_png(qdr->group.image); cairo_surface_t *surface = image_surface_create(&b, qdr->group.image); if(!surface) return; int w = cairo_image_surface_get_width(surface); int h = cairo_image_surface_get_height(surface); pattern = cairo_pattern_create_for_surface(surface); //scaling if(w>qdr->msize || h>qdr->msize){ int big = w>h ? w : h; double scaling = (double)qdr->msize/big; cairo_matrix_t matrix; cairo_matrix_init_scale(&matrix, 1/scaling, 1/scaling); cairo_pattern_set_matrix(pattern, &matrix); } cairo_surface_destroy(surface); if(b.data) free(b.data); } //umm... if(qdr->group.is_mark){ cairo_set_source_rgba(cr, qdr->group.attr[idx].r, qdr->group.attr[idx].g, qdr->group.attr[idx].b, qdr->group.attr[idx].a); cairo_fill(cr); } cairo_translate(cr, x, y); cairo_set_source(cr, pattern); //cairo_pattern_set_filter (cairo_get_source(cr), CAIRO_FILTER_GAUSSIAN); cairo_rectangle(cr, 0, 0, qdr->msize, qdr->msize); //cairo_fill(cr); cairo_translate(cr, -x, -y); return; } cairo_set_source_rgba(cr, qdr->group.attr[idx].r, qdr->group.attr[idx].g, qdr->group.attr[idx].b, qdr->group.attr[idx].a); cairo_fill(cr); }
void FontPlatformData::initializeWithFontFace(cairo_font_face_t* fontFace, const FontDescription& fontDescription) { cairo_font_options_t* options = getDefaultFontOptions(); cairo_matrix_t ctm; cairo_matrix_init_identity(&ctm); // Scaling a font with width zero size leads to a failed cairo_scaled_font_t instantiations. // Instead we scale we scale the font to a very tiny size and just abort rendering later on. float realSize = m_size ? m_size : 1; cairo_matrix_t fontMatrix; if (!m_pattern) cairo_matrix_init_scale(&fontMatrix, realSize, realSize); else { setCairoFontOptionsFromFontConfigPattern(options, m_pattern.get()); // FontConfig may return a list of transformation matrices with the pattern, for instance, // for fonts that are oblique. We use that to initialize the cairo font matrix. FcMatrix fontConfigMatrix, *tempFontConfigMatrix; FcMatrixInit(&fontConfigMatrix); // These matrices may be stacked in the pattern, so it's our job to get them all and multiply them. for (int i = 0; FcPatternGetMatrix(m_pattern.get(), FC_MATRIX, i, &tempFontConfigMatrix) == FcResultMatch; i++) FcMatrixMultiply(&fontConfigMatrix, &fontConfigMatrix, tempFontConfigMatrix); cairo_matrix_init(&fontMatrix, fontConfigMatrix.xx, -fontConfigMatrix.yx, -fontConfigMatrix.xy, fontConfigMatrix.yy, 0, 0); // We requested an italic font, but Fontconfig gave us one that was neither oblique nor italic. int actualFontSlant; if (fontDescription.italic() && FcPatternGetInteger(m_pattern.get(), FC_SLANT, 0, &actualFontSlant) == FcResultMatch) m_syntheticOblique = actualFontSlant == FC_SLANT_ROMAN; // The matrix from FontConfig does not include the scale. cairo_matrix_scale(&fontMatrix, realSize, realSize); } if (syntheticOblique()) { static const float syntheticObliqueSkew = -tanf(14 * acosf(0) / 90); cairo_matrix_t skew = {1, 0, syntheticObliqueSkew, 1, 0, 0}; cairo_matrix_multiply(&fontMatrix, &skew, &fontMatrix); } m_horizontalOrientationMatrix = fontMatrix; if (m_orientation == Vertical) rotateCairoMatrixForVerticalOrientation(&fontMatrix); m_scaledFont = cairo_scaled_font_create(fontFace, &fontMatrix, &ctm, options); cairo_font_options_destroy(options); }
static void draw_n (cairo_t *cr, cairo_pattern_t *pat, double dest_size, int n) { cairo_matrix_t mat; cairo_matrix_init_scale (&mat, SRC_WIDTH / dest_size, SRC_HEIGHT / dest_size); cairo_matrix_translate (&mat, n * -dest_size, 0.0); cairo_pattern_set_matrix (pat, &mat); cairo_set_source (cr, pat); cairo_new_path (cr); cairo_rectangle (cr, n * dest_size, 0.0, dest_size, dest_size); cairo_fill (cr); }
static gboolean pattern_value_parse (GtkCssParser *parser, GValue *value) { if (_gtk_css_parser_try (parser, "none", TRUE)) { /* nothing to do here */ } else { GError *error = NULL; gchar *path; GdkPixbuf *pixbuf; GFile *file; cairo_surface_t *surface; cairo_pattern_t *pattern; cairo_matrix_t matrix; file = _gtk_css_parser_read_url (parser); if (file == NULL) return FALSE; path = g_file_get_path (file); g_object_unref (file); pixbuf = gdk_pixbuf_new_from_file (path, &error); g_free (path); if (pixbuf == NULL) { _gtk_css_parser_take_error (parser, error); return FALSE; } surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, 1, NULL); pattern = cairo_pattern_create_for_surface (surface); cairo_surface_destroy (surface); cairo_matrix_init_scale (&matrix, gdk_pixbuf_get_width (pixbuf), gdk_pixbuf_get_height (pixbuf)); cairo_pattern_set_matrix (pattern, &matrix); g_object_unref (pixbuf); g_value_take_boxed (value, pattern); } return TRUE; }
void FontPlatformData::platformDataInit(HFONT font, float size, HDC hdc, WCHAR* faceName) { m_fontFace = cairo_win32_font_face_create_for_hfont(font); cairo_matrix_t sizeMatrix, ctm; cairo_matrix_init_identity(&ctm); cairo_matrix_init_scale(&sizeMatrix, size, size); static cairo_font_options_t* fontOptions = 0; if (!fontOptions) { fontOptions = cairo_font_options_create(); cairo_font_options_set_antialias(fontOptions, CAIRO_ANTIALIAS_SUBPIXEL); } m_scaledFont = cairo_scaled_font_create(m_fontFace, &sizeMatrix, &ctm, fontOptions); }
static cairo_surface_t * _eventd_nd_cairo_limit_size(cairo_surface_t *source, gint max_width, gint max_height) { gdouble s = 1.0; gint width, height; cairo_surface_t *surface; cairo_t *cr; cairo_pattern_t *pattern; cairo_matrix_t matrix; width = cairo_image_surface_get_width(source); height = cairo_image_surface_get_height(source); if ( ( width > max_width ) && ( height > max_height ) ) { if ( width > height ) s = (gdouble) max_width / (gdouble) width; else s = (gdouble) max_height / (gdouble) height; } else if ( width > max_width ) s = (gdouble) max_width / (gdouble) width; else if ( height > max_height ) s = (gdouble) max_height / (gdouble) height; else return source; width *= s; height *= s; surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); cr = cairo_create(surface); cairo_matrix_init_scale(&matrix, 1. / s, 1. / s); pattern = cairo_pattern_create_for_surface(source); cairo_pattern_set_matrix(pattern, &matrix); cairo_set_source(cr, pattern); cairo_paint(cr); cairo_pattern_destroy(pattern); cairo_destroy(cr); cairo_surface_destroy(source); return surface; }