Re: glyph item split

2011-05-27 Thread august
 On 05/27/11 12:55, august wrote:
  The split_index is said to be: byte index of position to split item,
  relative to the start of the item
  
  Can you explain what this means in more detail?   What is the start
  of the item?  How do I get that?
 
 The item corresponds to a chunk of the text, say, from start to end.  start is
 what you want.  It's recorded in item-offset actually.
 
 So this should work, if everything else is correct:
 
   Pango.GlyphItem vorn =  glyphitem.split ( text,
 glyphitem.glyphs.log_clusters[gi.end_index] - glyphitem.item.offset)
 

thanks for the reply.  Can you tell me what happens to the glyphitem and
the gi when I make that split?

The following code goes through a text line by line, run by run, and
glyphitem by glyphitem.  It then tries to split off the first cluster
and continue in the loop.   

http://pastebin.com/Ewi3c1UD

Line 79 is where the split happens.   I'm sure this changes the
glyphitemiter somehow, but don't know how to do it so that I can
continue inside that loop.   Any suggestions?


 You may want to check the source code in situations like this.

I couldn't find anything that is doing something similar to what I want.

any help would be appreciated.

many thanks -august.
___
gtk-i18n-list mailing list
gtk-i18n-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-i18n-list


Re: Drawing glyph bounding box on rendered text?

2011-05-09 Thread august

Behdad posted a python application that draws lines around clusters,
runs, and lines:

http://mail.gnome.org/archives/gtk-i18n-list/2011-April/msg7.html

Maybe you haven't seen that yet and can help.

best -august.

 Hi all,
 
 I'm trying to accurately draw a rectangle around each glyph (not
 character) in rendered text. I'm very close but things aren't quite
 lining up correctly. I've attached an image showing this, but if the
 mailing list filters it, you can also see it here:
 http://www.phonething.com/test.png
 Green box shows line extents, red boxes should show bounding box for
 each glyph.
 
 As you can see, widths and X starting positions of the boxes are off
 slightly. (So is height, but I suppose I could lock that to the
 bottom of the line extents?)
 
 Relevant code that drew that is:
 
 double pango_to_ink = (1.0 / ((double) PANGO_SCALE)); // utility
 
 [ create surface, context, layout, then do pango_layout_set_text() ]
 
 [ for each line in layout use pango_layout_iter_get_line() : ]
 
 pango_layout_iter_get_line_extents(pIter, line_r, NULL);
 pangolineX = pango_to_ink * ((double) line_r.x);  // start position
 of this line of the layout
 pangolineY = pango_to_ink * ((double) line_r.y);
 
 [ get each run in current line: ]
 
 for (i = 0; i  pRun-glyphs-num_glyphs; i++) // loop through
 glyphs in current run
  {
 
  pango_font_get_glyph_extents(font, glyphID, NULL, glyphbox);
 // Just to get glyph height as it's not in the geometry
 
  glyphX = pangolineX + pango_to_ink * ((double)
 pRun-glyphs-glyphs[i].geometry.x_offset);
  glyphY = pangolineY + pango_to_ink * ((double)
 pRun-glyphs-glyphs[i].geometry.y_offset);
  glyphW = pango_to_ink * ((double)
 pRun-glyphs-glyphs[i].geometry.width);
  glyphH = pango_to_ink * ((double) glyphbox.height);
 
   cairo_rectangle(context, glyphX, glyphY, glyphW, glyphH - glyphY);
   cairo_stroke(context);
 
   }
 
 
 Where am I going wrong in getting the glyph bounding boxes
 accurately? (this needs to also work for Indic, Hebrew, Arabic,
 Chinese and so on)
 It doesn't matter if the box has empty space, i.e. incorporates the
 distance between glyphs, though knowing the actual glyph bounding
 box AND the space separating it from the next glyph
 would be ideal.
 
 Thanks and regards,
 Alex
 


 ___
 gtk-i18n-list mailing list
 gtk-i18n-list@gnome.org
 http://mail.gnome.org/mailman/listinfo/gtk-i18n-list


-- 
---
http://aug.ment.org

___
gtk-i18n-list mailing list
gtk-i18n-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-i18n-list


Re: Drawing glyph bounding box on rendered text?

2011-05-09 Thread august

Whoops sorry.  Fired that off without noticing he sent that code to you
originally.

I go back into lurker mode.  Appologies.


 Behdad posted a python application that draws lines around clusters,
 runs, and lines:
 
   http://mail.gnome.org/archives/gtk-i18n-list/2011-April/msg7.html
 
 Maybe you haven't seen that yet and can help.
 
 best -august.

___
gtk-i18n-list mailing list
gtk-i18n-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-i18n-list


Re: pango_cairo_show_glyph_item_range ?

2010-11-09 Thread august
 On 11/01/10 20:22, august wrote:
  
  
  Would it be possible to have a pango_cairo_show_glyph_item_range
  function that would take a start and end value?
  
  
  This would be very useful.
 
 I agree.  Filed a bug:
 
   https://bugzilla.gnome.org/show_bug.cgi?id=633926
 
 Feel free to submit a patch.  Or I'll get to it next time I'm adding Pango 
 API.
 
 behdad


Have you started on this already?

If not, I will look into it now.   IF you can, please advise me on
where to start.

-august.
___
gtk-i18n-list mailing list
gtk-i18n-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-i18n-list


Re: go from PangoGlyphItemIter to an index into a PangoLogAttr ?

2010-10-25 Thread august
 My main problem, which I have partially solved, is how to iterate
 through a layout (line by line, run by run, and then glyphitem by gitem)
 and keep the log_attributes I get from the layout in sync with my
 iteration.
 
 I noticed that when I change the set_width() of my layout, the number of
 characters in the layout/log_attr array changes.  Why is that? 
 I was surprised when I found this out...but still don't know how it
 changes the character count.  Is there now an extra char in my log_attr
 for every line or run or some mixture?  I ran some tests where I
 increment my index into the log_attr array for each line or run, but did
 not see any regularity.   My solution for now is to not set_width on the
 layout.
 
 I've also tried to get an index into the log_attr array using
 log_attr[glyphitemiter.glyph_item.glyphs.log_clusters[i]] 
 
 where i is incremented for every call to next_cluster()
 
 however, this does not work ( at least not when you set_width on the
 layout).

I think I can narrow my question down a bit.  I the pango docs for
pango_layout_get_log_attr() it says:

n_attrs: location to store the number of the attributes in the array.
(The stored value will be one more than the total number of characters
 in the layout, since there need to be attributes corresponding to both
 the position before the first character and the position after the last
 character.) 

So, when I do this, I know the number of characters in the layout.  I
can also count the number of characters in the source text fed into the
layout.  However, what I don't know is the correlation between the  #
characters in the layout and the # characters in the source text.  They
are not the same.

-august.


___
gtk-i18n-list mailing list
gtk-i18n-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-i18n-list


go from PangoGlyphItemIter to an index into a PangoLogAttr ?

2010-10-24 Thread august

Hi,

Could someone tell me how to go from a PangoGlyphItemIter to and
index into a PangoLogAttr that comes from pango_layout_get_log_attrs?

My code first gets a layout and sets the text.  Then, I do
get_log_attrs on the text.   

The pango docs say that the get_log_attrs function Retrieves an
array of logical attributes for each character in the layout. 
What does character mean in that sentence?

Then, after getting the log_attrs, I get a layout iter and step
through the text by line, run, and then by
glyphitemiter.next_cluster.

Is there no direct way to index back into my log_attrs[] array from
the glyphitemiter?


thanks for any tips.  I've been staring at this for so long now.

best -august.
___
gtk-i18n-list mailing list
gtk-i18n-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-i18n-list


some questions about runs, glyphs, chars, bytes, clusters

2010-07-12 Thread august

Hi, 

I am making some tests to try and learn more about Pango.  Right now
I am trying to step through a layout line by line, run by run, and
then word by word.

I was hoping someone might be able to help me out with some
questions.

Here is what I am doing.

static char * text = {  flower power };
// I get the layout
PangoLayout *layout;
layout = pango_layout_new(pango_context);
pango_layout_set_text(layout, text, -1);
pango_layout_context_changed(layout);


// I then get iterators for lines and stuff
PangoLayoutIter* p_iter = 0;
p_iter = pango_layout_get_iter(layout);
PangoLayoutLine* p_line = pango_layout_iter_get_line(p_iter);
GSList* current_run = p_line-runs;
PangoLayoutRun* p_run=(PangoLayoutRun*)current_run-data;

// I then try to get attribute info for this run
PangoLogAttr * logattrs = (PangoLogAttr *) malloc( 
(p_run-item-num_chars +1 ) * sizeof(PangoLogAttr) );
pango_break(text+ p_run-item-offset, p_run-item-length,
  p_run-item-analysis, logattrs,
  p_run-item-num_chars+1);

// Am I doing this wrong?
// This then gives me a PangoLogAttr for every byte char in the text
// string, correct?  But, since there could be more than one char for 
// a glyph, where do I check for word_end?

// Can someone tell me here what num_chars refers to in the item?
// is that character bytes? 
// is that not always the same as item-length?
// Also, what is the difference between a byte, a character, a glyph,
// and a cluster in Pango?  In the docs and naming of variables, is
// it consistently named?

// Then, I try to step through the run by glyph and logattr to see
// where words start and end
// Is this correct? 

   for(int i=0;ip_run-glyphs-num_glyphs;i++) {
j=p_run-glyphs-log_clusters[i];
// I print out some info about the word start and end
printf(\t\tword_start:%d, , logattrs[j].is_word_start);
printf(word_end:%d \n, logattrs[j].is_word_end);
}


The funny thing that I notice heres is that the f and the l in
flower is considered one glyph.  Is that right?


Sorry if my questions are basic.  I can see how complex type layout
is now that I am getting my hands dirty.  Any help would be greatly
appreciated.

thank you -august.

___
gtk-i18n-list mailing list
gtk-i18n-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-i18n-list


glyphs

2010-07-07 Thread august

Hi,
I'm a newbie to pango low-level functions and am trying to learn how
to use pango_itemize, pango_break, and pango_shape properly. 

Given an item from pango_itemize, I do:


PangoGlyphString *glyphs = pango_glyph_string_new();
pango_glyph_string_set_size(glyphs, item-num_chars);
pango_shape(text+item-offset, item-length, item-analysis, glyphs);

printf(number of glyphs: %d \n, glyphs-num_glyphs);

for (int j=1;j glyphs-num_glyphs ;j++){
// crashes here
printf(#%d, guint32 glyph=%d\n, j, glyphs[j].glyphs-glyph );
}


What am I doing wrong? 


thanks -august.
___
gtk-i18n-list mailing list
gtk-i18n-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-i18n-list


Re: glyphs

2010-07-07 Thread august
 Hi,
   I'm a newbie to pango low-level functions and am trying to learn how
   to use pango_itemize, pango_break, and pango_shape properly. 
 
   Given an item from pango_itemize, I do:
 
 
   PangoGlyphString *glyphs = pango_glyph_string_new();
   pango_glyph_string_set_size(glyphs, item-num_chars);
   pango_shape(text+item-offset, item-length, item-analysis, glyphs);
 
   printf(number of glyphs: %d \n, glyphs-num_glyphs);
 
   for (int j=1;j glyphs-num_glyphs ;j++){
   // crashes here
   printf(#%d, guint32 glyph=%d\n, j, glyphs[j].glyphs-glyph );
   }
 
 
   What am I doing wrong? 
 

it figures that I have been staring at this for a few hours already and
notice my mistake right after I send for help to the list.

It should be:
printf(#%d, guint32 glyph=%d\n, j, glyphs-glyphs[j].glyph );


sorry for the noise.

But, if anyone has a link to some readable example code using
pango_itemize, pango_break, and pango_shape, I'd really appreciate it.
I cannot find anything online.


-august.
___
gtk-i18n-list mailing list
gtk-i18n-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-i18n-list


iterate through a layout by char or word?

2010-07-07 Thread august


Is there any way to iterate through a PangoyLayout by character or word?

Is there a way to iterate by word and then show it using cairo?



I can do something similar with pango_itemize, pango_break, and
pango_shape.   But, I can't seem to do anything with the resulting
PangoGlyphString  that I get.

I can do pango_cairo_show_glyph_string(), but I want to just show a word
or character.  Is there something like
pango_cairo_show_glyph_string_range()?


I can do pango_glyph_string_copy(), but cant do anything like strncpy
where I can just get a segment of that PangoGlyphString.  


Any tips would be greatly appreciated.


thanks -august.



___
gtk-i18n-list mailing list
gtk-i18n-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-i18n-list


memory leaks on pango examples

2009-08-06 Thread august

hi,

I'm trying to debug some of my code (which is based on the example
code provided by pango), and came across a bunch of memory leaks.
I'm still new to valgrind, so can anyone explain to me why there are
leaks with:

valgrind --leak-check=full ./cairosimple blah.png

where ./cairosimple is the example program provided in the pango
source dir.



thanks -august.
___
gtk-i18n-list mailing list
gtk-i18n-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-i18n-list


Re: pango layout in irregular (non-rectangular) bounding shape

2009-03-02 Thread august
 august,
 
  I
  can already render stuff to screen and bound a text segment by width
  and height
 
 I guess you tried PangoLayout and friends.
 
  how to render text within a non-rectangular bounding shape?
 
  Can someone point me in the right direction?
 
 If I were you, I'd be using PangoItem, PangoGlyphString, and friends.
 They are lower layer interface to pango, and you need to write more
 codes than using PangoLayout, but it gives you better control over
 layout.  (There may be some easier ways if you only needs fill texts
 ina non rectangular area, but I don't know.)
 
 The following outlines what you need to do:
 
 (1) Call pango_itemize() once for your text,
 (2) Call pango_break() for your entire text,
 (3) Call pango_shape() for each PangoItem you got,
 (4) Fold the text into lines, scanning the list of PangoItems, calling
 pango_glyph_string_get_width() for each PangoGlyphString you got,
 also breaking several PangoItem in a middle, referring to
 PangoLogAttr array you got (This will be the most complicated step),
 (5) Either call pango_reorder_items() for each folded line and somehow
 refrect the results to your list of PangoGlyphString (or does an
 equivalent processing manually as suggested by pango document...), and
 (6) Call pango_cairo_show_glyph_string() for each PangoGlyphString,
 moving the cairo current point appropriately.
 
 Hope this helps,
 Alissa

Alissa,

thanks so much for taking the time to outline all of this.  I am
still learning the pango api and this helps.

-august.
___
gtk-i18n-list mailing list
gtk-i18n-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-i18n-list


Re: pango layout in irregular (non-rectangular) bounding shape

2009-03-02 Thread august
 
In addition, I'd like to render text inside a polygon shape. 
 
 This is not possible yet.  Here is the bug tracking this issue:
 
   http://bugzilla.gnome.org/show_bug.cgi?id=435706


Behdad,

How far did you get with that?  I also see you were looking at
Nathan Hurst's code for inkscape.  I'd love to study some of 
that
code...but it seems like most of the links on that page are gone
now.  Is this something I could help implement?

-august.

___
gtk-i18n-list mailing list
gtk-i18n-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-i18n-list


GLib new user + Quarks and Hash Tables

2000-06-23 Thread David August


  I am currently working on a research compiler and simulator for computer
architecture (i.e. design your own novel hardware feature, compile for it,
simulate, measure benefit).  I have very recently become interested in GLib
and have thought of replacing parts my current home-grown library with it if
it makes sense to do so.  My first task was the replacement of our symbol
table.

The hash table/symbol table I currently use maps a string (or any type) to a
pointer (string-pointer) just like GLib's hash table.  However, there are
forms of the add and find functions which return a unique identifier (the
symbol) much like your quarks.  This unique identifier is used in other
higher level structures to quickly return either the string or the pointer.
It is also used for equality/inequality comparisons with other symbols.
This unique identifier (or symbol) is currently implemented as a pointer to
the hash table element, but this is hidden from the user with functions
implemented very simply as:  (pseudo code here)

get_pointer_from_symbol(symbol) {symbol-pointer}

and

get_string_from_symbol(symbol) {symbol-string}

Alternatively, the unique identifier could be an int (or quark) and these
function could return the results of an array lookup, etc.

As I tried to port my compiler's symbol table to GLib I ran into a small
concern.  Basically, I need to use quark to map a string to a unique int
(which I can use as a symbol and compare in the higher level structures) and
a hash table to map the unique int to the pointer.

The inefficiency with this in GLib is that it utilizes two hash tables.  In
addition to space concerns, two lookups are necessary to go from a string to
pointer.  My question is:

Is there a better way to do this in GLib?

If not:
Can we augment the hash table to return a unique symbol (polymorphic
quark-like item) for some versions of add, find etc?

These unique symbols are essentially polymorphic quarks which might be a
nice thing to offer anyway.   This change would also make the implementation
of string quarks simpler, faster, and more space efficient.   (Quarks would
basically be a hash table of strings-NULL.  The quark would be the
symbol/pointer to the hash table element.  The string would be accessible by
symbol by a single dereference.  The pointer to NULL would basically be
ignored.  No array necessary.)

Thank you in advance for your help.

David

--
Prof. David AugustDepartment of Computer Science
[EMAIL PROTECTED]   Princeton University
http://www.cs.princeton.edu/~august   (609) 258-2085


___
gtk-list mailing list
[EMAIL PROTECTED]
http://mail.gnome.org/mailman/listinfo/gtk-list