Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size...

55
Word Processing

Transcript of Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size...

Page 1: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Word Processing

Page 2: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Word Processing and the WWW• Differences

– WWW is dynamic• Variable window size

• Possibly non-graphical devices

• Leave decisions to the browser

• Simple implementation when building many browsers

– Word processing is static• Fixed page size

• Exact layout

• Target is always paper

Page 3: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Word Processing and the WWW

• Similarities– Text is still text– Basic styling of headers, bold, italic, tables

• These are inherent in how people communicate with text

– Similar underlying algorithms and structures

Page 4: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Microsoft Word

Style Font Size Bold, ItalicUnderline

Page 5: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Microsoft Word

Justification Lists Indentation Colors

Virtually every word processor has these same features

Page 6: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Word and HTML

Page 7: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Word and HTML

Page 8: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

<html xmlns:o="urn:schemas-microsoft-com:office:office"

xmlns:w="urn:schemas-microsoft-com:office:word"

xmlns="http://www.w3.org/TR/REC-html40">

<head>

<meta http-equiv=Content-Type content="text/html; charset=windows-1252">

<meta name=Originator content="Microsoft Word 9">

<title>This is some new text</title>

<!--[if gte mso 9]><xml>

<o:DocumentProperties>

<o:Author>Dan R. Olsen Jr.</o:Author>

</o:DocumentProperties>

</xml></head>

<body lang=EN-US style='tab-interval:.5in'>

<div class=Section1>

<p class=MsoNormal>This is <b>some</b> new text</p></div>

</body>

</html>

Word and HTML

Page 9: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

HTML in Word

• Word doesn’t like JavaScript very much

Page 10: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

• HTML– This is <b>some</b> text

• Word– Use special characters beyond 128 instead of tags

Encodings

T h i s i s < b > s o m e < / b > t e x t84 104 105 115 32 105 115 32 60 98 62 115 111 109 101 60 47 98 62 32 116 101 120 116

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23

T h i s i s ## s o m e ## t e x t84 104 105 115 32 105 115 32 220 115 111 109 101 221 32 116 101 120 116

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18

Bold

Bold

Page 11: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Translating Encodings

• Word encodes many more kinds of style information than HTML– Paragraph indentation

– Superscript and subscript

– Embedded EXCEL tables

• Saving as HTML– Re code similar features (bold, underline)

– Simulate the Word feature using HTML features

– Throw away the Word feature

Page 12: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Translating Encodings

• MS Word -> WordPerfect

• WordPerfect -> HTML

• HTML-> MS Word

• Each step may modify or discard some features

• The end result will rarely be the same

Page 13: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Algorithms for Basic Word Processing

Type a character

• Delete a character

• Select some characters

• Bold some characters

• Cut / Copy / Paste

Page 14: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Cursor Positionan index into the string

A s t r i n g65 32 115 116 114 105 110 103

0 1 2 3 4 5 6 7

Cursor = 3

Cursor=6

Page 15: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Typing a Character

A s t r i n g65 32 115 116 114 105 110 103

0 1 2 3 4 5 6 7

Cursor=4A s p t r i n g65 32 115 112 116 114 105 110 103

0 1 2 3 4 5 6 7 8

Cursor = 3Key = ‘p’

Page 16: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Typing a Character

A s t r i n g65 32 115 116 114 105 110 103

0 1 2 3 4 5 6 7

Cursor = 3Key = ‘p’

For ( index I starting at Text.length-1 down to Cursor){ Text[I+1]=Text[I] }Text[Cursor] = Key;Cursor = Cursor+1;

Page 17: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Typing a Character

Cursor = 3Key = ‘p’I=8

A s t r i n g g65 32 115 116 114 105 110 103 103

0 1 2 3 4 5 6 7 8

For ( index I starting at Text.length-1 down to Cursor){ Text[I+1]=Text[I] } move character up one spaceText[Cursor] = Key;Cursor = Cursor+1;

Page 18: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Typing a Character

Cursor = 3Key = ‘p’I=7

A s t r i n n g65 32 115 116 114 105 110 110 103

0 1 2 3 4 5 6 7 8

For ( index I starting at Text.length-1 down to Cursor){ Text[I+1]=Text[I] } move character up one spaceText[Cursor] = Key;Cursor = Cursor+1;

Page 19: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Typing a Character

Cursor = 3Key = ‘p’I=6

A s t r i i n g65 32 115 116 114 105 105 110 103

0 1 2 3 4 5 6 7 8

For ( index I starting at Text.length-1 down to Cursor){ Text[I+1]=Text[I] } move character up one spaceText[Cursor] = Key;Cursor = Cursor+1;

Page 20: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Typing a Character

Cursor = 3Key = ‘p’I=5

A s t r r i n g65 32 115 116 114 114 105 110 103

0 1 2 3 4 5 6 7 8

For ( index I starting at Text.length-1 down to Cursor){ Text[I+1]=Text[I] } move character up one spaceText[Cursor] = Key;Cursor = Cursor+1;

Page 21: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Typing a Character

Cursor = 3Key = ‘p’I=4

A s t t r i n g65 32 115 116 116 114 105 110 103

0 1 2 3 4 5 6 7 8

For ( index I starting at Text.length-1 down to Cursor){ Text[I+1]=Text[I] } move character up one spaceText[Cursor] = Key;Cursor = Cursor+1;

Page 22: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Typing a Character

Cursor = 3Key = ‘p’I=3

A s p t r i n g65 32 115 112 116 114 105 110 103

0 1 2 3 4 5 6 7 8

For ( index I starting at Text.length-1 down to Cursor){ Text[I+1]=Text[I] }Text[Cursor] = Key; add the typed characterCursor = Cursor+1;

Page 23: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Typing a Character

Cursor = 4Key = ‘p’I=3

A s p t r i n g65 32 115 112 116 114 105 110 103

0 1 2 3 4 5 6 7 8

For ( index I starting at Text.length-1 down to Cursor){ Text[I+1]=Text[I] }Text[Cursor] = Key;Cursor = Cursor+1; move the cursor over

Page 24: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Algorithms for Basic Word Processing

• Type a characterDelete a character

• Select some characters

• Bold some characters

• Cut / Copy / Paste

Page 25: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Delete a Character

Cursor = 4Key = deleteI=?

For ( index I starting at Cursor+1 up to Text.length-1){ Text[I-1]=Text[I] } move a character down one spaceCursor = Cursor-1;Text[Text.length-1] = “no character”

A s p t r i n g65 32 115 112 116 114 105 110 103

0 1 2 3 4 5 6 7 8

Page 26: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Delete a Character

Cursor = 4Key = deleteI=3

A s t t r i n g65 32 115 116 116 114 105 110 103

0 1 2 3 4 5 6 7 8

For ( index I starting at Cursor+1 up to Text.length-1){ Text[I-1]=Text[I] } move a character down one spaceCursor = Cursor-1;Text[Text.length-1] = “no character”

Page 27: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Delete a Character

Cursor = 4Key = deleteI=4

A s t r r i n g65 32 115 116 114 114 105 110 103

0 1 2 3 4 5 6 7 8

For ( index I starting at Cursor+1 up to Text.length-1){ Text[I-1]=Text[I] } move a character down one spaceCursor = Cursor-1;Text[Text.length-1] = “no character”

Page 28: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Delete a Character

Cursor = 4Key = deleteI=5

A s t r i i n g65 32 115 116 114 105 105 110 103

0 1 2 3 4 5 6 7 8

For ( index I starting at Cursor+1 up to Text.length-1){ Text[I-1]=Text[I] } move a character down one spaceCursor = Cursor-1;Text[Text.length-1] = “no character”

Page 29: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Delete a Character

Cursor = 4Key = deleteI=6

A s t r i n n g65 32 115 116 114 105 110 110 103

0 1 2 3 4 5 6 7 8

For ( index I starting at Cursor+1 up to Text.length-1){ Text[I-1]=Text[I] } move a character down one spaceCursor = Cursor-1;Text[Text.length-1] = “no character”

Page 30: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Delete a Character

Cursor = 4Key = deleteI=7

A s t r i n g g65 32 115 116 114 105 110 103 103

0 1 2 3 4 5 6 7 8

For ( index I starting at Cursor+1 up to Text.length-1){ Text[I-1]=Text[I] } move a character down one spaceCursor = Cursor-1;Text[Text.length-1] = “no character”

Page 31: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Delete a Character

Cursor = 3Key = deleteI=8

A s t r i n g g65 32 115 116 114 105 110 103 103

0 1 2 3 4 5 6 7 8

For ( index I starting at Cursor+1 up to Text.length-1){ Text[I-1]=Text[I] } Cursor = Cursor-1; move the cursor overText[Text.length-1] = “no character”

Page 32: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Delete a Character

Cursor = 3Key = deleteI=8

A s t r i n g65 32 115 116 114 105 110 103 ###

0 1 2 3 4 5 6 7 8

For ( index I starting at Cursor+1 up to Text.length-1){ Text[I-1]=Text[I] } Cursor = Cursor-1;Text[Text.length-1] = “no character”; blank out last character

Page 33: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

A Helpful Function

Function moveChars(Text,Start,End,Distance){ if (Distance>0)

{ for (index I from End down to Start){ Text[I+Distance]=Text[I];}

}Else

{ for (index I from Start up to End)

{ Text[I+Distance]=Text[I] }}

}

Page 34: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Typing a Character

A s t r i n g65 32 115 116 114 105 110 103

0 1 2 3 4 5 6 7

Cursor = 3Key = ‘p’

moveChars(text,Cursor,text.length-1, 1);Text[Cursor]=Key;Cursor=Cursor+1;

Page 35: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Delete a Character

Cursor = 4Key = deleteI=?

moveChars(text,cursor,text.length-1,-1);Cursor=Cursor-1;text[text.length -1]=no character;

A s p t r i n g65 32 115 112 116 114 105 110 103

0 1 2 3 4 5 6 7 8

Page 36: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Algorithms for Basic Word Processing

• Type a character

• Delete a characterSelect some characters

• Bold some characters

• Cut / Copy / Paste

Page 37: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Selecting Characters

A s t r i n g65 32 115 116 114 105 110 103

0 1 2 3 4 5 6 7

Start = 2End = 7

Page 38: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Algorithms for Basic Word Processing

• Type a character

• Delete a character

• Select some charactersBold some characters

• Cut / Copy / Paste

Page 39: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Bolding Characters

Start = 2End = 7

moveChars(text,End,text.length-1,2);moveChars(text,Start,End-1,1);Text[Start]=code for start bold;Text[End+1]=code for end bold;End=End+2;

A s t r i n g65 32 115 116 114 105 110 103 ### ###

0 1 2 3 4 5 6 7 8 9

Page 40: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Bolding Characters

Start = 2End = 7

moveChars(text,End,text.length-1,2); -> moveChars(text,7,7,2)moveChars(text,Start,End-1,1);Text[Start]=code for start bold;Text[End+1]=code for end bold;End=End+2;

A s t r i n g g65 32 115 116 114 105 110 103 ### 103

0 1 2 3 4 5 6 7 8 9

Page 41: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Bolding Characters

Start = 2End = 7

moveChars(text,End,text.length-1,2);moveChars(text,Start,End-1,1); -> moveChars(text,2,6,1)Text[Start]=code for start bold;Text[End+1]=code for end bold;End=End+2;

A s s t r i n g65 32 115 115 116 114 105 110 ### 103

0 1 2 3 4 5 6 7 8 9

Page 42: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Bolding Characters

Start = 2End = 7

moveChars(text,End,text.length-1,2);moveChars(text,Start,End-1,1); Text[Start]=code for start bold;Text[End+1]=code for end bold;End=End+2;

A ## s t r i n g65 32 <b> 115 116 114 105 110 ### 103

0 1 2 3 4 5 6 7 8 9

Page 43: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Bolding Characters

Start = 2End = 7

moveChars(text,End,text.length-1,2);moveChars(text,Start,End-1,1); Text[Start]=code for start bold;Text[End+1]=code for end bold;End=End+2;

A ## s t r i n ## g65 32 <b> 115 116 114 105 110 </b> 103

0 1 2 3 4 5 6 7 8 9

Page 44: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Bolding Characters

Start = 2End = 9

moveChars(text,End,text.length-1,2);moveChars(text,Start,End-1,1); Text[Start]=code for start bold;Text[End+1]=code for end bold;End=End+2;

A ## s t r i n ## g65 32 <b> 115 116 114 105 110 </b> 103

0 1 2 3 4 5 6 7 8 9

Page 45: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Algorithms for Basic Word Processing

• Type a character

• Delete a character

• Select some characters

• Bold some charactersCut / Copy / Paste

Page 46: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Cut

A s t r i n g65 32 115 116 114 105 110 103

0 1 2 3 4 5 6 7

Start = 2End = 7

ClipBoard=

For (each character C with index >= Start and < End){ copy C to the ClipBoard }moveChars(text,End,text.length-1,Start-End);Set the last (End-Start) characters in the array to “no character”End=Start;

Page 47: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Cut

A s t r i n g65 32 115 116 114 105 110 103

0 1 2 3 4 5 6 7

Start = 2End = 7

ClipBoard=“strin”

For (each character C with index >= Start and < End){ copy C to the ClipBoard }moveChars(text,End,text.length-1,Start-End);Set the last (End-Start) characters in the array to “no character”End=Start;

Page 48: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Cut

A g t r i n g65 32 103 116 114 105 110 103

0 1 2 3 4 5 6 7

Start = 2End = 7

ClipBoard =“strin”

For (each character C with index >= Start and < End){ copy C to the ClipBoard }moveChars(text,End,text.length-1,Start-End);Set the last (End-Start) characters in the array to “no character”End=Start;

Page 49: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Cut

A g65 32 103 ### ### ### ### ###

0 1 2 3 4 5 6 7

Start = 2End = 7

ClipBoard =“strin”

For (each character C with index >= Start and < End){ copy C to the ClipBoard }moveChars(text,End,text.length-1,Start-End);Set the last (End-Start) characters in the array to “no character”End=Start;

Page 50: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Cut

A g65 32 103 ### ### ### ### ###

0 1 2 3 4 5 6 7

Start = 2End = 2

ClipBoard =“strin”

For (each character C with index >= Start and < End){ copy C to the ClipBoard }moveChars(text,End,text.length-1,Start-End);Set the last (End-Start) characters in the array to “no character”End=Start;

Page 51: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Copy

A s t r i n g65 32 115 116 114 105 110 103

0 1 2 3 4 5 6 7

Start = 2End = 7

ClipBoard =“strin”

For (each character C with index >= Start and < End){ copy C to the ClipBoard }

Page 52: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Paste

Start = 2End = 2

ClipBoard =“strin”

A s 65 32 115

0 1 2

moveChars(text,End,text.length-1, ClipBoard.length);Copy the characters from ClipBoard into the array at index Start

Page 53: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Paste

A g g65 32 103 ### ### ### ### 103

0 1 2 3 4 5 6 7

Start = 2End = 2

ClipBoard =“strin”

moveChars(text,End,text.length-1, ClipBoard.length);Copy the characters from ClipBoard into the array at index Start

Page 54: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Paste

A s t r i n g65 32 115 116 114 105 110 103

0 1 2 3 4 5 6 7

Start = 2End = 2

ClipBoard =“strin”

moveChars(text,End,text.length-1, ClipBoard.length);Copy the characters from ClipBoard into the array at index Start

Page 55: Word Processing. Word Processing and the WWW Differences –WWW is dynamic Variable window size Possibly non-graphical devices Leave decisions to the browser.

Review

• Other encodings besides <b></b>• Translating between encodings can modify or lose

information• Text is just an array

– Typing a character - move characters right– Deleting a character - move characters left– Selecting - Start and End are array indices– Cut - copy to clip board and move characters left– Copy - copy to clip board– Paste - move characters right and copy from clip board