Index: anchor.c
===================================================================
RCS file: /cvs/plucker/plucker_src/viewer/anchor.c,v
retrieving revision 1.57
diff -a -u -r1.57 anchor.c
--- anchor.c	29 Dec 2003 20:44:18 -0000	1.57
+++ anchor.c	23 Jan 2004 14:18:21 -0000
@@ -58,6 +58,8 @@
     UInt16          image;              /* The image to link to */
     Int16           paragraphOffset;    /* The offset to named anchor
                                            paragraph */
+    Int16           byteOffset;         /* The byte offset within the
+                                           paragraph */
     AnchorStateType state;
     Int16           anchorId;
     Boolean         underline;
@@ -84,7 +86,8 @@
 static Boolean AnchorInViewport(AnchorType *anchor) ANCHOR_SECTION;
 static void AnchorCreate(const TextContext *tContext,
                 const UInt16 reference, const UInt16 image,
-                const Int16 offset, const Int16 anchorId) ANCHOR_SECTION;
+                const Int16 paragraphOffset,
+                const Int16 anchorId) ANCHOR_SECTION;


 /* initialize new list of anchors */
@@ -149,7 +152,7 @@
     const TextContext*  tContext,   /* pointer to text context */
     const UInt16        reference,  /* record reference */
     const UInt16        image,      /* image reference */
-    const Int16         offset,     /* offset to first paragraph */
+    const Int16         paragraphOffset, /* offset to first paragraph */
     const Int16         anchorId    /* unique ID for anchor */
     )
 {
@@ -166,7 +169,8 @@
     anchor->anchorId            = anchorId;
     anchor->reference           = reference;
     anchor->image               = image;
-    anchor->paragraphOffset     = offset;
+    anchor->paragraphOffset     = paragraphOffset;
+    anchor->byteOffset          = 0;
     anchor->underline           = true;
     anchor->state               = ANCHOR_LIMBO;

@@ -181,13 +185,31 @@
     (
     const TextContext* tContext,    /* pointer to text context */
     const UInt16 reference,         /* record reference */
-    const Int16 offset              /* offset to first paragraph */
+    const Int16 paragraphOffset     /* offset to first paragraph */
     )
 {
     if ( ! DO_ANCHORS( tContext->writeMode ) )
         return;

-    AnchorCreate( tContext, reference, NO_IMAGE, offset, anchorId++ );
+    AnchorCreate( tContext, reference, NO_IMAGE, paragraphOffset,
+        anchorId++ );
+}
+
+
+
+/* Set byte offset within paragraph */
+void AnchorSetByteOffset
+    (
+    UInt16  offset
+    )
+{
+    if ( anchorList != NULL ) {
+        AnchorType* lastAnchor;
+
+        lastAnchor = ListLast( anchorList );
+
+        lastAnchor->byteOffset = offset;
+    }
 }


@@ -248,6 +272,7 @@

         AnchorCreate( tContext, lastAnchor->reference, image,
             lastAnchor->paragraphOffset, lastAnchor->anchorId );
+        AnchorSetByteOffset( lastAnchor->byteOffset );
     }
 }

@@ -401,8 +426,8 @@



-/* Return the offset of a visible anchor */
-Int16 GetVisibleOffset
+/* Return the paragraph offset of a visible anchor */
+Int16 GetVisibleParagraphOffset
     (
     const Int16 index   /* index of visible anchor */
     )
@@ -416,6 +441,21 @@



+/* Return the byte offset of a visible anchor */
+Int16 GetVisibleByteOffset
+    (
+    const Int16 index   /* index of visible anchor */
+    )
+{
+    AnchorType* anchor;
+
+    anchor = ListGet( anchorList, index );
+
+    return anchor->byteOffset;
+}
+
+
+
 /* Return the image reference for a visible anchor */
 UInt16 GetVisibleImage
     (
Index: anchor.h
===================================================================
RCS file: /cvs/plucker/plucker_src/viewer/anchor.h,v
retrieving revision 1.29
diff -a -u -r1.29 anchor.h
--- anchor.h	12 Jul 2003 14:57:02 -0000	1.29
+++ anchor.h	23 Jan 2004 14:18:21 -0000
@@ -44,8 +44,14 @@
 /* Return the image reference for a visible anchor */
 extern UInt16 GetVisibleImage(const Int16 index) ANCHOR_SECTION;

+/* Set byte offset within paragraph */
+void AnchorSetByteOffset( UInt16 offset ) ANCHOR_SECTION;
+
+/* Return the paragraph offset of a visible anchor */
+extern Int16 GetVisibleParagraphOffset(const Int16 index) ANCHOR_SECTION;
+
 /* Return the paragraph offset of a visible anchor */
-extern Int16 GetVisibleOffset(const Int16 index) ANCHOR_SECTION;
+extern Int16 GetVisibleByteOffset(const Int16 index) ANCHOR_SECTION;

 /* Return the reference of a visible anchor */
 extern UInt16 GetVisibleReference(const Int16 index) ANCHOR_SECTION;
@@ -75,7 +81,7 @@
 /* Initialize a new visible anchor */
 extern void AnchorStart(const TextContext *tContext,
                         const UInt16 reference,
-                        const Int16 offset) ANCHOR_SECTION;
+                        const Int16  paragraphOffset) ANCHOR_SECTION;

 /* Mark the end of a visible anchor */
 extern void AnchorStop(const TextContext *tContext,
Index: control.c
===================================================================
RCS file: /cvs/plucker/plucker_src/viewer/control.c,v
retrieving revision 1.124
diff -a -u -r1.124 control.c
--- control.c	10 Jan 2004 17:11:35 -0000	1.124
+++ control.c	23 Jan 2004 14:18:22 -0000
@@ -440,6 +440,9 @@


 /* Jump to requested record */
+/* If pOffset == NO_OFFSET, then cOffset counts from the
+   beginning of the record;  otherwise, cOffset counts from
+   the beginning of the paragraph */
 void JumpToRecord
     (
     const UInt16  recordId, /* record ID */
@@ -483,13 +486,15 @@
     if ( 0 < control ) {
         Int16   anchorIndex;
         UInt16  reference;
-        Int16   offset;
+        Int16   paragraphOffset;
+        Int16   byteOffsetInPara;
         UInt16  image;

         anchorIndex = control - 1;
         reference   = GetVisibleReference( anchorIndex );
-        offset      = GetVisibleOffset( anchorIndex );
-        image       = GetVisibleImage( anchorIndex );
+        paragraphOffset    = GetVisibleParagraphOffset( anchorIndex );
+        byteOffsetInPara   = GetVisibleByteOffset( anchorIndex );
+        image              = GetVisibleImage( anchorIndex );

         SndPlaySystemSound( sndClick );

@@ -524,7 +529,7 @@
                 reference = image;
             }
         }
-        JumpToRecord( reference, offset, NO_OFFSET );
+        JumpToRecord( reference, paragraphOffset, byteOffsetInPara );

         return;
     }
Index: document.c
===================================================================
RCS file: /cvs/plucker/plucker_src/viewer/document.c,v
retrieving revision 1.161
diff -a -u -r1.161 document.c
--- document.c	16 Jan 2004 16:08:17 -0000	1.161
+++ document.c	23 Jan 2004 14:18:23 -0000
@@ -82,6 +82,8 @@
                 Boolean recalculateHeights, Coord yPosition,
                 Boolean backwards, WriteModeType mode )
                 DOCUMENT_SECTION;
+static void NormalizeOffsets( Header* record, Int16* pOffsetPtr,
+                Int16* cOffsetPtr ) DOCUMENT_SECTION;
 static Boolean ViewPHTML( Header* record, Boolean newPage,
                 Int16 pOffset, Int16 cOffset, Coord yPosition,
                 Boolean backwards, WriteModeType mode )
@@ -799,7 +801,6 @@
     meta          = MemHandleLock( metaRecord );
     metaParagraph = GET_METAPARAGRAPH( meta, 0 );

-
     InitializeTextContext( &thisContext, mode );

     numOfParagraphs = record->paragraphs;
@@ -964,8 +965,30 @@



+/* Make sure that at least one of *pOffsetPtr and *cOffsetPtr is
+   is set to NO_OFFSET */
+static void NormalizeOffsets
+    (
+    Header* record,     /* pointer to record header */
+    Int16*  pOffsetPtr, /* paragraph number */
+    Int16*  cOffsetPtr  /* character offset */
+    )
+{
+    if ( *cOffsetPtr == NO_OFFSET || *pOffsetPtr == NO_OFFSET )
+        return;
+
+    *cOffsetPtr  += GET_PARAGRAPH( record, *pOffsetPtr ) -
+                    GET_PARAGRAPH( record, 0 );
+    *pOffsetPtr   = NO_OFFSET;
+}
+
+
+

 /* View Plucker HTML record */
+/* If pOffset == NO_OFFSET, then cOffset counts from the
+   beginning of the record;  otherwise, cOffset counts from
+   the beginning of the paragraph */
 static Boolean ViewPHTML
     (
     Header* record,     /* pointer to record header */
@@ -994,8 +1017,7 @@

     prevCoordSys = PalmSetCoordinateSystem( NATIVE );

-    if ( cOffset != NO_OFFSET )
-        pOffset = NO_OFFSET;
+    NormalizeOffsets( record, &pOffset, &cOffset );

     didDraw      = false;

@@ -1190,6 +1212,9 @@


 /* View record */
+/* If pOffset == NO_OFFSET, then cOffset counts from the
+   beginning of the record;  otherwise, cOffset counts from
+   the beginning of the paragraph */
 Boolean ViewRecord
     (
     UInt16          recordId,   /* record ID */
@@ -1223,6 +1248,9 @@


 /* View record ( or image ) */
+/* If pOffset == NO_OFFSET, then cOffset counts from the
+   beginning of the record;  otherwise, cOffset counts from
+   the beginning of the paragraph */
 static Boolean ViewRecordAt
     (
     UInt16          recordId,   /* record ID */
Index: paragraph.c
===================================================================
RCS file: /cvs/plucker/plucker_src/viewer/paragraph.c,v
retrieving revision 1.151
diff -a -u -r1.151 paragraph.c
--- paragraph.c	16 Jan 2004 16:08:17 -0000	1.151
+++ paragraph.c	23 Jan 2004 14:18:24 -0000
@@ -188,6 +188,8 @@
                         TextContext* tContext, Int16* width ) PARAGRAPH_SECTION;
 static FunctionType DoNamedAnchor( ParagraphContext* pContext,
                         TextContext* tContext, Int16* width ) PARAGRAPH_SECTION;
+static FunctionType DoSetTargetByteOffset( ParagraphContext* pContext,
+                        TextContext* tContext, Int16* width ) PARAGRAPH_SECTION;
 static FunctionType DoAnchorEnd( ParagraphContext* pContext,
                         TextContext* tContext, Int16* width ) PARAGRAPH_SECTION;
 static FunctionType DoSetStyle( ParagraphContext* pContext,
@@ -286,7 +288,8 @@
     { 0x78, DoStrikeEnd },
     { 0x83, DoUnicode16 },
     { 0x85, DoUnicode32 },
-    { 0x92, DoTable }
+    { 0x92, DoTable },
+    { 0x9A, DoSetTargetByteOffset }
 };

 /* variables for link list*/
@@ -1188,6 +1191,29 @@
 }


+/* Set the character offset of the current anchor. */
+static FunctionType DoSetTargetByteOffset
+    (
+    ParagraphContext*   pContext,
+    TextContext*        tContext,
+    Int16*              width
+    )
+{
+    if ( tContext != NULL && tContext->activeAnchor ) {
+        UInt8*  functionArgs;
+        Int16   offset;
+
+        functionArgs = pContext->function + 1;
+
+        offset       = *functionArgs * 256 + *( functionArgs + 1 );
+
+        AnchorSetByteOffset( offset );
+        ForceDefaultColor( tContext, true );
+    }
+    return ANCHOR;
+}
+
+
 /* Handle end of anchor data */
 static FunctionType DoAnchorEnd
     (
Index: paragraph.h
===================================================================
RCS file: /cvs/plucker/plucker_src/viewer/paragraph.h,v
retrieving revision 1.44
diff -a -u -r1.44 paragraph.h
--- paragraph.h	2 Jan 2004 15:36:16 -0000	1.44
+++ paragraph.h	23 Jan 2004 14:18:24 -0000
@@ -68,6 +68,7 @@
     10010000    0x90  Start Row (in table doc)
     10010010    0x92  Include table (record ID)
     10010111    0x97  Table cell (align, image_ref, colspan, rowspan, text len)
+    10011010    0x9A  Set offset of anchor target in target paragraph

     Note about attributes:
     For Paragraph objects, the attributes consist of the following bits:

