Subject: POW -- Show Paragraphs
From: Paul Rohr (paul@abisource.com)
Date: Fri Dec 24 1999 - 14:33:42 CST
We try to vary the mix of POWs so that hardcore GUI hackers and people who 
hate compilers can each find some way to help out.  Since the hackers are 
currently making great headway in knocking off their POWs (hint, hint!), 
this week we have another coding project. 
the goal
--------
Implement the "View / Show Paragraphs" menu item.  This feature, which is 
sometimes also known as "Show Invisibles" or "Show All", optionally draws 
special indicators for some or all of the following:
  space,
  tab,
  forced line/page/column/section breaks,
  paragraph breaks,
  page/column boundaries or crop marks,
  etc. 
Since these non-printing characters usually just create various amounts of 
white space, this feature allows users to identify what and where they are 
so that they can be edited.
scope
-----
This project is an excellent way to start learning how documents and views 
interact. 
If you take a look at the existing run-drawing code, it should be reasonably 
obvious what's going on.  We draw the background (potentially selected), the 
spell-check squiggles (if any), and the text itself.  
  abi/src/text/fmt/xp/fp_Run.cpp
Right now, we don't draw tabs or breaks at all, but there is a special run 
type for each, so optionally implementing drawing logic there should be 
easy.  (You'll want to use a different gray than we use for selections, and 
either do line-drawing using 2D GR_Graphics calls, or just use the 
appropriate special character from the current font.)
Likewise, spaces are easy to detect inside text runs, so adding invisibles 
there shouldn't be bad either.  (This is likely to involve marching through 
the charwidths array to figure out where to place those little gray dots on 
their own separate drawing pass.)
The one thing you'll probably need to add is a special run type for 
paragraph breaks (the funky backwards P).  Save this one for later, because 
it's more involved.  Essentially, we want those breaks to be selectable 
whether they're drawn or not, but this will involve updating the document's 
notion of PT_DocPosition notion a bit, since paragraph breaks currently have 
a "width" of zero, and this will need to change to 1, instead.  
hints
-----
To implement this feature, you'll need to touch three different areas of the 
code:
1.  As with the View Rulers POW, there needs to be a new persistent 
preferences item which is honored on a per-view basis.  This time, instead 
of storing the state inside each frame, it'll get stored inside each view.   
2.  Most of the work happens down in the run-drawing code.  Each run 
subclass has it's own _draw() method, and many of these should be updated to 
optionally draw something extra if the view-level flag is set.  For example:
  - slugs for spaces
  - arrows and lines (fp_TabRun, fp_LineBreak, fp_ColBreak, fp_PageBreak)
  - funky P symbol (after each paragraph)
Of these, only the P will need a new run type, so that it'll be selectable 
in the right font, etc. 
3.  As suggested above, you will need to dive into the piece table briefly 
so that the new P symbol has its own DocPosition.  Get the other steps 
working smoothly before tackling this one, because it's likely to take more 
work to get editing working properly again.  
As a special bonus, however, doing this last step right should finally 
eliminate a whole category of lingering bugs in the formatter.  (Right now, 
it's occasionally possible for a block to have no runs at all, which 
triggers crashes at various spots throughout the code.  After this change, 
even blocks with no content should still have this one run which is used to 
optionally draw the P symbol.)
extra credit
------------
While you're deep in the drawing code using that new snazzy gray, you might 
also want to consider optionally drawing margins and/or crop marks in that 
color for various layout containers (page, column, header, footer, etc.).  
I've seen features like this in other WPs, and the effect can be nice if 
it's subtle enough.  
Enjoy!
Paul
PS:  For more background on the whole POW / ZAP / SHAZAM concept, see the 
following introduction:
  http://www.abisource.com/mailinglists/abiword-dev/99/September/0097.html
This archive was generated by hypermail 2b25 : Fri Dec 24 1999 - 14:28:37 CST