Difference between FPDFAnnot_SetRect and FPDFAnnot_AppendAttachmentPoints when adding a annotation to pdf document - pdf-generation

I'm using pdfium to add annotations to pdf files.
I opened the pdf file using Notepad++ and viewed its objects. Annotation object was present inside the Page object as follows,
3 0 obj
<</Annots[<</C[ 1 1 0]/CA 1/F 4/QuadPoints[ 0 300 300 300 0 0 300 0]/Rect[ 216.182 702.94 368.75 686.38]/Subtype/Highlight/Type/Annot>>]/Contents 4 0 R /Group<</CS/DeviceRGB/S/Transparency/Type/Group>>/MediaBox[ 0 0 612 792]/Parent 2 0 R /Resources<</ExtGState<</GS7 7 0 R /GS8 8 0 R >>/Font<</F1 5 0 R >>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI]>>/StructParents 0/Tabs/S/Type/Page>>
endobj
I used following code to add the rect and attachment points to the annotation.
FPDF_ANNOTATION highlightAnnot = FPDFPage_CreateAnnot(page, FPDF_ANNOT_HIGHLIGHT);
FPDFAnnot_SetRect(highlightAnnot, &rect);
FPDFAnnot_AppendAttachmentPoints(highlightAnnot, &new_quadpoints);
As I understood, Attachment points are set to give the location of Highlight annotation where we want it to be. But I don't understand the purpose of setting the Rect for this annotation.
Can someone please tell the reason for using FPDFAnnot_SetRect function?
Another thing,

FPDFAnnot_SetRect defines the bounding box, while FPDFAnnot_AppendAttachmentPoints defines the actual shape. Consider a multiline highlight annotation, it has only one Rect, but several AttachmentPoints.
A Rect could be used as a "collision box" at application level so that when you click on it, you select the contained annotation. Or it can be an "updating box".
Rect is more general and only text-related annotation types have AttachmentPoints.

Related

Set page size after issuing painting/show operators

I'm developing a printer emulator (partly) in PostScript. The command system I want to emulate is designed for roll paper thermal printers, mostly used for printing Point of Sale receipts. I'd prefer to execute the operations in the same order as the real printer would do, which means my program doesn't know the page size until it encounters a "cut" command. I want the program to work with variable paper size CUPS printers¹.
Can I change the page height after I issued painting/show commands without the filled parts of the document disappearing?
I have tried modifying the page device dictionary at the end of the document, but if I change the PageSize array, everything on the document disappears.
For example if I run the following program:
<< /PageSize [ 100 30 ] >> setpagedevice
0 0 moveto
(Text) show
showpage
I get the output:
But when I modify the code to adjust the page size right before the showpage command:
<< /PageSize [ 100 30 ] >> setpagedevice
0 0 moveto
(Text) show
<< /PageSize [ 100 100 ] >> setpagedevice
showpage
I only get a blank image:
I'm aware I can defer the execution of the painting/show operators, so my program calculates the document size before painting, and only executes the operations when it encounters the cut command. I would be able to implement that by myself, I don't need help with such a solution currently. I'm rather wondering, whether a simpler solution is possible for cutting an already drawn document to a calculated page size.
You cannot use marking operations and then select the page size in PostScript. Setting the media size in PostScript executes an implicit erasepage which clears any marks on the page.
See the note on page 408 of the 3rd edition PLRM (Section 6.1.1 PageDevice Dictionary):
Note: setpagedevice is a page-oriented operator used to control the
output processing of one or more pages of a page description. Any call
to setpagedevice implicitly invokes erasepage and initgraphics, and
thus must precede the descriptions of the pages to be affected.
Thanks to KenS I realized what was wrong with my original approach so I came up with an alternative solution, deferring the execution of the marking operators and calculating the page height beforehand. Below is an incomplete proof of concept of my method of implementing a simple receipt printer with variable page size:
%!
/feed {
0 % return to left margin
currentpoint exch pop % y coordinate
20 sub moveto % feed 20 points
} def
% deferred feed
/_feed {
/feed cvx % push executable name on stack
dup exec % execute procedure, to save position in current point
} def
% deferred show
/_show {
dup % duplicate string
stringwidth rmoveto % simulate position change
/show cvx % push show operator on stack
2 array
astore cvx % create procedure for showing the text
} def
Each time I run the underscore procedures, they will push a procedure on the operand stack, but apply all position changes that will happen during the final execution.
% Set font
/DejaVuSansMono findfont
16 scalefont
setfont
% The receipt itself
0 0 moveto
(text) _show
_feed
(text) _show
_feed
% Save coordinates
currentpoint
/y exch def
/x exch def
% Calculate and set document height based on position
/pageheight y neg def
<< /PageSize [ 100 pageheight ] >> setpagedevice
% Translate the negative y coordinates
0 pageheight 16 sub translate
% reset position
0 0 moveto
% Execute all procedures on the operand stack
count array astore { exec } forall
showpage
The output of this script: the word "text" appearing twice, the image is automatically cut to the right height
It is incomplete of course, but I wanted to demonstrate it the simplest possible way. I hope some will find it interesting/useful.

Postscript image output wrong on some color models

I have written a C code to generate postscript files from PWG raster files. The output is working on (format is color model - bit depth): black-1, black-8, black-16, rgb-8, rgb-16, gray-1, gray-8, gray-16, srgb-8, srgb-16, adobergb-8, sgray-1, sgray-8, cmyk-1, cmyk-8, cmyk-16.
But the output of adobergb-16 and sgray-16 given is wrong. I get the pattern similar to the input file but the colors are all pixelated.
Actual code is very big, so I am posting what I did:
take all the image pixels in an unsigned char* variable (this sometimes becomes very large)
encode the pixels using deflate algorithm from zlib
display the result
For adobergb-16 I am setting PS colorspace to /DeviceRGB and the decode array is /Decode [0 1 0 1 0 1].
For sgray-16 I am setting the PS colorspace to /DeviceGray and the decode is /Decode [0 1]
These setting are similar to adobergb-8 and sgray-8.
EDIT 1:
Adding the example files I used to test HERE
If you want any further information or the code snippets, please feel free to ask.
Well you've set "/BitsPerComponent 16"; as I said above, that's not a legal value, since PostScript only supports 1, 2, 4, 8 and 12 bits per component.
Running this file through Adobe Acrobat Distiller gives:
%%[ Error: rangecheck; OffendingCommand: imageDistiller; ErrorInfo: BitsPerComponent 16 ]%%
Rewriting your image like this:
gsave
/DeviceRGB setcolorspace
/Input currentfile /FlateDecode filter def
4958 7017 scale
<<
/ImageType 1
/Width 4958
/Height 7017
/BitsPerComponent 8
/Decode [0 1 0 1 0 1]
/DataSource {3 string 0 1 2 {1 index exch Input read {pop}if Input read pop put } for} bind
/ImageMatrix [4958 0 0 -7017 0 7017]
>> image
Sets the BitsPerComponent to 8, discards the top byte of every 16-bit value, and the output works as expected.
When I said 'a nice simple small example' I didn't mean 30 MB of data, that is not necessary to exhibit the problem I am certain. When posting examples make a simple, small, example and use that. I haven't bothered to download your other files.
To reiterate; you cannot set /BitsPerComponent 16, PostScript does not support 16 bits per component.

Form property automatically changing on saving changes in VB6 (configured with VSS 2005)

I am facing below issue in VB6 :
When I checkout file file and check "Show differences" it is showing no difference (identical files) but when I save my changes without changing and form property and again check for differences in VSS , it is showing difference in few property.One of them is mentioned below.Kindly suggest.
Begin VB.Label CommStatus
BackColor = &H80000014&
BorderStyle = 1 'Fixed Single
BeginProperty Font
**Name = "Arial"** 'this property is changing
Size = 8.25
Charset = 204
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H000000C0&
Height = 375
Left = 240
TabIndex = 3
ToolTipText = "The most recently detected error"
Top = 360
Width = 7815
End
You can check attach image
After looking in to this, the reason for seems to be Windows zoom setting (100%,125% and 150%, control panel/Make text and other items larger or smaller). If the form is checked in to TFS/VSS/GIT in one zoom setting, and later edited in another, VB6 will change all kind of form properties to adjust for this. So this probably only happens in dev teams with 2+ users that happens to have different screen sizes and therefor different zoom settings.
Only way to avoid this is probably to all use the same zoom setting...

Change cell background color without changing focus

On a form I have 4 MSFlexGrids.
The top grid contains dynamic data, which updates once in a while.
The user can enter data in the cells of the 3 other grids.
The data which is used to fill the top grid is received via a Winsock control, processed, and then the results are written into the appropriate cells using .TextMatrix(intRow, intCol) = strData
This works fine. The data is updated flawlessly, and the user can enter his data into the other 3 grids without any problems.
The problem occurs when I want to change the background color of some cells in the top grid.
On rare occasions the received data is very important, and the background color of the corresponding cells should change color.
I change the color of the cells with the following code:
With grd
For lngRow = 1 To .Rows - 1
'default background color
lngBack = vbWhite
'check for important values
If Val(.TextMatrix(lngRow, 1)) >= lngMax Then
'important color
lngBack = &H3040FF
End If
'select whole row
.Row = lngRow
.Col = 0
.RowSel = lngRow
.ColSel = .Cols - 1
'set the background color of the selected row
.CellBackColor = lngBack
Next lngRow
End With 'grd
The problem with this is that when the user is entering data in the other 3 grids, and the background color of a row in the top grid is changed, then the focus moves to the top grid, and the user has to enter his data anew in the grid where he was working.
Is it possible to change the background color of a cell or whole row in a MSFlexGrid without moving the focus to that grid?
So far I could not find a solution to the problem itself.
I created a work around though :
I created an enum containing a value for each grid:
Public Enum ActiveGrid
enuSystem = 0
enuTel = 1
enuRLN = 2
enuRood = 3
enuData = 4
enuCircuit = 5
End Enum
Whenever a grid gets the focus I save the corresponding enum value in a form level variable.
After coloring the required cells in the first grid I return the focus to the grid which last had it.
The user is not editing in the grid itself, but in a textbox which is laid over the cell, so there is no real problem with the grid losing the focus.
When you look closely though you see the focus leave and return quickly.
For now I will accept this work around, and its minor glitches.
Maybe in the future I can come up with a better solution, or anyone else has a better suggestion?

Changes to a dialog wont appear when i run it in Visual Basic using VB Editor 6.0

I have this huge VB project which i just got from some one. i want to add a check box to a dialog in it so i opened Main2.frm and added a check box using ide. but now when i run the application the dialog resized to its orignal size hence not showing the new check box which is at the bottom. I know that this means somewhere in the code there might be something resizing the dialog box but i have scaned the code and found nothing. where the dialog is being created this is being done:
Main2.vsCodeOptions.Left = 10
Main2.vsCodeOptions.Top = 0
Main2.Move main.Left + (main.Width - Main2.Width) \ 2, main.Top + (main.Height - Main2.Height) \ 2, 3900, 5010
Main2.VSImport.Visible = False
Main2.VSAlload.Visible = False
Main2.VsrepPrt.Visible = False
Main2.VSAbout.Visible = False
Main2.vsCodeOptions.Visible = True
Main2.Left = main.Left + (main.Width - Main2.Width) \ 2
Main2.Top = main.Top + (main.Height - Main2.Height) \ 2
'Use this code to make the form stay on top in the form module:
SetWindowPos Main2.hWnd, HWND_TOPMOST, Main2.Left, Main2.Top, 0, 0, SWP_NOMOVE + SWP_NOSIZE
one more thing i am new to VB and VB editor. i want to all controls in a dialog to move collectively, one method is to select them one by one but i want to select all and then move them to make room for new dialog –
thanks
The first line of your code snippet - doesn't it set the size of Main2? To 3900 x 5010? And then a few lines later you move the form again (to exactly where it is) for no good reason.
I'm a little thrown off by all the \ - should they be / ? Did you type this or paste this?
Try to make the position of the control relative to the Top and Left properties of the form. This way it will always be at the same position no matter what the size of the form is.

Resources