Add support to parse link fields in RTF. This enables copying of links

in NSTextView.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@37946 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Fred Kiefer 2014-06-15 21:38:40 +00:00
parent 6cfc4f8367
commit b48b73ee82
7 changed files with 1637 additions and 1339 deletions

View file

@ -1,3 +1,12 @@
2014-06-15 Fred Kiefer <FredKiefer@gmx.de>
* TextConverters/RTF/rtfScanner.m,
* TextConverters/RTF/rtfGrammar.y,
* TextConverters/RTF/RTFConsumerFunctions.h,
* TextConverters/RTF/RTFConsumer.m: Add support for parsing link fields.
* TextConverters/RTF/rtfGrammar.tab.h,
* TextConverters/RTF/rtfGrammar.tab.m: Regenerated.
2014-06-09 Fred Kiefer <FredKiefer@gmx.de>
* Source/externs.m: Correct many string values that where

View file

@ -284,6 +284,8 @@ static BOOL classInheritsFromNSMutableAttributedString (Class c)
- (void) appendString: (NSString*)string;
- (void) appendHelpLink: (NSString*)fileName marker: (NSString *)markerName;
- (void) appendHelpMarker: (NSString*)markerName;
- (void) appendField: (NSString*)instruction
result: (NSString*)result;
- (void) reset;
@end
@ -778,6 +780,40 @@ static BOOL classInheritsFromNSMutableAttributedString (Class c)
}
}
- (void) appendField: (NSString*)instruction
result: (NSString*)fieldResult
{
if (!ignore)
{
int oldPosition = [result length];
int textlen = [fieldResult length];
NSRange insertionRange = NSMakeRange(oldPosition, textlen);
[self appendString: fieldResult];
if ([instruction hasPrefix: @"HYPERLINK "])
{
NSDictionary *attributes;
NSString *link = [instruction substringFromIndex: 10];
if ([link characterAtIndex: 0] == (unichar)'\"')
{
link = [link substringWithRange: NSMakeRange(1, [link length] - 2)];
}
attributes = [[NSDictionary alloc]
initWithObjectsAndKeys:
link, NSLinkAttributeName,
[NSNumber numberWithInt : 1], NSUnderlineStyleAttributeName,
[NSColor blueColor], NSForegroundColorAttributeName,
nil];
[result addAttributes: attributes
range: insertionRange];
DESTROY(attributes);
}
}
}
@end
#undef IGNORE
@ -1349,3 +1385,21 @@ void GSRTFNeXTHelpMarker (void *ctxt, int num, const char *markername)
[(RTFDConsumer *)ctxt appendHelpMarker: markerName];
}
void GSRTFaddField (void *ctxt, const char *inst, const char *result)
{
NSString *fieldResult = [[NSString alloc] initWithCString: result
encoding: ENCODING];
NSString *fieldInstruction;
// Ignore leading blanks
while (inst[0] == ' ')
{
inst++;
}
fieldInstruction = [[NSString alloc] initWithCString: inst
encoding: ENCODING];
[(RTFDConsumer *)ctxt appendField: fieldInstruction result: fieldResult];
DESTROY(fieldInstruction);
DESTROY(fieldResult);
}

View file

@ -147,5 +147,7 @@ void GSRTFNeXTHelpLink(void *ctxt, int num, const char *markername,
/* NeXTHelpMarker */
void GSRTFNeXTHelpMarker(void *ctxt, int num, const char *markername);
void GSRTFaddField (void *ctxt, const char *inst, const char *result);
#endif

View file

@ -1,10 +1,8 @@
/* A Bison parser, made by GNU Bison 2.7. */
/* A Bison parser, made by GNU Bison 2.4.1. */
/* Skeleton interface for Bison's Yacc-like parsers in C
/* Bison interface for Yacc-like parsers in C
Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
Free Software Foundation, Inc.
Copyright (C) 1984, 1989-1990, 2000-2012 Free Software Foundation, Inc.
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
@ -32,6 +30,15 @@
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
#ifndef YY_GSRTF_RTFGRAMMAR_TAB_H_INCLUDED
# define YY_GSRTF_RTFGRAMMAR_TAB_H_INCLUDED
/* Enabling traces. */
#ifndef YYDEBUG
# define YYDEBUG 0
#endif
#if YYDEBUG
extern int GSRTFdebug;
#endif
/* Tokens. */
#ifndef YYTOKENTYPE
@ -63,87 +70,94 @@
RTFemspace = 279,
RTFenspace = 280,
RTFbullet = 281,
RTFlquote = 282,
RTFrquote = 283,
RTFldblquote = 284,
RTFrdblquote = 285,
RTFred = 286,
RTFgreen = 287,
RTFblue = 288,
RTFcolorbg = 289,
RTFcolorfg = 290,
RTFunderlinecolor = 291,
RTFcolortable = 292,
RTFfont = 293,
RTFfontSize = 294,
RTFNeXTGraphic = 295,
RTFNeXTGraphicWidth = 296,
RTFNeXTGraphicHeight = 297,
RTFNeXTHelpLink = 298,
RTFNeXTHelpMarker = 299,
RTFNeXTfilename = 300,
RTFNeXTmarkername = 301,
RTFNeXTlinkFilename = 302,
RTFNeXTlinkMarkername = 303,
RTFpaperWidth = 304,
RTFpaperHeight = 305,
RTFmarginLeft = 306,
RTFmarginRight = 307,
RTFmarginTop = 308,
RTFmarginButtom = 309,
RTFfirstLineIndent = 310,
RTFleftIndent = 311,
RTFrightIndent = 312,
RTFalignCenter = 313,
RTFalignJustified = 314,
RTFalignLeft = 315,
RTFalignRight = 316,
RTFlineSpace = 317,
RTFspaceAbove = 318,
RTFstyle = 319,
RTFbold = 320,
RTFitalic = 321,
RTFunderline = 322,
RTFunderlineDot = 323,
RTFunderlineDash = 324,
RTFunderlineDashDot = 325,
RTFunderlineDashDotDot = 326,
RTFunderlineDouble = 327,
RTFunderlineStop = 328,
RTFunderlineThick = 329,
RTFunderlineThickDot = 330,
RTFunderlineThickDash = 331,
RTFunderlineThickDashDot = 332,
RTFunderlineThickDashDotDot = 333,
RTFunderlineWord = 334,
RTFstrikethrough = 335,
RTFstrikethroughDouble = 336,
RTFunichar = 337,
RTFsubscript = 338,
RTFsuperscript = 339,
RTFtabstop = 340,
RTFfcharset = 341,
RTFfprq = 342,
RTFcpg = 343,
RTFOtherStatement = 344,
RTFfontListStart = 345,
RTFfamilyNil = 346,
RTFfamilyRoman = 347,
RTFfamilySwiss = 348,
RTFfamilyModern = 349,
RTFfamilyScript = 350,
RTFfamilyDecor = 351,
RTFfamilyTech = 352
RTFfield = 282,
RTFfldinst = 283,
RTFfldalt = 284,
RTFfldrslt = 285,
RTFflddirty = 286,
RTFfldedit = 287,
RTFfldlock = 288,
RTFfldpriv = 289,
RTFfttruetype = 290,
RTFlquote = 291,
RTFrquote = 292,
RTFldblquote = 293,
RTFrdblquote = 294,
RTFred = 295,
RTFgreen = 296,
RTFblue = 297,
RTFcolorbg = 298,
RTFcolorfg = 299,
RTFunderlinecolor = 300,
RTFcolortable = 301,
RTFfont = 302,
RTFfontSize = 303,
RTFNeXTGraphic = 304,
RTFNeXTGraphicWidth = 305,
RTFNeXTGraphicHeight = 306,
RTFNeXTHelpLink = 307,
RTFNeXTHelpMarker = 308,
RTFNeXTfilename = 309,
RTFNeXTmarkername = 310,
RTFNeXTlinkFilename = 311,
RTFNeXTlinkMarkername = 312,
RTFpaperWidth = 313,
RTFpaperHeight = 314,
RTFmarginLeft = 315,
RTFmarginRight = 316,
RTFmarginTop = 317,
RTFmarginButtom = 318,
RTFfirstLineIndent = 319,
RTFleftIndent = 320,
RTFrightIndent = 321,
RTFalignCenter = 322,
RTFalignJustified = 323,
RTFalignLeft = 324,
RTFalignRight = 325,
RTFlineSpace = 326,
RTFspaceAbove = 327,
RTFstyle = 328,
RTFbold = 329,
RTFitalic = 330,
RTFunderline = 331,
RTFunderlineDot = 332,
RTFunderlineDash = 333,
RTFunderlineDashDot = 334,
RTFunderlineDashDotDot = 335,
RTFunderlineDouble = 336,
RTFunderlineStop = 337,
RTFunderlineThick = 338,
RTFunderlineThickDot = 339,
RTFunderlineThickDash = 340,
RTFunderlineThickDashDot = 341,
RTFunderlineThickDashDotDot = 342,
RTFunderlineWord = 343,
RTFstrikethrough = 344,
RTFstrikethroughDouble = 345,
RTFunichar = 346,
RTFsubscript = 347,
RTFsuperscript = 348,
RTFtabstop = 349,
RTFfcharset = 350,
RTFfprq = 351,
RTFcpg = 352,
RTFOtherStatement = 353,
RTFfontListStart = 354,
RTFfamilyNil = 355,
RTFfamilyRoman = 356,
RTFfamilySwiss = 357,
RTFfamilyModern = 358,
RTFfamilyScript = 359,
RTFfamilyDecor = 360,
RTFfamilyTech = 361
};
#endif
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE
{
/* Line 1676 of yacc.c */
/* Line 2058 of yacc.c */
#line 82 "rtfGrammar.y"
int number;
@ -151,9 +165,8 @@ typedef union YYSTYPE
RTFcmd cmd;
/* Line 1676 of yacc.c */
#line 157 "rtfGrammar.tab.h"
/* Line 2058 of yacc.c */
#line 170 "rtfGrammar.tab.h"
} YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
@ -161,5 +174,18 @@ typedef union YYSTYPE
#endif
#ifdef YYPARSE_PARAM
#if defined __STDC__ || defined __cplusplus
int GSRTFparse (void *YYPARSE_PARAM);
#else
int GSRTFparse ();
#endif
#else /* ! YYPARSE_PARAM */
#if defined __STDC__ || defined __cplusplus
int GSRTFparse (void *ctxt, void *lctxt);
#else
int GSRTFparse ();
#endif
#endif /* ! YYPARSE_PARAM */
#endif /* !YY_GSRTF_RTFGRAMMAR_TAB_H_INCLUDED */

File diff suppressed because it is too large Load diff

View file

@ -68,7 +68,7 @@ typedef void *GSRTFctxt;
#define CTXT ctxt
#define YYERROR_VERBOSE
#define YYDEBUG 0
#define YYDEBUG 1
#include "RTFConsumerFunctions.h"
/*int GSRTFlex (YYSTYPE *lvalp, RTFscannerCtxt *lctxt); */
@ -110,6 +110,15 @@ int GSRTFlex(void *lvalp, void *lctxt);
%token RTFemspace
%token RTFenspace
%token RTFbullet
%token RTFfield
%token RTFfldinst
%token RTFfldalt
%token RTFfldrslt
%token RTFflddirty
%token RTFfldedit
%token RTFfldlock
%token RTFfldpriv
%token RTFfttruetype
%token RTFlquote
%token RTFrquote
%token RTFldblquote
@ -187,6 +196,7 @@ int GSRTFlex(void *lvalp, void *lctxt);
%token RTFfamilyTech
%type <number> rtfFontFamily rtfCharset rtfFontStatement
%type <text> rtfFieldinst rtfFieldrslt
/* let's go */
@ -220,10 +230,45 @@ rtfBlock: '{' { GSRTFopenBlock(CTXT, NO); } rtfIngredients rtfNeXTstuff '}' { GS
| '{' { GSRTFopenBlock(CTXT, YES); } RTFheader rtfIngredients '}' { GSRTFcloseBlock(CTXT, YES); }
| '{' { GSRTFopenBlock(CTXT, YES); } RTFfooter rtfIngredients '}' { GSRTFcloseBlock(CTXT, YES); }
| '{' { GSRTFopenBlock(CTXT, YES); } RTFpict rtfIngredients '}' { GSRTFcloseBlock(CTXT, YES); }
| '{' { GSRTFopenBlock(CTXT, NO); } RTFfield rtfField '}' { GSRTFcloseBlock(CTXT, NO); }
| '{' error '}'
;
rtfField: rtfFieldMod rtfFieldinst rtfFieldrslt { GSRTFaddField(CTXT, $2, $3); free((void *)$2); free((void *)$3); }
| error
;
rtfFieldMod: /* empty */
| rtfFieldMod RTFflddirty
| rtfFieldMod RTFfldedit
| rtfFieldMod RTFfldlock
| rtfFieldMod RTFfldpriv
;
rtfIgnore: /* empty */
| RTFignore
;
rtfFieldinst: '{' rtfIgnore RTFfldinst RTFtext rtfFieldalt '}' { $$ = $4;}
| '{' rtfIgnore RTFfldinst '{' { GSRTFopenBlock(CTXT, YES); } rtfStatementList RTFtext rtfFieldalt '}' { GSRTFcloseBlock(CTXT, YES); } '}' { $$ = $7;}
| '{' error '}' { $$ = NULL;}
;
rtfFieldalt: /* empty */
| RTFfldalt
;
rtfFieldrslt: '{' rtfIgnore RTFfldrslt RTFtext '}' { $$ = $4;}
| '{' rtfIgnore RTFfldrslt '{' rtfStatementList RTFtext '}' '}' { $$ = $6;}
| '{' error '}' { $$ = NULL;}
;
rtfStatementList: /* empty */
| rtfStatementList rtfStatement
| rtfStatementList rtfBlock
;
/*
RTF statements start with a '\', have a alpha name and a number argument
*/
@ -548,6 +593,7 @@ rtfFontAttrs: /* empty */
| rtfFontAttrs RTFfcharset
| rtfFontAttrs RTFfprq
| rtfFontAttrs RTFcpg
| rtfFontAttrs RTFfttruetype
| rtfFontAttrs rtfBlock
;

View file

@ -180,7 +180,15 @@ LexKeyword RTFcommands[] =
{"fcharset", token(RTFfcharset)},
{"fdecor", token(RTFfamilyDecor)},
{"fi", token(RTFfirstLineIndent)},
{"field", token(RTFfield)},
{"filename", token(RTFNeXTfilename)},
{"fldalt", token(RTFfldalt)},
{"flddirty", token(RTFflddirty)},
{"fldedit", token(RTFfldedit)},
{"fldinst", token(RTFfldinst)},
{"fldlock", token(RTFfldlock)},
{"fldpriv", token(RTFfldpriv)},
{"fldrslt", token(RTFfldrslt)},
{"fmodern", token(RTFfamilyModern)},
{"fnil", token(RTFfamilyNil)},
{"fonttbl", token(RTFfontListStart)},
@ -196,6 +204,7 @@ LexKeyword RTFcommands[] =
{"fscript", token(RTFfamilyScript)},
{"fswiss", token(RTFfamilySwiss)},
{"ftech", token(RTFfamilyTech)},
{"fttruetype", token(RTFfttruetype)},
{"green", token(RTFgreen)},
/* All headers are mapped on one entry */
{"header", token(RTFheader)},