Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Justify !!

Status
Not open for further replies.

karephul

Programmer
May 14, 2006
24
US

In microsoft word, when you write something say a paragraph by default its is aligned left, you want it to be JUSTIFY .. so that it looks neet !!

what algorithm they might have used and what data structure Microsoft word would have maintained while you are writing !!!

Google Interview Question !!!
 
Here a snippet I wrote in cobol to justify W70-Lib(Icur):
Code:
MOVE W70-Lib(Icur) TO Xcur
INSPECT Xcur REPLACING LEADING " " BY "\"
CALL "MoveGauche" USING Xcur Xcur
  BY VALUE c70 c70 RETURNING LgX
IF LgX = c70 EXIT SECTION END-IF
COMPUTE LgFree = c70 - LgX         *>Nb blancs a justifier
MOVE 0 TO LgWrap                   *>Nb blancs duplicables
INSPECT Xcur(1:LgX) TALLYING LgWrap FOR ALL SPACE
IF LgFree <= LgWrap
  MOVE 1 TO Isav MOVE SPACE TO Xsav
  PERFORM VARYING iPosit FROM 1 BY 1 UNTIL iPosit > LgX
    MOVE Xcur(iPosit:1) TO Xsav(Isav:1)
    ADD 1 TO Isav
    IF Xcur(iPosit:1) = " "
      SUBTRACT 1 FROM LgWrap
      IF LgWrap > LgFree * 2 EXIT PERFORM CYCLE END-IF
      ADD 1 TO Isav
      SUBTRACT 1 FROM LgFree
      IF LgFree <= 0
        MOVE Xcur(iPosit + 1:) TO Xsav(Isav:)
        EXIT PERFORM
      END-IF
    END-IF
  END-PERFORM
  INSPECT Xsav REPLACING LEADING "\" BY " "
  MOVE Xsav TO W70-Lib(Icur)
END-IF
Note: the MoveGauche routine remove all leading spaces and replace all consecutive blanks with a single one.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I'm not sure I understand the question.

Each line is word-wrapped, then the spacing between the letters increased until the rightmost edge of the last word is aligned with the right margin. If the space between words passes a certain aesthetic threshold, the spacing between the letters in each word is increased until the result is more balanced. If there is only one word between the margins, the letters in the word are also spaced apart.

I imagine that in order to avoid calculating every line every time you make an edit, some data structures are maintained which keep the calculated values for each txt line. Only when an event occurs in the document that invalidates a line will its word-wrapping and full justification attributes have to be recalculated:

Typing on a line recalculates the line.
If the affected line pushes a word to the next line or pulls a word from the next line, the next line is also recalculated, with a ripple effect until a paragraph mark is encountered or the change does not affect the next line.

If a new line is created or removed from the end of the paragraph, all subsequent paragraphs must be marked suspect and recalculated as text flowing around floating objects can affect word-wrapping by changing the width of a line next to the object.
 
In Word, justify a paragraph and then do a manual line break ([Shift][Return]) in the middle of a line.

I'm using Word 2002. What I see is that it puts a ridiculous amount of space between the words, no change in the spacing of letters within a word. It might depend on font, of course.

------------------------------
An old man [tiger] who lives in the UK
 

Hey PHV,

I am not a awsome programmer and I dont know about cobol.

Can anyone who know C and Cobol translate that program in C ..
sorry PHV, but I dint understand what you are trying to do !!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top