本文整理汇总了C++中pango_layout_set_text函数的典型用法代码示例。如果您正苦于以下问题:C++ pango_layout_set_text函数的具体用法?C++ pango_layout_set_text怎么用?C++ pango_layout_set_text使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pango_layout_set_text函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: text_to_path
gboolean
text_to_path (const Text *text, GArray *points)
{
cairo_t *cr;
cairo_surface_t *surface;
PangoLayout *layout;
PangoRectangle ink_rect;
char *str;
gboolean ret = FALSE;
if (!PANGO_IS_CAIRO_FONT_MAP (pango_context_get_font_map (dia_font_get_context())))
return FALSE;
layout = pango_layout_new(dia_font_get_context());
pango_layout_set_font_description (layout, dia_font_get_description (text->font));
pango_layout_set_indent (layout, 0);
pango_layout_set_justify (layout, FALSE);
pango_layout_set_alignment (layout,
text->alignment == ALIGN_LEFT ? PANGO_ALIGN_LEFT :
text->alignment == ALIGN_RIGHT ? PANGO_ALIGN_RIGHT : PANGO_ALIGN_CENTER);
str = text_get_string_copy (text);
pango_layout_set_text (layout, str, -1);
g_free (str);
pango_layout_get_extents (layout, &ink_rect, NULL);
/* any surface should do - this one is always available */
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
ink_rect.width / PANGO_SCALE, ink_rect.height / PANGO_SCALE);
cr = cairo_create (surface);
cairo_surface_destroy (surface);
pango_cairo_layout_path (cr, layout);
/* convert the path */
if (cairo_status (cr) == CAIRO_STATUS_SUCCESS)
{
cairo_path_t *path;
int i;
path = cairo_copy_path (cr);
for (i=0; i < path->num_data; i += path->data[i].header.length) {
cairo_path_data_t *data = &path->data[i];
BezPoint bp;
switch (data->header.type) {
case CAIRO_PATH_MOVE_TO :
bp.type = BEZ_MOVE_TO;
bp.p1.x = data[1].point.x; bp.p1.y = data[1].point.y;
break;
case CAIRO_PATH_LINE_TO :
bp.type = BEZ_LINE_TO;
bp.p1.x = data[1].point.x; bp.p1.y = data[1].point.y;
break;
case CAIRO_PATH_CURVE_TO :
bp.type = BEZ_CURVE_TO;
bp.p1.x = data[1].point.x; bp.p1.y = data[1].point.y;
bp.p2.x = data[2].point.x; bp.p2.y = data[2].point.y;
bp.p3.x = data[3].point.x; bp.p3.y = data[3].point.y;
break;
case CAIRO_PATH_CLOSE_PATH :
/* can't do anything */
default :
continue;
}
g_array_append_val (points, bp);
}
ret = (path->status == CAIRO_STATUS_SUCCESS);
cairo_path_destroy (path);
}
/* finally scale it ? */
/* clean up */
g_object_unref (layout);
cairo_destroy (cr);
return ret;
}
示例2: create_pages
static void
create_pages (Pqueue * queue)
{
gchar * msg;
gdouble line_height;
guint i, id;
glong index;
PangoLayoutLine * line;
PangoRectangle ink_rect, logical_rect;
g_return_if_fail (queue);
g_return_if_fail (queue->pos < strlen(queue->text));
while (queue->pos < strlen (queue->text))
{
while (gtk_events_pending ())
gtk_main_iteration ();
for (i = 0; i < queue->lines_per_page; i++)
{
line = pango_layout_iter_get_line (queue->iter);
pango_layout_iter_next_line (queue->iter);
pango_layout_iter_get_line_extents (queue->iter, &ink_rect, &logical_rect);
index = pango_layout_iter_get_index (queue->iter);
if (index == 0)
{
i = queue->lines_per_page;
queue->pos = strlen (queue->text);
g_message ("%s", _("Error: Pango iter index is zero."));
continue;
}
line_height = logical_rect.height / PANGO_SCALE;
if ((queue->page_height + line_height) > (queue->height - (EDGE_MARGIN/2)))
{
queue->pos += index;
queue->page_height = EDGE_MARGIN;
gtk_progress_bar_pulse (queue->progressbar);
pango_cairo_update_layout (queue->cr, queue->layout);
queue->layout = make_new_page (queue->context, queue->desc, queue->height, queue->width);
i = queue->lines_per_page;
queue->page_count++;
pango_layout_set_text (queue->layout, (queue->text+queue->pos), -1);
queue->iter = pango_layout_get_iter (queue->layout);
pango_cairo_show_layout_line (queue->cr, line);
pango_cairo_update_layout (queue->cr, queue->layout);
cairo_show_page (queue->cr);
}
else
pango_cairo_show_layout_line (queue->cr, line);
queue->page_height += line_height;
cairo_move_to (queue->cr, SIDE_MARGIN / 2, queue->page_height);
}
}
pango_layout_iter_free (queue->iter);
gtk_progress_bar_set_fraction (queue->progressbar, 0.0);
cairo_surface_destroy(queue->surface);
pango_font_description_free (queue->desc);
g_object_unref (queue->context);
g_object_unref (queue->layout);
cairo_destroy (queue->cr);
id = gtk_statusbar_get_context_id (queue->statusbar, PACKAGE);
msg = g_strdup_printf (ngettext("Saved PDF file. (%ld page)",
"Saved PDF file (%ld pages).", queue->page_count), queue->page_count);
gtk_statusbar_push (queue->statusbar, id, msg);
g_free (msg);
}
示例3: text_get_extents
gboolean
text_get_extents (const gchar *fontname,
const gchar *text,
gint *width,
gint *height,
gint *ascent,
gint *descent)
{
PangoFontDescription *font_desc;
PangoContext *context;
PangoLayout *layout;
PangoFontMap *fontmap;
PangoRectangle rect;
g_return_val_if_fail (fontname != NULL, FALSE);
g_return_val_if_fail (text != NULL, FALSE);
fontmap = pango_cairo_font_map_new_for_font_type (CAIRO_FONT_TYPE_FT);
if (! fontmap)
g_error ("You are using a Pango that has been built against a cairo "
"that lacks the Freetype font backend");
pango_cairo_font_map_set_resolution (PANGO_CAIRO_FONT_MAP (fontmap),
72.0); /* FIXME: resolution */
context = pango_font_map_create_context (fontmap);
g_object_unref (fontmap);
layout = pango_layout_new (context);
g_object_unref (context);
font_desc = pango_font_description_from_string (fontname);
pango_layout_set_font_description (layout, font_desc);
pango_font_description_free (font_desc);
pango_layout_set_text (layout, text, -1);
pango_layout_get_pixel_extents (layout, NULL, &rect);
if (width)
*width = rect.width;
if (height)
*height = rect.height;
if (ascent || descent)
{
PangoLayoutIter *iter;
PangoLayoutLine *line;
iter = pango_layout_get_iter (layout);
line = pango_layout_iter_get_line_readonly (iter);
pango_layout_iter_free (iter);
pango_layout_line_get_pixel_extents (line, NULL, &rect);
if (ascent)
*ascent = PANGO_ASCENT (rect);
if (descent)
*descent = - PANGO_DESCENT (rect);
}
g_object_unref (layout);
return TRUE;
}
示例4: g_type_init
unsigned Gosu::pango::textWidth(const std::wstring& text,
const std::wstring& fontFace, unsigned fontHeight,
unsigned fontFlags)
{
g_type_init();
int dpi_x = 100, dpi_y = 100;
context = pango_ft2_get_context(dpi_x, dpi_y);
pango_context_set_language(context, pango_language_from_string ("en_US"));
PangoDirection init_dir = PANGO_DIRECTION_LTR;
pango_context_set_base_dir(context, init_dir);
// static PangoFontDescription *font_description;
font_description = pango_font_description_new();
pango_font_description_set_family(font_description,
g_strdup(narrow(fontFace).c_str()));
pango_font_description_set_style(font_description,
(fontFlags & ffItalic) ? PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL);
pango_font_description_set_variant(font_description, PANGO_VARIANT_NORMAL);
pango_font_description_set_weight(font_description,
(fontFlags & ffBold) ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL);
pango_font_description_set_stretch(font_description, PANGO_STRETCH_NORMAL);
int init_scale = int(fontHeight/2.0 + 0.5);
pango_font_description_set_size(font_description, init_scale * PANGO_SCALE);
pango_context_set_font_description(context, font_description);
layout = pango_layout_new(context);
if(fontFlags & ffUnderline)
{
// PangoAttribute *attr;
attr = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE);
attr->start_index = 0;
attr->end_index = text.length();
// PangoAttrList* attrList;
attrList = pango_attr_list_new();
pango_attr_list_insert(attrList, attr);
pango_layout_set_attributes(layout, attrList);
pango_attr_list_unref(attrList);
}
// IMPR: Catch errors? (Last NULL-Pointer)
gchar* utf8Str = g_ucs4_to_utf8((gunichar*)text.c_str(), text.length(), NULL, NULL, NULL);
pango_layout_set_text(layout, utf8Str, -1);
g_free(utf8Str);
PangoDirection base_dir = pango_context_get_base_dir(context);
pango_layout_set_alignment(layout,
base_dir == PANGO_DIRECTION_LTR ? PANGO_ALIGN_LEFT : PANGO_ALIGN_RIGHT);
pango_layout_set_width(layout, -1);
PangoRectangle logical_rect;
pango_layout_get_pixel_extents(layout, NULL, &logical_rect);
height = logical_rect.height;
width = logical_rect.width;
return width;
}
示例5: draw_callback
static gboolean draw_callback(GtkWidget *widget,cairo_t *cr,gpointer data)
{
guint width=gtk_widget_get_allocated_width(widget);
guint height=gtk_widget_get_allocated_height(widget);
double sw,sh,spacing;
//PangoLayout* pn=gtk_widget_create_pango_layout(widget,"HELLO? IS THIS WORKING?(\u2126)");
PangoContext* pc=gtk_widget_get_pango_context(widget);
PangoLayout* pn=pango_layout_new(pc);
sw=((double)width-2*gutter)/grid.width;
sh=((double)height-2*gutter)/grid.height;
spacing=MIN(sw,sh);
cairo_set_source_rgb(cr,0,0,255);
// cairo_arc(cr,mouseX,mouseY,5,0,2*G_PI);
cairo_translate(cr,(double)width/2,(double)height/2);
cairo_translate(cr,-(double)grid.width/2.0*spacing,-(double)grid.height/2.0*spacing);
int i,j;
cairo_set_source_rgb(cr,0,0,0);
for(i=0;i<grid.map.ccount;i++)
{
Component* c=grid.map.components+i;
int A=c->A;
int B=c->B;
draw_component(cr,pc,spacing,spacing*(A%(grid.width+1)),spacing*(A/(grid.width+1)),spacing*(B%(grid.width+1)),spacing*(B/(grid.width+1)),c);
}
cairo_set_source_rgb(cr,0,0,0);
char buffer[20];
for(i=0;i<=grid.width;i++)
{
for(j=0;j<=grid.height;j++)
{
if(draw_flags&VOLTAGES){
sprintf(buffer,"%.2fV",grid.map.vertices[i+j*(grid.width+1)].voltage);
pango_layout_set_text(pn,buffer,-1);
int w,h;
pango_layout_get_pixel_size(pn,&w,&h);
cairo_arc(cr,i*spacing,j*spacing,25,0,2*G_PI);
cairo_set_source_rgb(cr,1.0,1.0,1.0);
cairo_fill_preserve(cr);
cairo_set_source_rgb(cr,0.0,0.0,0.0);
cairo_stroke(cr);
cairo_move_to(cr,i*spacing-w/2,j*spacing-h/2);
pango_cairo_update_layout(cr,pn);
pango_cairo_show_layout(cr,pn);
cairo_new_path(cr);
/* sprintf(buffer,"%gV",grid.map.vertices[i+j*(grid.width+1)].voltage);
pango_layout_set_text(pn,buffer,-1);
int w,h;
pango_layout_get_pixel_size(pn,&w,&h);
cairo_arc(cr,i*spacing,j*spacing,w/2,0,2*G_PI);
cairo_set_source_rgb(cr,1.0,1.0,1.0);
cairo_fill_preserve(cr);
cairo_set_source_rgb(cr,0.0,0.0,0.0);
cairo_stroke(cr);
cairo_move_to(cr,i*spacing-w/2,j*spacing-h/2);
pango_cairo_update_layout(cr,pn);
pango_cairo_show_layout(cr,pn);
cairo_new_path(cr);*/
}else{
cairo_arc(cr,i*spacing,j*spacing,2,0,2*G_PI);
cairo_set_source_rgb(cr,1.0,1.0,1.0);
cairo_fill_preserve(cr);
cairo_set_source_rgb(cr,0.0,0.0,0.0);
cairo_stroke(cr);
}
}
}
//pango_cairo_show_layout(cr,pn);
return FALSE;
}
示例6: draw_component
void draw_component(cairo_t *cr,PangoContext* pc,double unit,double x1,double y1,double x2,double y2,Component* com)
{
PangoLayout* pn=pango_layout_new(pc);
char buffer[20];
double ang=atan2(y2-y1,x2-x1);
if((ang>90&&ang<270)){
ang-=180;
}
int w=0;
int h=0;
if(draw_flags&CURRENTS){
sprintf(buffer,"%.3gA",com->current);
cairo_move_to(cr,(x1+x2)/2,(y1+y2)/2);
pango_layout_set_text(pn,buffer,-1);
cairo_save(cr);
cairo_translate(cr,(x1+x2)/2,(y1+y2)/2);
pango_layout_get_pixel_size(pn,&w,&h);
cairo_rotate(cr,ang);
cairo_move_to(cr,-w/2,10);
pango_cairo_update_layout(cr,pn);
pango_cairo_show_layout(cr,pn);
cairo_restore(cr);
}
if(com->type==WIRE)
{
cairo_move_to(cr,x1,y1);
cairo_line_to(cr,x2,y2);
cairo_stroke(cr);
return;
}
if(com->type==RESISTOR)
{
//char buffer[20];
//sprintf(buffer,"%g\u2126 %gA",*(double*)com->data,com->current);
cairo_move_to(cr,x1,y1);
cairo_save(cr);
cairo_translate(cr,(x1+x2)/2,(y1+y2)/2);
/*cairo_move_to(cr,unit*.2,unit*.2);
PangoLayout* pn=pango_layout_new(pc);
pango_layout_set_text(pn,buffer,-1);
pango_cairo_update_layout(cr,pn);
pango_cairo_show_layout(cr,pn);*/
cairo_scale(cr,unit,unit);
cairo_rotate(cr,atan2(y2-y1,x2-x1));
cairo_line_to(cr,-.25,0);
cairo_line_to(cr,-.1875,.125);
cairo_line_to(cr,-.0625,-.125);
cairo_line_to(cr,.0625,.125);
cairo_line_to(cr,.1875,-.125);
cairo_line_to(cr,.25,0);
cairo_restore(cr);
cairo_line_to(cr,x2,y2);
cairo_stroke(cr);
cairo_save(cr);
cairo_translate(cr,(x1+x2)/2,(y1+y2)/2);
cairo_rotate(cr,ang);
sprintf(buffer,"%g\u2126",*(double*)com->data);
pango_layout_set_text(pn,buffer,-1);
pango_layout_get_pixel_size(pn,&w,&h);
cairo_move_to(cr,-w/2,-h-10);
pango_cairo_update_layout(cr,pn);
pango_cairo_show_layout(cr,pn);
cairo_restore(cr);
cairo_new_path(cr);
return;
}
if(com->type==BATTERY)
{
if(*(double*)com->data==0){
cairo_save(cr);
const double dash[]={10};
cairo_set_dash(cr,dash,1,0);
cairo_move_to(cr,x1,y1);
cairo_line_to(cr,x2,y2);
cairo_stroke(cr);
cairo_restore(cr);
}else{
if(*(double*)com->data<0){
double tmp=x1;
x1=x2;
x2=tmp;
tmp=y1;
y1=y2;
y2=tmp;
}
cairo_move_to(cr,x1,y1);
cairo_save(cr);
cairo_translate(cr,(x1+x2)/2,(y1+y2)/2);
cairo_scale(cr,unit,unit);
cairo_rotate(cr,atan2(y2-y1,x2-x1));
cairo_line_to(cr,-.05,0);
cairo_move_to(cr,-.05,.25);
cairo_line_to(cr,-.05,-.25);
cairo_move_to(cr,.05,.15);
cairo_line_to(cr,.05,-.15);
cairo_move_to(cr,-.15,-.25);
cairo_line_to(cr,-.25,-.25);
//.........这里部分代码省略.........
示例7: pango_attr_list_new
bool wxFont::GTKSetPangoAttrs(PangoLayout* layout) const
{
if (!IsOk() || !(GetUnderlined() || GetStrikethrough()))
return false;
PangoAttrList* attrs = pango_attr_list_new();
PangoAttribute* a;
#ifndef __WXGTK3__
if (wx_pango_version_check(1,16,0))
{
// a PangoLayout which has leading/trailing spaces with underlined font
// is not correctly drawn by this pango version: Pango won't underline the spaces.
// This can be a problem; e.g. wxHTML rendering of underlined text relies on
// this behaviour. To workaround this problem, we use a special hack here
// suggested by pango maintainer Behdad Esfahbod: we prepend and append two
// empty space characters and give them a dummy colour attribute.
// This will force Pango to underline the leading/trailing spaces, too.
const char* text = pango_layout_get_text(layout);
const size_t n = strlen(text);
if ((n > 0 && text[0] == ' ') || (n > 1 && text[n - 1] == ' '))
{
wxCharBuffer buf(n + 6);
// copy the leading U+200C ZERO WIDTH NON-JOINER encoded in UTF8 format
memcpy(buf.data(), "\342\200\214", 3);
// copy the user string
memcpy(buf.data() + 3, text, n);
// copy the trailing U+200C ZERO WIDTH NON-JOINER encoded in UTF8 format
memcpy(buf.data() + 3 + n, "\342\200\214", 3);
pango_layout_set_text(layout, buf, n + 6);
// Add dummy attributes (use colour as it's invisible anyhow for 0
// width spaces) to ensure that the spaces in the beginning/end of the
// string are underlined too.
a = pango_attr_foreground_new(0x0057, 0x52A9, 0xD614);
a->start_index = 0;
a->end_index = 3;
pango_attr_list_insert(attrs, a);
a = pango_attr_foreground_new(0x0057, 0x52A9, 0xD614);
a->start_index = n + 3;
a->end_index = n + 6;
pango_attr_list_insert(attrs, a);
}
}
#endif // !__WXGTK3__
if (GetUnderlined())
{
a = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE);
pango_attr_list_insert(attrs, a);
}
if (GetStrikethrough())
{
a = pango_attr_strikethrough_new(true);
pango_attr_list_insert(attrs, a);
}
pango_layout_set_attributes(layout, attrs);
pango_attr_list_unref(attrs);
return true;
}
示例8: render_text
void render_text(GdkDrawable *da, GdkGC *gc, int x, int y, double angle,
const char *s, const char *font, double xalign, double yalign,
int xmax, int ymax)
{
GdkScreen *screen;
PangoRenderer *renderer;
PangoContext *context;
PangoLayout *layout;
PangoFontDescription *desc;
int width, height;
PangoMatrix m = PANGO_MATRIX_INIT;
double f_min, f;
/* set up the renderer */
screen = gdk_drawable_get_screen(da);
renderer = gdk_pango_renderer_get_default(screen);
gdk_pango_renderer_set_drawable(GDK_PANGO_RENDERER(renderer), da);
gdk_pango_renderer_set_gc(GDK_PANGO_RENDERER(renderer), gc);
/* start preparing the layout */
context = gdk_pango_context_get_for_screen(screen);
layout = pango_layout_new(context);
pango_layout_set_text(layout, s, -1);
/* apply the font */
desc = pango_font_description_from_string(font);
pango_layout_set_font_description(layout, desc);
pango_font_description_free(desc);
/* align and position the text */
pango_layout_get_size(layout, &width, &height);
f_min = 1.0;
if (xmax) {
f = xmax/((double) width/PANGO_SCALE);
if (f < f_min)
f_min = f;
}
if (ymax) {
f = ymax/((double) height/PANGO_SCALE);
if (f < f_min)
f_min = f;
}
if (f_min < MIN_FONT_SCALE)
f_min = MIN_FONT_SCALE;
pango_matrix_translate(&m, x, y);
pango_matrix_rotate(&m, angle);
pango_matrix_translate(&m,
-xalign*f_min*width/PANGO_SCALE,
(yalign-1)*f_min*height/PANGO_SCALE);
pango_matrix_scale(&m, f_min, f_min);
pango_context_set_matrix(context, &m);
pango_layout_context_changed(layout);
pango_renderer_draw_layout(renderer, layout, 0, 0);
/* clean up renderer */
gdk_pango_renderer_set_drawable(GDK_PANGO_RENDERER(renderer), NULL);
gdk_pango_renderer_set_gc(GDK_PANGO_RENDERER(renderer), NULL);
/* free objects */
g_object_unref(layout);
g_object_unref(context);
}
示例9: gtk_shruler_draw_ticks
//.........这里部分代码省略.........
break;
if (scale == G_N_ELEMENTS (ruler_metric.ruler_scale))
scale = G_N_ELEMENTS (ruler_metric.ruler_scale) - 1;
unit = gtk_shruler_get_unit (ruler);
/* drawing starts here */
length = 0;
for (i = G_N_ELEMENTS (ruler_metric.subdivide) - 1; i >= 0; i--)
{
gdouble subd_incr;
/* hack to get proper subdivisions at full pixels */
if (unit == CM_UNIT_PIXEL && scale == 1 && i == 1)
subd_incr = 1.0;
else
subd_incr = ((gdouble) ruler_metric.ruler_scale[scale] /
(gdouble) ruler_metric.subdivide[i]);
if (subd_incr * fabs (increment) <= MINIMUM_INCR)
continue;
/* don't subdivide pixels */
if (unit == CM_UNIT_PIXEL && subd_incr < 1.0)
continue;
if (lower < upper)
{
start = floor (lower / subd_incr) * subd_incr;
end = ceil (upper / subd_incr) * subd_incr;
}
else
{
start = floor (upper / subd_incr) * subd_incr;
end = ceil (lower / subd_incr) * subd_incr;
}
for (cur = start; cur <= end; cur += subd_incr)
{
if (((int)cur) % 10 == 0)
length = height * 2 / 3;
else if (((int)cur) % 5 == 0)
length = height / 3;
else
length = height / 4;
pos = ROUND ((cur - lower) * increment);
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
{
cairo_rectangle (cr,
pos, height + ythickness - length,
1, length);
}
else
{
cairo_rectangle (cr,
height + xthickness - length, pos,
length, 1);
}
/* draw label */
if (i == 0 && ((int)cur) % 10 == 0)
{
g_snprintf (unit_str, sizeof (unit_str), "%d", (int) cur);
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
{
pango_layout_set_text (layout, unit_str, -1);
pango_layout_get_extents (layout, &logical_rect, NULL);
cairo_move_to (cr,
pos + 2,
ythickness + PANGO_PIXELS (logical_rect.y - digit_offset));
pango_cairo_show_layout (cr, layout);
}
else
{
gint j;
for (j = 0; j < (int) strlen (unit_str); j++)
{
pango_layout_set_text (layout, unit_str + j, 1);
pango_layout_get_extents (layout, NULL, &logical_rect);
cairo_move_to (cr,
xthickness + 1,
pos + digit_height * j + 2 + PANGO_PIXELS (logical_rect.y - digit_offset));
pango_cairo_show_layout (cr, layout);
}
}
}
}
}
cairo_fill (cr);
out:
cairo_destroy (cr);
}
示例10: vik_viewport_draw_scale
//.........这里部分代码省略.........
PangoLayout *pl;
gchar s[128];
vik_viewport_screen_to_coord ( vvp, 0, vvp->height, &left );
vik_viewport_screen_to_coord ( vvp, vvp->width/SCSIZE, vvp->height, &right );
vik_units_distance_t dist_units = a_vik_get_units_distance ();
switch (dist_units) {
case VIK_UNITS_DISTANCE_KILOMETRES:
base = vik_coord_diff ( &left, &right ); // in meters
break;
case VIK_UNITS_DISTANCE_MILES:
// in 0.1 miles (copes better when zoomed in as 1 mile can be too big)
base = VIK_METERS_TO_MILES(vik_coord_diff ( &left, &right )) * 10.0;
break;
default:
base = 1; // Keep the compiler happy
g_critical("Houston, we've had a problem. distance=%d", dist_units);
}
ratio = (vvp->width/SCSIZE)/base;
unit = 1;
diff = fabs(base-unit);
old_unit = unit;
old_diff = diff;
odd = 1;
while (diff <= old_diff) {
old_unit = unit;
old_diff = diff;
unit = unit * (odd%2 ? 5 : 2);
diff = fabs(base-unit);
odd++;
}
unit = old_unit;
len = unit * ratio;
/* white background */
vik_viewport_draw_line(vvp, vvp->scale_bg_gc,
PAD, vvp->height-PAD, PAD + len, vvp->height-PAD);
vik_viewport_draw_line(vvp, vvp->scale_bg_gc,
PAD, vvp->height-PAD, PAD, vvp->height-PAD-HEIGHT);
vik_viewport_draw_line(vvp, vvp->scale_bg_gc,
PAD + len, vvp->height-PAD, PAD + len, vvp->height-PAD-HEIGHT);
/* black scale */
vik_viewport_draw_line(vvp, gtk_widget_get_style(GTK_WIDGET(&vvp->drawing_area))->black_gc,
PAD, vvp->height-PAD, PAD + len, vvp->height-PAD);
vik_viewport_draw_line(vvp, gtk_widget_get_style(GTK_WIDGET(&vvp->drawing_area))->black_gc,
PAD, vvp->height-PAD, PAD, vvp->height-PAD-HEIGHT);
vik_viewport_draw_line(vvp, gtk_widget_get_style(GTK_WIDGET(&vvp->drawing_area))->black_gc,
PAD + len, vvp->height-PAD, PAD + len, vvp->height-PAD-HEIGHT);
if (odd%2) {
int i;
for (i=1; i<5; i++) {
vik_viewport_draw_line(vvp, vvp->scale_bg_gc,
PAD+i*len/5, vvp->height-PAD, PAD+i*len/5, vvp->height-PAD-((i==5)?(2*HEIGHT/3):(HEIGHT/2)));
vik_viewport_draw_line(vvp, gtk_widget_get_style(GTK_WIDGET(&vvp->drawing_area))->black_gc,
PAD+i*len/5, vvp->height-PAD, PAD+i*len/5, vvp->height-PAD-((i==5)?(2*HEIGHT/3):(HEIGHT/2)));
}
} else {
int i;
for (i=1; i<10; i++) {
vik_viewport_draw_line(vvp, vvp->scale_bg_gc,
PAD+i*len/10, vvp->height-PAD, PAD+i*len/10, vvp->height-PAD-((i==5)?(2*HEIGHT/3):(HEIGHT/2)));
vik_viewport_draw_line(vvp, gtk_widget_get_style(GTK_WIDGET(&vvp->drawing_area))->black_gc,
PAD+i*len/10, vvp->height-PAD, PAD+i*len/10, vvp->height-PAD-((i==5)?(2*HEIGHT/3):(HEIGHT/2)));
}
}
pl = gtk_widget_create_pango_layout (GTK_WIDGET(&vvp->drawing_area), NULL);
pango_layout_set_font_description (pl, gtk_widget_get_style(GTK_WIDGET(&vvp->drawing_area))->font_desc);
switch (dist_units) {
case VIK_UNITS_DISTANCE_KILOMETRES:
if (unit >= 1000) {
sprintf(s, "%d km", (int)unit/1000);
} else {
sprintf(s, "%d m", (int)unit);
}
break;
case VIK_UNITS_DISTANCE_MILES:
// Handle units in 0.1 miles
if (unit < 10.0) {
sprintf(s, "%0.1f miles", unit/10.0);
}
else if ((int)unit == 10.0) {
sprintf(s, "1 mile");
}
else {
sprintf(s, "%d miles", (int)(unit/10.0));
}
break;
default:
g_critical("Houston, we've had a problem. distance=%d", dist_units);
}
pango_layout_set_text(pl, s, -1);
vik_viewport_draw_layout(vvp, gtk_widget_get_style(GTK_WIDGET(&vvp->drawing_area))->black_gc,
PAD + len + PAD, vvp->height - PAD - 10, pl);
g_object_unref(pl);
pl = NULL;
}
}
示例11: _paint_lyrics
static void
_paint_lyrics (OlScrollWindow *scroll, cairo_t *cr)
{
ol_assert (OL_IS_SCROLL_WINDOW (scroll));
GtkWidget *widget = GTK_WIDGET (scroll);
ol_assert (GTK_WIDGET_REALIZED (widget));
OlScrollWindowPrivate *priv = OL_SCROLL_WINDOW_GET_PRIVATE (scroll);
int line_height = ol_scroll_window_get_font_height (scroll) + priv->line_margin;
int count = ol_scroll_window_compute_line_count (scroll);
gint width, height;
gdk_drawable_get_size (gtk_widget_get_window (GTK_WIDGET (scroll)),
&width, &height);
/* set the font */
PangoLayout *layout = _get_pango (scroll, cr);
/* paint the lyrics*/
cairo_save (cr);
cairo_new_path (cr);
cairo_rectangle (cr,
priv->padding_x, 0,
width - priv->padding_x * 2,
height - priv->padding_y * 2);
cairo_close_path (cr);
cairo_clip (cr);
int i;
gint current_lyric_id;
gint lrc_y;
_calc_paint_pos (scroll,
¤t_lyric_id,
&lrc_y);
int begin = current_lyric_id - count / 2;
int end = current_lyric_id + count / 2 + 1;
int ypos = height / 2 - lrc_y - (count / 2 + 1) * line_height;
cairo_set_source_rgb(cr,
priv->inactive_color.r,
priv->inactive_color.g,
priv->inactive_color.b);
if (scroll->whole_lyrics != NULL) {
for (i = begin; i < end; i++) {
ypos += line_height;
if (i < 0) continue;
if (i >= scroll->whole_lyrics->len)
break;
pango_layout_set_text (layout,
g_ptr_array_index (scroll->whole_lyrics, i),
-1);
cairo_save (cr);
double ratio = _get_active_color_ratio (scroll, i);
double alpha = 1.0;
if (ypos < line_height / 2.0 + priv->padding_y)
alpha = 1.0 - (line_height / 2.0 + priv->padding_y - ypos) * 1.0 / line_height * 2;
else if (ypos > height - line_height * 1.5 - priv->padding_y)
alpha = (height - line_height - priv->padding_y - ypos) * 1.0 / line_height * 2;
if (alpha < 0.0) alpha = 0.0;
cairo_set_source_rgba (cr,
priv->active_color.r * ratio +
priv->inactive_color.r * (1 - ratio),
priv->active_color.g * ratio +
priv->inactive_color.g * (1 - ratio),
priv->active_color.b * ratio +
priv->inactive_color.b * (1 - ratio),
alpha);
cairo_move_to (cr, priv->padding_x, ypos);
pango_cairo_update_layout (cr, layout);
pango_cairo_show_layout (cr, layout);
cairo_restore (cr);
}
}
g_object_unref (layout);
cairo_reset_clip (cr);
cairo_restore (cr);
}
示例12: gdl_dock_item_grip_size_allocate
static void
gdl_dock_item_grip_size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
{
GdlDockItemGrip *grip;
GtkContainer *container;
GtkRequisition button_requisition = { 0, };
GtkAllocation child_allocation;
g_return_if_fail (GDL_IS_DOCK_ITEM_GRIP (widget));
g_return_if_fail (allocation != NULL);
grip = GDL_DOCK_ITEM_GRIP (widget);
container = GTK_CONTAINER (widget);
GTK_WIDGET_CLASS (parent_class)->size_allocate (widget, allocation);
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
child_allocation.x = allocation->x + container->border_width + ALIGN_BORDER;
else
child_allocation.x = allocation->x + allocation->width - container->border_width;
child_allocation.y = allocation->y + container->border_width;
gtk_widget_size_request (grip->_priv->close_button, &button_requisition);
if (gtk_widget_get_direction (widget) != GTK_TEXT_DIR_RTL)
child_allocation.x -= button_requisition.width;
child_allocation.width = button_requisition.width;
child_allocation.height = button_requisition.height;
gtk_widget_size_allocate (grip->_priv->close_button, &child_allocation);
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
child_allocation.x += button_requisition.width;
gtk_widget_size_request (grip->_priv->iconify_button, &button_requisition);
if (gtk_widget_get_direction (widget) != GTK_TEXT_DIR_RTL)
child_allocation.x -= button_requisition.width;
child_allocation.width = button_requisition.width;
child_allocation.height = button_requisition.height;
gtk_widget_size_allocate (grip->_priv->iconify_button, &child_allocation);
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
child_allocation.x += button_requisition.width;
if (grip->title_window) {
GdkRectangle area;
/* set layout text */
ensure_title_and_icon_pixbuf (grip);
pango_layout_set_text (grip->_priv->title_layout, grip->_priv->title, -1);
gdl_dock_item_grip_get_title_area (grip, &area);
gdk_window_move_resize (grip->title_window,
area.x, area.y, area.width, area.height);
if (grip->_priv->icon_pixbuf)
area.width -= gdk_pixbuf_get_width (grip->_priv->icon_pixbuf) + 1;
/* ellipsize title if it doesn't fit the title area */
ellipsize_layout (grip->_priv->title_layout, area.width);
}
}
示例13: gimp_tag_popup_layout_tags
static gint
gimp_tag_popup_layout_tags (GimpTagPopup *popup,
gint width)
{
PangoFontMetrics *font_metrics;
gint x;
gint y;
gint height = 0;
gint i;
gint line_height;
gint space_width;
x = GIMP_TAG_POPUP_MARGIN;
y = GIMP_TAG_POPUP_MARGIN;
font_metrics = pango_context_get_metrics (popup->context,
pango_context_get_font_description (popup->context),
NULL);
line_height = PANGO_PIXELS ((pango_font_metrics_get_ascent (font_metrics) +
pango_font_metrics_get_descent (font_metrics)));
space_width = PANGO_PIXELS (pango_font_metrics_get_approximate_char_width (font_metrics));
pango_font_metrics_unref (font_metrics);
for (i = 0; i < popup->tag_count; i++)
{
PopupTagData *tag_data = &popup->tag_data[i];
gint w, h;
pango_layout_set_text (popup->layout,
gimp_tag_get_name (tag_data->tag), -1);
pango_layout_get_pixel_size (popup->layout, &w, &h);
tag_data->bounds.width = w + 2 * GIMP_TAG_POPUP_PADDING;
tag_data->bounds.height = h + 2 * GIMP_TAG_POPUP_PADDING;
if (x + space_width + tag_data->bounds.width +
GIMP_TAG_POPUP_MARGIN - 1 > width)
{
x = GIMP_TAG_POPUP_MARGIN;
y += line_height + 2 * GIMP_TAG_POPUP_PADDING + GIMP_TAG_POPUP_LINE_SPACING;
}
tag_data->bounds.x = x;
tag_data->bounds.y = y;
x += tag_data->bounds.width + space_width;
}
if (gtk_widget_get_direction (GTK_WIDGET (popup)) == GTK_TEXT_DIR_RTL)
{
for (i = 0; i < popup->tag_count; i++)
{
PopupTagData *tag_data = &popup->tag_data[i];
tag_data->bounds.x = (width -
tag_data->bounds.x -
tag_data->bounds.width);
}
}
height = y + line_height + GIMP_TAG_POPUP_MARGIN;
return height;
}
示例14: pango_textlayout
//.........这里部分代码省略.........
g_free(tfont);
}
*fontpath = buf;
}
}
#ifdef ENABLE_PANGO_MARKUP
if ((span->font) && (flags = span->font->flags)) {
unsigned char buf[BUFSIZ];
agxbuf xb;
agxbinit(&xb, BUFSIZ, buf);
agxbput(&xb,"<span");
if (flags & HTML_BF)
agxbput(&xb," weight=\"bold\"");
if (flags & HTML_IF)
agxbput(&xb," style=\"italic\"");
if (flags & HTML_UL)
agxbput(&xb," underline=\"single\"");
if (flags & HTML_S)
agxbput(&xb," strikethrough=\"true\"");
agxbput (&xb,">");
if (flags & HTML_SUP)
agxbput(&xb,"<sup>");
if (flags & HTML_SUB)
agxbput(&xb,"<sub>");
agxbput (&xb,xml_string0(span->str, TRUE));
if (flags & HTML_SUB)
agxbput(&xb,"</sub>");
if (flags & HTML_SUP)
agxbput(&xb,"</sup>");
agxbput (&xb,"</span>");
if (!pango_parse_markup (agxbuse(&xb), -1, 0, &attrs, &text, NULL, &error)) {
fprintf (stderr, "Error - pango_parse_markup: %s\n", error->message);
text = span->str;
attrs = NULL;
}
agxbfree (&xb);
}
else {
text = span->str;
attrs = NULL;
}
#else
text = span->str;
#endif
layout = pango_layout_new (context);
span->layout = (void *)layout; /* layout free with textspan - see labels.c */
span->free_layout = pango_free_layout; /* function for freeing pango layout */
pango_layout_set_text (layout, text, -1);
pango_layout_set_font_description (layout, desc);
#ifdef ENABLE_PANGO_MARKUP
if (attrs)
pango_layout_set_attributes (layout, attrs);
#endif
pango_layout_get_extents (layout, NULL, &logical_rect);
/* if pango doesn't like the font then it sets width=0 but height = garbage */
if (logical_rect.width == 0)
logical_rect.height = 0;
textlayout_scale = POINTS_PER_INCH / (FONT_DPI * PANGO_SCALE);
span->size.x = (int)(logical_rect.width * textlayout_scale + 1); /* round up so that width/height are never too small */
span->size.y = (int)(logical_rect.height * textlayout_scale + 1);
/* FIXME -- Horrible kluge !!! */
/* For now we are using pango for single line blocks only.
* The logical_rect.height seems to be too high from the font metrics on some platforms.
* Use an assumed height based on the point size.
*/
span->size.y = (int)(span->font->size * 1.1 + .5);
/* The y offset from baseline to 0,0 of the bitmap representation */
#if !defined(WIN32) && defined PANGO_VERSION_MAJOR && (PANGO_VERSION_MAJOR >= 1)
span->yoffset_layout = pango_layout_get_baseline (layout) * textlayout_scale;
#else
{
/* do it the hard way on rhel5/centos5 */
PangoLayoutIter *iter = pango_layout_get_iter (layout);
span->yoffset_layout = pango_layout_iter_get_baseline (iter) * textlayout_scale;
}
#endif
/* The distance below midline for y centering of text strings */
span->yoffset_centerline = 0.2 * span->font->size;
if (logical_rect.width == 0)
return FALSE;
return TRUE;
}
示例15: histo_expose_vertical_ruler
/* Redraw the vertical ruler */
static gboolean
histo_expose_vertical_ruler( GtkWidget *widget, GdkEventExpose *event, gpointer user_data )
{
histoDrawing_t *drawing = (histoDrawing_t*)user_data;
HistoControlFlowData *histo_cfv = drawing->histo_control_flow_data;
gchar text[255];
PangoContext *context;
PangoLayout *layout;
PangoFontDescription *FontDesc;
PangoRectangle ink_rect;
gint global_height=0;
GdkColor foreground = { 0, 0, 0, 0 };
GdkColor background = { 0, 0xffff, 0xffff, 0xffff };
GdkColor red ={ 0, 0xFFFF, 0x1E00, 0x1000 };
//GdkColor magneta ={ 0, 0x8900, 0x0000, 0x8400 };
g_debug("vertical ruler expose event");
gdk_draw_rectangle (drawing->vertical_ruler->window,
drawing->vertical_ruler->style->white_gc,
TRUE,
event->area.x, event->area.y,
event->area.width,
event->area.height);
gdk_draw_line (drawing->vertical_ruler->window,
drawing->ruler_gc_butt,
padding_width-1/*event->area.width-1*/,event->area.y,
padding_width-1/*event->area.width-1*/,event->area.y + event->area.height);
snprintf(text, 255, "%.1f", (float)histo_cfv->max_height);
layout = gtk_widget_create_pango_layout(drawing->drawing_area, NULL);
context = pango_layout_get_context(layout);
FontDesc = pango_context_get_font_description(context);
pango_font_description_set_size(FontDesc, 6*PANGO_SCALE);
pango_layout_context_changed(layout);
pango_layout_set_text(layout, text, -1);
pango_layout_get_pixel_extents(layout, &ink_rect, NULL);
global_height += ink_rect.height;
gdk_draw_layout_with_colors(drawing->vertical_ruler->window,
drawing->ruler_gc_butt,
1,
1,
layout, &foreground, &background);
gdk_draw_line (drawing->vertical_ruler->window,
drawing->ruler_gc_round,
drawing->vertical_ruler-> allocation.width-1, 1,
drawing->vertical_ruler-> allocation.width-7, 1);
snprintf(text, 255, "%d", 0);
pango_layout_set_text(layout, text, -1);
pango_layout_get_pixel_extents(layout, &ink_rect, NULL);
global_height += ink_rect.height;
if(global_height <= drawing->vertical_ruler->allocation.height)
{
gdk_draw_layout_with_colors(drawing->vertical_ruler->window,
drawing->ruler_gc_butt,
1,
drawing->vertical_ruler->allocation.height - ink_rect.height-2,
layout, &foreground, &background);
gdk_draw_line (drawing->vertical_ruler->window,
drawing->ruler_gc_butt,
drawing->vertical_ruler-> allocation.width-1,
drawing->vertical_ruler->allocation.height-1,
drawing->vertical_ruler-> allocation.width-7,
drawing->vertical_ruler->allocation.height-1);
}
snprintf(text, 255, "%.1f",(float) histo_cfv->max_height/2.0);
pango_layout_set_text(layout, text, -1);
pango_layout_get_pixel_extents(layout, &ink_rect, NULL);
global_height += ink_rect.height;
if(global_height <= drawing->vertical_ruler->allocation.height)
{
gdk_draw_layout_with_colors(drawing->vertical_ruler->window,
drawing->ruler_gc_butt,
1,
(drawing->vertical_ruler->allocation.height - ink_rect.height)/2,
layout, &foreground, &background);
gdk_draw_line (drawing->vertical_ruler->window,
drawing->ruler_gc_butt,
drawing->vertical_ruler-> allocation.width-1,
drawing->vertical_ruler-> allocation.height/2,
drawing->vertical_ruler-> allocation.width-7,
drawing->vertical_ruler->allocation.height/2);
//.........这里部分代码省略.........