/* This file is part of DITABIS, a File Format plugin for Adobe Photoshop Copyright (C) 2003-6 Toby Thain, toby@telegraphics.com.au This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ //#include #include #include #include #include "ditabis.h" #include "version.h" enum{ MAX_CAPTION = 2L<<10, MAX_KEYWORDS = 2L<<10, IPTC_VERSION = 4, PHOTOSHOP_MARKER = 0x1c, // Photoshop uses this tag marker DATASET_2_VERSION = 00, DATASET_2_KEYWORDS = 25, DATASET_2_CAPTION = 120, DATASET_SIZE = 5 /* number of bytes per dataset */ }; struct iptc_dataset_tag{ unsigned char marker,recordnum,datasetnum,octets[2]; }; extern int headertext,commenttext,headerlines,commentlines; extern long magnification; char *add_dataset(char *p,int marker,int recnum,int datasetnum,char *s,int n); char *add_datasetnum(char *p,int marker,int recnum,int datasetnum,int v); /* Append a standard IPTC dataset. Pass in a pointer to the current end of the data; the function returns the updated end pointer. */ char *add_dataset(char *p,int marker,int recnum,int datasetnum,char *s,int n){ // standard dataset tag *p++ = marker; *p++ = recnum; *p++ = datasetnum; *p++ = n>>8; *p++ = n; // dataset data field memcpy(p,s,n); return p+n; } char *add_datasetnum(char *p,int marker,int recnum,int datasetnum,int v){ char s[2]; s[0] = v>>8; s[1] = v; return add_dataset(p,marker,recnum,datasetnum,s,2); } Handle build_metadata(FormatRecordPtr gpb){ extern struct node_t *firstnode; extern char *magstr; struct node_t *node,*nodetemp; char *iptcrec,*caption,*p,*pc; int n,captionsize,iptcsize; Handle h = 0; static char maglabel[] = "MAGNIFICATION = "; static char program_id[] = "DITABIS File Format plugin http://www.telegraphics.com.au/sw/"; /* What I want is that each Line except the first downto COMMENT is inserted in the Keywords-Section (each Line one Keyword). All the Text that follows COMMENT (may be several lines) shall be inserted in the description field I do not know exactly the english name of this field, as I have the German Version of Photoshop7. In the Photoshop 5 where I have a english version it is CAPTION. This is the field that can be inserted into the printout. If the Magnification is other than 1 then the Magnification shall be inserted also to the description field, so this information can also be printed out. Insert this in the first line, then following the comment. */ captionsize = strlen(maglabel) + strlen(magstr) + 1 + commenttext + commentlines; /* there is one dataset per keyword (header line), one for the caption, and 3 "housekeeping" datasets */ iptcsize = (headerlines+1+3)*DATASET_SIZE + headertext + captionsize + strlen(program_id) + strlen(VERSION_STR) + 2; /*sprintf(s,"headerlines=%d headertext=%d commentlines=%d commenttext=%d captionsize=%d iptcsize=%d", headerlines,headertext,commentlines,commenttext,captionsize,iptcsize); dbg(s);*/ if( (iptcrec = p = malloc(iptcsize)) ){ if( (caption = pc = malloc(captionsize)) ){ #if 0 // Photoshop doesn't seem to bother with the object envelope, so nor will we /* object envelope record = 1 Within record 1:xx, DataSets 1:00, 1:20, 1:22, 1:30, 1:40 and 1:70 are mandatory. */ p = add_num(p, 1,00, 4); // model version p = add_num(p, 1,20, 00); // file format (no object data) p = add_num(p, 1,22, 1); // file format version p = add_tag(p, 1,30, "DITABIS",7); // service identifier p = add_tag(p, 1,40, "00000000",8); // envelope number //p = add_tag(p, 1,70, ...); // date sent time(&now); timerec = gmtime(&now); sprintf(s,"%04%02%02",timerec->tm_year+1900,timerec->tm_mon+1,timerec->tm_mday); p = add_tag(p, 1,70, s,8); // date sent /* application record = 2 */ // p = add_num(p, 2,00, 4); // record version #endif if(magnification != 1 && *magstr){ pc = cat(pc,maglabel); pc = cat(pc,magstr); *pc++ = CR; }//else dbg("NOT adding magnification line to caption"); p = add_datasetnum(p, PHOTOSHOP_MARKER, 2,DATASET_2_VERSION, IPTC_VERSION); // IPTC version number - mandatory for( node = firstnode ; node ; ){ if(node->iscomment){ /* append this text to the caption */ // sprintf(s,"add comment offset=%d",pc-caption); dbg(s); memcpy(pc,node->text,node->length); pc += node->length; *pc++ = CR; }else /* treat it as a keyword */ p = add_dataset(p, PHOTOSHOP_MARKER, 2,DATASET_2_KEYWORDS, node->text,node->length); free(node->text); nodetemp = node; node = node->next; free(nodetemp); } p = add_dataset(p, PHOTOSHOP_MARKER, 2,65, program_id,strlen(program_id)); // originating program p = add_dataset(p, PHOTOSHOP_MARKER, 2,70, VERSION_STR,strlen(VERSION_STR)); // program version p = add_dataset(p, PHOTOSHOP_MARKER, 2,DATASET_2_CAPTION, caption,pc - caption); // caption/abstract n = p - iptcrec; if( (h = PINEWHANDLE(n)) ){ Ptr ptr = PILOCKHANDLE(h,false); memcpy(ptr,iptcrec,n); PIUNLOCKHANDLE(h); } // sprintf(s,"final record size=%d iptcsize=%d",n,iptcsize); dbg(s); free(caption); } free(iptcrec); } return h; }