Re: regarding all the possible functions that can be assigned to PangoCairoShapeRendererFunc func



On Sun, Sep 9, 2012 at 1:21 AM, Behdad Esfahbod <behdad behdad org> wrote:
On 09/08/2012 10:21 AM, Parth Kanungo wrote:
> I think that it is the presence of these initialized functions that enables
> pangocairo to render different styles(italic/oblique), variants, weights(thin,
> normal, ultraheavy), stretch etc. and other attributes, which are impossible
> to render in pangoft2.

How are they impossible?

 
Hi Behdad,
They are impossible when I don't use WINDOWSFONTDIR in my fonts.conf. I add the path of an in-house font, which does not have bold and italic version (like say arial which has arial.ttf, ariali.ttf, arialbd.ttf).
 
 
Note that Pango doesn't really implement font variants.  Italic, bold, stretch
etc should work as far as fonts are available.  Italic and bold are
synthesized if not available, but not stretch or other properties.
 
Through my experiements, I found that when Italic and bold are not available (as a consequence of path change in fonts.conf),  they are not synthesized.
Only PANGO_UNDERLINE_ERROR and other PangoUnderlines work. Nothing else.
 
 
Maybe I have done something wrong here, you can help me figure out. I have used the following code:
(Also, attaching the same code in a file, if the above code appears unreadable on the email.)
Thanks.
 

/// #.... libraries exported for display function    //////
#include "pango.h"
#include "pangoft2.h"
#include <pango/pangofc-fontmap.h>
#include <pango/pangofc-font.h>
#include "pango-attributes.h"
#include<fontconfig.h>
#include<freetype.h>
 
int test1(void);
 
int test1()
{
 PangoLayout* layout;
 PangoFontMap* PFM;
 PangoContext* context;

 PFM = pango_ft2_font_map_new();          // new FontMap
 
 context = pango_font_map_create_context(PANGO_FONT_MAP(PFM));               /// Create Context using FontMap
 pango_context_set_base_gravity(context,PANGO_GRAVITY_EAST);                    ///there is no effect of even this.
 layout = pango_layout_new(context);                                                                       // Create Layout using Context

 PangoFontDescription *desc;      // this structure stores a description of the ideal font
 
 pango_layout_set_text(layout, "Hello World!", -1);
 PangoAttrList *list = pango_attr_list_new();
 PangoAttribute* attr1 = pango_attr_underline_new(PANGO_UNDERLINE_ERROR);
 pango_attr_list_insert(list, attr1);
 PangoAttribute* attr2 = pango_attr_weight_new(PANGO_WEIGHT_ULTRAHEAVY);
 pango_attr_list_insert(list, attr2);
 PangoAttribute* attr3 = pango_attr_style_new(PANGO_STYLE_OBLIQUE);
 pango_attr_list_insert(list, attr3);
 pango_layout_set_attributes(layout, list);
 pango_layout_context_changed(layout);

 desc = pango_font_description_from_string("Sans Bold 40");             // specify the font that would be ideal for your particular use
 pango_layout_set_font_description(layout, desc);                              // assign the previous font description to the layout
 pango_font_description_free(desc);                                                   // free the description
 
 int bitmap_width = 550, bitmap_height = 80;
 pango_ft2_font_map_set_resolution(PANGO_FT2_FONT_MAP(PFM),100, 100);  //Set Resolution  
 
 FT_Bitmap* bm;
 bm = g_slice_new(FT_Bitmap);     // new bitmap and set its various attributes
 bm->rows = bitmap_height;
 bm->width = bitmap_width;
 bm->pitch = bm->width;
 bm->num_grays = 256;       // num_grays
 bm->pixel_mode = FT_PIXEL_MODE_GRAY;
 bm->buffer = (unsigned char*)g_malloc(bm->pitch * bm->rows);
 memset(bm->buffer, 0x00, bm->pitch * bm->rows);   // sets all the data fields of an empty bitmap to zero
 
 pango_ft2_render_layout(bm,layout,0,0); 
 
 Display_on_screen_class::Clear();
 Display_on_screen_class::DrawGlyphImage(0,0, bitmap_width, bitmap_height, bm->buffer, 0xffffffff);
 Display_on_screen_class::Flush(960, 540);
 wchar_t* filename = (wchar_t*)L"image.bmp";
 Display_on_screen_class::SaveAsFile(filename);
 
 pango_attribute_destroy(attr1);
 pango_attribute_destroy(attr2);
 pango_attribute_destroy(attr3);
 return 0;  
}
 
 
 
--
PangoLeaner
/// #.... other initialization and libraries exported for display function    //////

#include "pango.h"
#include "pangoft2.h"
#include <pango/pangofc-fontmap.h>
#include <pango/pangofc-font.h>
#include "pango-attributes.h"

#include<fontconfig.h>
#include<freetype.h>

int test1(void);

int test1()
{
	PangoLayout* layout;
	PangoFontMap* PFM; 
	PangoContext* context;

	/////////// FONTMAP //////////////
	PFM = pango_ft2_font_map_new();										// new FontMap

	//////////CONTEXT////////////////
	context = pango_font_map_create_context(PANGO_FONT_MAP(PFM));		// Create Context using FontMap
	pango_context_set_base_gravity(context,PANGO_GRAVITY_EAST);	///can be changed to EAST/WEST to observe effects

	///////////LAYOUT//////////////
	layout = pango_layout_new(context);									// Create Layout using Context


	PangoFontDescription *desc;						// this structure stores a description of the style of font you'd most like
	pango_layout_set_text(layout, "Hello World!", -1);
	PangoAttrList *list = pango_attr_list_new();
	PangoAttribute* attr1 = pango_attr_underline_new(PANGO_UNDERLINE_ERROR);
	pango_attr_list_insert(list, attr1);
	PangoAttribute* attr2 = pango_attr_weight_new(PANGO_WEIGHT_ULTRAHEAVY);
	pango_attr_list_insert(list, attr2);
	PangoAttribute* attr3 = pango_attr_style_new(PANGO_STYLE_OBLIQUE);
	pango_attr_list_insert(list, attr3);

	pango_layout_set_attributes(layout, list);
	pango_layout_context_changed(layout);


	desc = pango_font_description_from_string("Sans Bold 40");		// specify the font that would be ideal for your particular use
	pango_layout_set_font_description(layout, desc);			// assign the previous font description to the layout
	pango_font_description_free(desc);					// free the description



	int bitmap_width = 550, bitmap_height = 80;
	pango_ft2_font_map_set_resolution(PANGO_FT2_FONT_MAP(PFM),100, 100);		//Set Resolution   

	FT_Bitmap* bm;
	bm = g_slice_new(FT_Bitmap);					// new bitmap and set its various attributes
	bm->rows = bitmap_height;
	bm->width = bitmap_width;
	bm->pitch = bm->width;
	bm->num_grays = 256;							// num_grays 
	bm->pixel_mode = FT_PIXEL_MODE_GRAY;
	bm->buffer = (unsigned char*)g_malloc(bm->pitch * bm->rows);
	memset(bm->buffer, 0x00, bm->pitch * bm->rows);   // sets all the data fields of an empty bitmap to zero

	pango_ft2_render_layout(bm,layout,0,0);  // empty bitmap and layout are passed along with the X position of the left of the layout & Y position of the top of the layout

	Display_on_screen_class::Clear();
	Display_on_screen_class::DrawGlyphImage(0,0, bitmap_width, bitmap_height, bm->buffer, 0xffffffff);
	Display_on_screen_class::Flush(960, 540);

	wchar_t* filename = (wchar_t*)L"image.bmp";
	Display_on_screen_class::SaveAsFile(filename);

	pango_attribute_destroy(attr1);
	pango_attribute_destroy(attr2);
	pango_attribute_destroy(attr3);
	return 0;   // success
}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]