Skip to content

Commit

Permalink
Add pdf support
Browse files Browse the repository at this point in the history
  • Loading branch information
rfm committed Mar 6, 2024
1 parent c787d26 commit 4fea5f4
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions Tools/xpbs.m
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
"image/svg",
"application/rtf",
"text/richtext",
"text/plain;charset=utf-8"
"text/plain;charset=utf-8",
"application/pdf"
};
static Atom atoms[sizeof(atom_names)/sizeof(char*)];

Expand Down Expand Up @@ -128,6 +129,7 @@
#define XG_MIME_APP_RTF atoms[34]
#define XG_MIME_TEXT_RICHTEXT atoms[35]
#define XG_MIME_UTF8 atoms[36]
#define XG_MIME_PDF atoms[37]

/** Return the GNUstep pasteboard type corresponding to the given atom
* or nil if there is no corresponding type.
Expand Down Expand Up @@ -158,6 +160,11 @@
return NSRTFPboardType;
}

if (XG_MIME_PDF == type)
{
return NSPasteboardTypePDF;
}

if (XG_MIME_PNG == type)
{
return NSPasteboardTypePNG;
Expand Down Expand Up @@ -856,7 +863,11 @@ - (void) pasteboard: (NSPasteboard*)pb provideDataForType: (NSString*)type
else if ([type isEqual: NSPasteboardTypePNG])
{
NSDebugLLog(@"Pbs", @"pasteboard: provideDataForType: - requestData XG_MIME_PNG");
[self requestData: XG_MIME_PNG];
[self requestData: (xType = XG_MIME_PNG)];
}
else if ([type isEqual: NSPasteboardTypePDF])
{
[self requestData: (xType = XG_MIME_PDF)];
}
// FIXME: Support more types
else
Expand Down Expand Up @@ -1331,6 +1342,10 @@ - (void) xSelectionNotify: (XSelectionEvent*)xEvent
{
[self setData: md];
}
else if (actual_type == XG_MIME_PDF)
{
[self setData: md];
}
else if (actual_type == XG_MIME_PNG)
{
[self setData: md];
Expand Down Expand Up @@ -1414,7 +1429,7 @@ - (BOOL) xProvideSelection: (XSelectionRequestEvent*)xEvent
{
unsigned numTypes = 0;
// ATTENTION: Increase this array when adding more types
Atom xTypes[18];
Atom xTypes[19];

/*
* The requestor wants a list of the types we can supply it with.
Expand Down Expand Up @@ -1455,6 +1470,11 @@ - (BOOL) xProvideSelection: (XSelectionRequestEvent*)xEvent
xTypes[numTypes++] = XG_MIME_TIFF;
}

if ([types containsObject: NSPasteboardTypePDF])
{
xTypes[numTypes++] = XG_MIME_PDF;
}

if ([types containsObject: NSPasteboardTypePNG])
{
xTypes[numTypes++] = XG_MIME_PNG;
Expand Down Expand Up @@ -1548,6 +1568,11 @@ - (BOOL) xProvideSelection: (XSelectionRequestEvent*)xEvent
xEvent->target = XG_MIME_TIFF;
[self xProvideSelection: xEvent];
}
else if ([types containsObject: NSPasteboardTypePDF])
{
xEvent->target = XG_MIME_PDF;
[self xProvideSelection: xEvent];
}
else if ([types containsObject: NSPasteboardTypePNG])
{
xEvent->target = XG_MIME_PNG;
Expand Down Expand Up @@ -1691,6 +1716,14 @@ - (BOOL) xProvideSelection: (XSelectionRequestEvent*)xEvent
format = 8;
numItems = [data length];
}
else if ((xEvent->target == XG_MIME_PDF)
&& [types containsObject: NSPasteboardTypePDF])
{
data = [_pb dataForType: NSPasteboardTypePDF];
xType = xEvent->target;
format = 8;
numItems = [data length];
}
else if ((xEvent->target == XG_MIME_PNG)
&& [types containsObject: NSPasteboardTypePNG])
{
Expand Down

0 comments on commit 4fea5f4

Please sign in to comment.