Copying GState

45 views
Skip to first unread message

Stratos Paraskevaidis

unread,
Apr 4, 2014, 9:20:36 AM4/4/14
to pdfne...@googlegroups.com
Good day to you all. I am trying to back up an element's graphics state (in my case it's a text object) to another GState object for some specific treatment, but the moment the iterator parses the next element my backed up GState changes dynamically. I know this problem is probably due to shallow copying but the same doesn't happen if I back up the fill color of the text. Is there a way to avoid copying the gState by reference and do a deep copy of it? Here is a snippet of what I'm basically doing:

GState backupGState = null;
while ((element = page_reader.next()) != null) {
switch (element.getType()) {
case Element.e_text: {
GState gs = element.getGState();
createTextField(backupGState);
backupGState = gs;
}
}
}

So after going into the while loop for the second time, the backupGState doesn't have the graphics state of the first element, but it changes dynamically to the state that the second element is in. This happens immediately after element = page_reader.next() is computed.

Support

unread,
Apr 7, 2014, 7:31:04 PM4/7/14
to
I guess you could copy all GState properties into a temp copy and implement an assignment operator that copies the properties back into a GState. To limit the amount of work, you could only copy a subset of GSTate related to text. For example:

class GSCopy
{
   GSCopy(GState gs) {
         // call gs getters to initialize the state...
         fill_color = gs.GetFillColor();
         fill_cs = gs.GetFillColorSpace();
         ....
    }

    void Assign(GState gs)  {
          // GSCopy  to GState
         gs.SetFillColor(fill_color);
         gs.SetFillColorSpace(fill_cs);
         ...
     }

    // the state ...
    ColorPt fill_color;
    ColorSpace fill_color_space;
}

Please let me know if this would work for you.
Reply all
Reply to author
Forward
0 new messages