Arg -- sorry to continue spamming the list.  Forgot the attachment on
that last message. :(

- Jamis

On Mon, 2002-04-29 at 11:37, Adam McDaniel wrote:
> On Mon, Apr 29, 2002 at 11:21:10AM -0600, Jamis Buck wrote:
> > Also, I found a bug in my word-wrap implementation: when the end of a
> > series of adjacent dashes is encountered, "lastSpaceIsVisible" needs to
> > be set to false (otherwise, "spaceCount" may be decremented
> > incorrectly).
> 
> You know whats funny, I dont have a PDB handy that implements line
> justification :) .. not too easy for me to test.
> 
> > I've attached a diff...hope I did it right.  It includes the change to
> > paragraph.c for the word wrap stuff, too.
> 
> Looks better, except it looks as though you diffed the hires branch off
> of the main trunk with your changes :) (hence removing hires.h from the
> top of paragraph.c) Just make sure that when you create the diff, you're
> using two exact copies of the code, except one has your changes.
> 
> What I do in the CVS is always have a plucker dir, then a plucker-orig
> dir. I make my changes in the plucker dir, run 'cvs update' in both to
> make sure everythings the latest.. then run
> 
> diff -Naur -x CVS plucker-orig plucker > diff
> 
> Be sure that before you run this command, run 'make distclean' and
> delete the configure script, just to make sure everything is 100% fresh.
> 
> Finally, always review the diff manually, just to make sure nothing
> stray popped in, and it's expressing only EXACTLY what you want/changed.
> 
> -- 
> Adam McDaniel
> Array Networks
> Calgary, AB, Canada
-- 
Jamis Buck
[EMAIL PROTECTED]
http://hippa-potta.jamisandtarasine.net
.
"I'd horsewhip you if I had a horse." -- Groucho Marx
diff -Naur -x CVS plucker-orig/viewer/paragraph.c plucker/viewer/paragraph.c
--- plucker-orig/viewer/paragraph.c	Sun Apr 21 11:27:51 2002
+++ plucker/viewer/paragraph.c	Mon Apr 29 11:43:45 2002
@@ -77,6 +77,9 @@
 /* Used to keep track of images */
 static Boolean image;
 
+/* Used to keep track of the end of a paragraph */
+static Boolean paragraphEnded;
+
 /* Used to keep track of the search pattern */
 static Int16 patternCount;
 static Int16 findPatternPos;
@@ -201,7 +204,7 @@
     else if ( pContext->type == ALIGNMENT_RIGHT )
         tContext->cursorX += diff;
     else if ( pContext->type == ALIGNMENT_JUSTIFY && ! multilineAnchor && 
-              0 < spaceCount && diff < pContext->maxPixels / 4 ) {
+              0 < spaceCount && !paragraphEnded ) {
         littleSpace = diff / spaceCount;    /* each space gets pixels */
         bigSpace    = diff % spaceCount;    /* this many get 1 extra */
     }
@@ -726,6 +729,9 @@
     Int16   lastSpacePixels;
     Int16   lastSpaceHeight;
     Int16   charWidth;
+    /* added 28 Apr 2002 by Jamis Buck ([EMAIL PROTECTED]) */
+    UInt8   adjacentDashes;
+    /* --------------------------- */
 
     startPosition       = pContext->position;
     initialFontStyle    = FntGetFont();
@@ -736,6 +742,7 @@
 
     *height     = 0;
     tokenCount  = 0;
+    paragraphEnded = false;
 
     spaceCount          = 0;
     lastSpace           = 0;
@@ -744,20 +751,26 @@
     lastSpaceHeight     = 0;
     lastSpaceIsVisible  = false;
 
+    /* added 28 Apr 2002 by Jamis Buck ([EMAIL PROTECTED]) */
+    adjacentDashes      = 0;
+    /* --------------------------- */
+
     for ( ;; ) {
         Char        nextToken;
         TokenType   nextTokenType;
 
         nextTokenType = GetNextToken( pContext, &nextToken );
 
-        if ( nextTokenType == TOKEN_PARAGRAPH_END )
+        if ( nextTokenType == TOKEN_PARAGRAPH_END ) {
+            paragraphEnded = true;
             break;
-        else if ( nextTokenType == TOKEN_FUNCTION ) {
+        } else if ( nextTokenType == TOKEN_FUNCTION ) {
             HandleFunction( pContext, NULL, &charWidth );
 
             tokenCount++;
             if ( newLine ) {
                 newLine = false;
+                paragraphEnded = true;
                 break;
             }
             if ( horizontalRule ) {
@@ -803,7 +816,29 @@
             lastSpacePixels     = linePixels;
             lastSpaceHeight     = *height;
             lastSpace           = tokenCount;
+
+        /* added 28 Apr 2002 by Jamis Buck ([EMAIL PROTECTED]) */
+        /* the idea here is to treat multiple adjacent hyphenation characters as if they were
+         * a single long hyphen.  If the line needs to wrap in the middle of this hyphen, we
+         * instead wrap on the "lastSpace" character. Note that we're looking for four
+         * different types of hyphens:
+         *   ASCII 0x2D '-'  : the standard ASCII dash, or minus, character
+         *   ASCII 0x96 '-'  : ISO Latin 1 'n-dash' character
+         *   ASCII 0x97 '--' : ISO Latin 1 'm-dash' character
+         *   ASCII 0xAD '�'  : in the HTML 4.0 list of character entities, this is the 'soft'
+         *                     or 'discretionary' hyphen.
+         * TODO: are there more types of hyphens and/or word-break characters we should be looking for? */
+        } else if( nextToken == '-' || nextToken == '\xAD' || nextToken == '\x96' || nextToken == '\x97' ) {
+          adjacentDashes++;
+
+        } else if( adjacentDashes > 0 ) {
+          lastSpacePixels = linePixels;
+          adjacentDashes = 0;
+          lastSpace = tokenCount;
+          lastSpaceIsVisible = false;
         }
+        /* --------------------------- */
+
         charWidth = FntCharWidth( nextToken );
 
         if ( pContext->maxPixels < ( charWidth + linePixels ) ) {
@@ -813,7 +848,17 @@
                 tokenCount  = lastSpace;
                 linePixels  = lastSpacePixels;
                 *height     = lastSpaceHeight;
+
+            /* added 28 Apr 2002 by Jamis Buck ([EMAIL PROTECTED]) */
+            /* if adjacentDashes is greater than 0, then we're in the middle of a series
+             * of adjacent hyphens, and we wrap instead of the previous space character. */
+            } else if( adjacentDashes > 0 ) {
+              tokenCount = lastSpace;
+              linePixels = lastSpacePixels;
+              *height = lastSpaceHeight;
             }
+            /* --------------------------- */
+
             break;
         }
         linePixels += charWidth;

Reply via email to