Okay, I mispoke myself in my last email. What I meant to say is that,
in the current AlignText implementation, "if the *difference* between
the line length and the maximum line length is greater than 25% of the
maximum line length", then the line will not be justified.
I have added a "paragraphEnded" flag and it seems to fix the problem.
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).
I've attached a diff...hope I did it right. It includes the change to
paragraph.c for the word wrap stuff, too.
- Jamis
On Mon, 2002-04-29 at 10:56, Jamis Buck wrote:
> Thanks for the hint -- I'll do a diff next time. ;) I'm new to all
> this, so please forgive any newbie mistakes.
>
> I think I've figured out why the ALIGNMENT_JUSTIFY will sometimes not
> justify a given line. The AlignText function is saying that the line
> will not be justified if the line length is less than 25% of the maximum
> line length. I assume this assumption is to catch the last line of a
> paragraph, but this also means that if a line is wrapped because of a
> long word at the end (ie, "blah blah supercalifragilistic..."), the
> "blah blah" will not be justified. I think if a new global flag is
> added ("paragraphEnded") and set to true when a 'newline' or
> PARAGRAPH_END token is encountered, you could check that flag explicitly
> in AlignText instead of assuming a short line to be the end of the
> paragraph. I'll tinker with it to see if this idea will work.
>
> Thanks!
>
> - Jamis
>
> On Mon, 2002-04-29 at 10:46, Adam McDaniel wrote:
> > On Sun, Apr 28, 2002 at 08:28:59PM -0600, Jamis Buck wrote:
> > > Okay -- I've attached the single function I modified (GetLineMetrics,
> > > in paragraph.c). I have commented the portions I modified. Please let
> > > me know if it does cause any problems -- I would really like to see this
> > > added. The only potential problem I can see is if the hyphen character
> > > is the first character in a word (ie, a unary negative). I haven't
> > > completely thought through how the code will behave in that case.
> >
> > I can try running it. In the future though, it would be better to make
> > a diff rather than send the whole function. It's easier for ppl who are
> > re-creating the environment to inject diffs into the original to try it
> > out.
> >
> > > On another note -- I've noticed that ALIGNMENT_JUSTIFY does not work in
> > > every case; i.e., in some instances, a line will not be justified, but
> > > the preceding and following lines will be. Is this a known bug, or
> > > should I investigate it further? (I've noticed it in the CVS snapshot I
> > > downloaded today.)
> >
> > I believe for ALIGNMENT_JUSTIFY to work, it must be specified in the
> > pdb by the parser. However, a whole paragraph should maintain the same
> > type of justification. If one line isn't, then it may be a bug.
> >
> > By all means, invesitage further :)
> >
> > --
> > 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
>
--
Jamis Buck
[EMAIL PROTECTED]
http://hippa-potta.jamisandtarasine.net
.
"I'd horsewhip you if I had a horse." -- Groucho Marx
--- paragraph.c Mon Apr 29 11:17:22 2002
+++ dev/plucker_2002-04-28_19h.14m.04s/viewer/paragraph.c Mon Apr 29 11:16:02
+2002
@@ -1,5 +1,5 @@
/*
- * $Id: paragraph.c,v 1.48.2.2 2002/04/23 19:58:43 adamm Exp $
+ * $Id: paragraph.c,v 1.49 2002/04/21 17:27:51 nordstrom Exp $
*
* Viewer - a part of Plucker, the free off-line HTML viewer for PalmOS
* Copyright (c) 1998-2002, Mark Ian Lillywhite and Michael Nordstr�m
@@ -20,12 +20,13 @@
*
*/
+#include <stdarg.h>
+
#include "anchor.h"
#include "const.h"
#include "debug.h"
#include "document.h"
#include "genericfile.h"
-#include "hires.h"
#include "history.h"
#include "image.h"
#include "os.h"
@@ -78,6 +79,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;
@@ -88,14 +92,13 @@
static Int16 bigSpace = 0; /* How many get 1 extra */
static Int16 littleSpace = 0; /* Extra pixels in each */
-/* Used to see if the current font is the fixed width font */
-static Boolean fixedWidthFont = false;
/***********************************************************************
*
* Local functions
*
***********************************************************************/
+static Boolean FixedWidthFont( void ) SECTION2;
static Int16 GetParagraphOffset( Header* record,
Paragraph* paragraph ) SECTION2;
static void AlignText( TextContext* tContext,
@@ -131,6 +134,12 @@
Int16 characters, Boolean skipLeadingSpace ) SECTION2;
+/* Check if current font is the fixed width font */
+static Boolean FixedWidthFont( void )
+{
+ return ( FntGetFont() == narrowFixedFont );
+}
+
/* Set position and length of find pattern */
void SetFindPatternData
@@ -196,7 +205,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 */
}
@@ -223,10 +232,6 @@
)
{
if ( MINSTYLES <= style && style < MAXSTYLES ) {
- if ( style == FIXEDSTYLE )
- fixedWidthFont = true;
- else
- fixedWidthFont = false;
FntSetFont( GetStyle( style ) );
pContext->fontHeight = FntLineHeight();
}
@@ -725,6 +730,9 @@
Int16 lastSpacePixels;
Int16 lastSpaceHeight;
Int16 charWidth;
+ /* added 28 Apr 2002 by Jamis Buck ([EMAIL PROTECTED]) */
+ UInt8 adjacentDashes;
+ /* --------------------------- */
startPosition = pContext->position;
initialFontStyle = FntGetFont();
@@ -735,6 +743,7 @@
*height = 0;
tokenCount = 0;
+ paragraphEnded = false;
spaceCount = 0;
lastSpace = 0;
@@ -743,20 +752,27 @@
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 ) {
HandleFunction( pContext, NULL, &charWidth );
tokenCount++;
if ( newLine ) {
newLine = false;
+ paragraphEnded = true;
break;
}
if ( horizontalRule ) {
@@ -790,7 +806,7 @@
}
addMarginToCurrent = false;
- if ( skipLeadingSpace && CharIsSpace( nextToken ) && ! fixedWidthFont )
+ if ( skipLeadingSpace && CharIsSpace( nextToken ) && ! FixedWidthFont() )
continue;
skipLeadingSpace = false;
@@ -802,7 +818,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 ) ) {
@@ -812,7 +850,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;
@@ -822,6 +870,7 @@
tokenCount++;
}
+
if ( pContext->fontHeight != *height )
pContext->fontHeight = *height;
@@ -838,6 +887,7 @@
}
+
/* Draw characters from a paragraph onto the display */
static void WriteLine
(
@@ -904,7 +954,7 @@
patternCount++;
- if ( skipLeadingSpace && CharIsSpace( nextChar ) && ! fixedWidthFont )
+ if ( skipLeadingSpace && CharIsSpace( nextChar ) && ! FixedWidthFont() )
continue;
skipLeadingSpace = false;
@@ -1008,8 +1058,9 @@
GetLineMetrics( &pContext, true, &length, &height );
patternCount = storeCount;
- if ( length <= 0 )
+ if ( length <= 0 ) {
break;
+ }
tContext->cursorY += height;