CAMLprim value ml_cairo_get_font_matrix (value v_cr) { #ifndef ARCH_ALIGN_DOUBLE CAMLparam1(v_cr); value v = cairo_matrix_alloc(); cairo_get_font_matrix (cairo_t_val (v_cr), cairo_matrix_t_val (v)); CAMLreturn(v); #else cairo_matrix_t mat; cairo_get_font_matrix (cairo_t_val (v_cr), &mat); check_cairo_status (v_cr); return ml_convert_cairo_matrix_out (&mat); #endif }
static PyObject * pycairo_get_font_matrix (PycairoContext *o) { cairo_matrix_t matrix; cairo_get_font_matrix (o->ctx, &matrix); return PycairoMatrix_FromMatrix (&matrix); }
static VALUE cr_get_font_matrix (VALUE self) { cairo_matrix_t matrix; cairo_get_font_matrix (_SELF, &matrix); cr_check_status (_SELF); return CRMATRIX2RVAL (&matrix); }
static int cr_get_font_matrix (lua_State *L) { cairo_t **obj = luaL_checkudata(L, 1, OOCAIRO_MT_NAME_CONTEXT); cairo_matrix_t mat; cairo_get_font_matrix(*obj, &mat); create_lua_matrix(L, &mat); return 1; }
int FontHeightWithContextReal(cairo_t * c) { cairo_matrix_t matrix; cairo_get_font_matrix(c, &matrix); int height = matrix.xx; return height; }
/* Currently not used */ static int CalculateStringWidthsUTF8 (cairo_t *ct, GDIPCONST GpFont *gdiFont, const BYTE *utf8, unsigned long StringDetailElements, GpStringDetailStruct *StringDetails) { FT_Face face; size_t i; gunichar *ucs4 = NULL; cairo_font_face_t *Font; GpStringDetailStruct *CurrentDetail; glong NumOfGlyphs; cairo_matrix_t matrix; #ifdef DRAWSTRING_DEBUG printf("CalculateStringWidths(font, %s, %d, details) called\n", utf8, StringDetailElements); #endif Font = (cairo_font_face_t *)gdiFont->cairofnt; face = gdip_cairo_ft_font_lock_face(Font); if (!face) return 0; cairo_get_font_matrix(ct, &matrix); cairo_matrix_scale(&matrix, gdiFont->sizeInPixels, gdiFont->sizeInPixels); ucs4 = g_utf8_to_ucs4 ((const gchar *) utf8, (glong)-1, NULL, &NumOfGlyphs, NULL); if ((NumOfGlyphs == 0) || (ucs4 == NULL)) { return 0; } CurrentDetail=StringDetails; for (i = 0; i < NumOfGlyphs; i++) { FT_Load_Glyph (face, FT_Get_Char_Index (face, ucs4[i]), FT_LOAD_DEFAULT); CurrentDetail->Width = DOUBLE_FROM_26_6 (face->glyph->advance.x); CurrentDetail++; } gdip_cairo_ft_font_unlock_face(Font); GdipFree(ucs4); #ifdef DRAWSTRING_DEBUG printf("CalculateStringWidths: string >%s< translated into %d glyphs\n", utf8, NumOfGlyphs); #endif return NumOfGlyphs; }
GpStatus cairo_DrawString (GpGraphics *graphics, GDIPCONST WCHAR *stringUnicode, int length, GDIPCONST GpFont *font, GDIPCONST RectF *rc, GDIPCONST GpStringFormat *format, GpBrush *brush) { cairo_matrix_t SavedMatrix; GpStringFormat *fmt; GpStringDetailStruct *StringDetails; WCHAR *CleanString; GpDrawTextData data; /* avoid recomputation of stuff done while measuring */ int StringLen = length; GpStatus status = AllocStringData (&CleanString, &StringDetails, length); if (status != Ok) return status; /* a NULL format is valid, it means get the generic default values (and free them later) */ if (!format) { GdipStringFormatGetGenericDefault ((GpStringFormat **)&fmt); } else { fmt = (GpStringFormat *)format; } /* is the following ok ? */ cairo_get_font_matrix (graphics->ct, &SavedMatrix); status = MeasureString (graphics, stringUnicode, &StringLen, font, rc, fmt, brush, NULL, NULL, NULL, CleanString, StringDetails, &data); if ((status == Ok) && (StringLen > 0)) { status = DrawString (graphics, stringUnicode, StringLen, font, rc, fmt, brush, CleanString, StringDetails, &data); } /* Restore matrix to original values */ cairo_set_font_matrix (graphics->ct, &SavedMatrix); /* Cleanup */ GdipFree (CleanString); GdipFree (StringDetails); /* we must delete the default stringformat (when one wasn't provided by the caller) */ if (format != fmt) GdipDeleteStringFormat (fmt); return status; }
GpStatus cairo_MeasureString (GpGraphics *graphics, GDIPCONST WCHAR *stringUnicode, int length, GDIPCONST GpFont *font, GDIPCONST RectF *rc, GDIPCONST GpStringFormat *format, RectF *boundingBox, int *codepointsFitted, int *linesFilled) { cairo_matrix_t SavedMatrix; GpStringFormat *fmt; GpStringDetailStruct *StringDetails; WCHAR *CleanString; int StringLen = length; GpStatus status; status = AllocStringData (&CleanString, &StringDetails, length); if (status != Ok) return status; /* a NULL format is valid, it means get the generic default values (and free them later) */ if (!format) { GdipStringFormatGetGenericDefault ((GpStringFormat **)&fmt); } else { fmt = (GpStringFormat *)format; } /* is the following ok ? */ cairo_get_font_matrix (graphics->ct, &SavedMatrix); status = MeasureString (graphics, stringUnicode, &StringLen, font, rc, fmt, NULL, boundingBox, codepointsFitted, linesFilled, CleanString, StringDetails, NULL); /* Restore matrix to original values */ cairo_set_font_matrix (graphics->ct, &SavedMatrix); /* Cleanup */ GdipFree (CleanString); GdipFree (StringDetails); /* we must delete the default stringformat (when one wasn't provided by the caller) */ if (format != fmt) GdipDeleteStringFormat (fmt); return status; }
void Context::getFontMatrix( Matrix *matrix ) { cairo_get_font_matrix( mCairo, &matrix->getCairoMatrix() ); }
static void render_spect_border (cairo_surface_t * surface, const char * filename, double left, double width, double seconds, double top, double height, double min_freq, double max_freq, bool log_freq) { char text [512] ; cairo_t * cr ; cairo_text_extents_t extents ; cairo_matrix_t matrix ; TICKS ticks ; int k, tick_count ; cr = cairo_create (surface) ; cairo_set_source_rgb (cr, 1.0, 1.0, 1.0) ; cairo_set_line_width (cr, BORDER_LINE_WIDTH) ; /* Print title. */ cairo_select_font_face (cr, font_family, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL) ; cairo_set_font_size (cr, 1.0 * TITLE_FONT_SIZE) ; snprintf (text, sizeof (text), "Spectrogram: %s", filename) ; cairo_text_extents (cr, text, &extents) ; cairo_move_to (cr, left + 2, top - extents.height / 2) ; cairo_show_text (cr, text) ; /* Print labels. */ cairo_select_font_face (cr, font_family, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL) ; cairo_set_font_size (cr, 1.0 * NORMAL_FONT_SIZE) ; /* Border around actual spectrogram. */ cairo_rectangle (cr, left, top, width, height) ; /* Put ticks on Time axis */ tick_count = calculate_ticks (0.0, seconds, width, false, &ticks) ; for (k = 0 ; k < tick_count ; k++) { y_line (cr, left + ticks.distance [k], top + height, TICK_LEN) ; if (JUST_A_TICK (ticks, k)) continue ; str_print_value (text, sizeof (text), ticks.value [k], ticks.decimal_places_to_print) ; cairo_text_extents (cr, text, &extents) ; cairo_move_to (cr, left + ticks.distance [k] - extents.width / 2, top + height + 8 + extents.height) ; cairo_show_text (cr, text) ; } ; /* Put ticks on Frequency axis */ tick_count = calculate_ticks (min_freq, max_freq, height, log_freq, &ticks) ; for (k = 0 ; k < tick_count ; k++) { x_line (cr, left + width, top + height - ticks.distance [k], TICK_LEN) ; if (JUST_A_TICK (ticks, k)) continue ; str_print_value (text, sizeof (text), ticks.value [k], ticks.decimal_places_to_print) ; cairo_text_extents (cr, text, &extents) ; cairo_move_to (cr, left + width + 12, top + height - ticks.distance [k] + extents.height / 4.5) ; cairo_show_text (cr, text) ; } ; cairo_set_font_size (cr, 1.0 * NORMAL_FONT_SIZE) ; /* Label X axis. */ snprintf (text, sizeof (text), "Time (secs)") ; cairo_text_extents (cr, text, &extents) ; cairo_move_to (cr, left + (width - extents.width) / 2, cairo_image_surface_get_height (surface) - 8) ; cairo_show_text (cr, text) ; /* Label Y axis (rotated). */ snprintf (text, sizeof (text), "Frequency (Hz)") ; cairo_text_extents (cr, text, &extents) ; cairo_get_font_matrix (cr, &matrix) ; cairo_matrix_rotate (&matrix, -0.5 * M_PI) ; cairo_set_font_matrix (cr, &matrix) ; cairo_move_to (cr, cairo_image_surface_get_width (surface) - 12, top + (height + extents.width) / 2) ; cairo_show_text (cr, text) ; cairo_destroy (cr) ; } /* render_spect_border */