Title: Word Processing
1Word Processing
2Word 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
3Word 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
4Microsoft Word
5Microsoft Word
Virtually every word processor has these same
features
6Word and HTML
7Word and HTML
8Word and HTML
lthtml xmlnso"urnschemas-microsoft-comofficeof
fice" xmlnsw"urnschemas-microsoft-comofficewo
rd" xmlns"http//www.w3.org/TR/REC-html40"gt lthead
gt ltmeta http-equivContent-Type
content"text/html charsetwindows-1252"gt ltmeta
nameOriginator content"Microsoft Word
9"gt lttitlegtThis is some new textlt/titlegt lt!--if
gte mso 9gtltxmlgt ltoDocumentPropertiesgt
ltoAuthorgtDan R. Olsen Jr.lt/oAuthorgt lt/oDocument
Propertiesgt lt/xmlgtlt/headgt ltbody langEN-US
style'tab-interval.5in'gt ltdiv
classSection1gt ltp classMsoNormalgtThis is
ltbgtsomelt/bgt new textlt/pgt lt/divgt lt/bodygt lt/htmlgt
9HTML in Word
- Word doesnt like JavaScript very much
10Encodings
- HTML
- This ltbgtislt/bgt text
- Word
- Use special characters beyond 128 instead of tags
11Translating 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
12Translating Encodings
- What if we take a Word document and
- Convert MS Word to WordPerfect
- then, convert WordPerfect to HTML
- then, convert HTML back to MS Word.
- Each step may modify or discard some features.
- The end result will rarely be the same as the
original document!!!
13Algorithms for Word Processing
- Insert a character
- Delete a character
- Select some characters
- Bold some characters
- Cut / Copy / Paste
14Cursor Position
15Insert a Character
Key p
16Insert a Character
4
Cursor 3 Key 'p' Text.length 7
8
function insertChar(text, cursor, key) For
(itext.length-1 igtcursor ii-1)
texti1 texti textcursor
key cursor cursor 1 text.length
text.length 1
Move a character up one space
Insert character
Increment cursor
Increment length
17Algorithms for Word Processing
- Insert a character
- Delete a character
- Select some characters
- Bold some characters
- Cut / Copy / Paste
18Delete a Character
3
Cursor 4 Key ltbkspgt Text.length 8
7
function deleteChar(text, cursor) For
(icursor Ilttext.length ii1)
texti-1texti cursor cursor -
1 text.length text.length - 1
Move a character back one space
Decrement cursor
Decrement length
19(No Transcript)
20function moveChars(text, start, end,
destination) for (i0 iltend-start ii1)
textidestinationtextistart return
moveChars
function moveChars(text, start, end,
destination) if (destinationltstart) for
(i0 iltend-start ii1) textidestinationte
xtistart else for (iend-start igt0
ii-1) textidestinationtextistart
return
21A Helpful Function
- function moveChars(text, start, end, destination)
- if (destination lt start)
- for (istart iltend ii1)
- textdestinationi-start texti
-
- else
- for (iend-1 igtstart ii-1)
- textdestinationi-start texti
-
- return
22Insert a Character
function insertChar(text, cursor, key) For
(itext.length-1 igtcursor ii-1)
texti1texti textCursor
key cursor cursor 1 text.length
text.length 1
Changed to
function insertChar(text, cursor,
key) moveChars(text, cursor, text.length,
cursor1) textcursor key cursor cursor
1 text.length text.length 1
23Delete a Character
function deleteChar(text, cursor) For
(icursor Ilttext.length ii1) texti-1
texti cursor cursor - 1 text.length
text.length - 1
Changed to
function deleteChar(text, cursor) moveChars(text
, cursor, text.length, cursor-1) cursor
cursor - 1 text.length text.length - 1
24Algorithms for Word Processing
- Insert a character
- Delete a character
- Select some characters
- Bold some characters
- Cut / Copy / Paste
25Selecting Characters
start 2 end 7
26Algorithms for Word Processing
- Insert a character
- Delete a character
- Select some characters
- Bold some characters
- Cut / Copy / Paste
27Bolding Characters
start 2 end 7
boldChars(text, 2, 7)
function boldChars(text, start,
end) moveChars(text, start, text.length,
start1) textstart ltcode for start
boldgt moveChars(text, end1, text.length1,
end2) textend1 ltcode for end boldgt end
end 2 text.length text.length 2
28Algorithms for Word Processing
- Insert a character
- Delete a character
- Select some characters
- Bold some characters
- Cut / Copy / Paste
29Cut
start 2 end 7
ClipBoard
function cutChars(text, start, end,
clipBoard) for (istart iltend ii1)
clipBoardi texti clipBoard.length
(end - start) moveChars(text, end,
text.length-1, start) text.length text.length
- clipBoard.length end start
30Paste
Start 2
ClipBoard strin
function pasteChars(text, start,
clipBoard) moveChars(text, start, text.length,
startclipBoard.length) for (i0
iltclipBoard.length ii1) textstarti
clipBoardi text.length text.length
clipBoard.length
31Review
- Other encodings besides ltbgtlt/bgt
- Translating between encodings can modify or lose
information - Text is just an array
- Insert 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