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:
fredkiefer 2014-06-15 21:38:40 +00:00
parent b278884e92
commit 101259e3e4
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> 2014-06-09 Fred Kiefer <FredKiefer@gmx.de>
* Source/externs.m: Correct many string values that where * 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) appendString: (NSString*)string;
- (void) appendHelpLink: (NSString*)fileName marker: (NSString *)markerName; - (void) appendHelpLink: (NSString*)fileName marker: (NSString *)markerName;
- (void) appendHelpMarker: (NSString*)markerName; - (void) appendHelpMarker: (NSString*)markerName;
- (void) appendField: (NSString*)instruction
result: (NSString*)result;
- (void) reset; - (void) reset;
@end @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 @end
#undef IGNORE #undef IGNORE
@ -1349,3 +1385,21 @@ void GSRTFNeXTHelpMarker (void *ctxt, int num, const char *markername)
[(RTFDConsumer *)ctxt appendHelpMarker: 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 */ /* NeXTHelpMarker */
void GSRTFNeXTHelpMarker(void *ctxt, int num, const char *markername); void GSRTFNeXTHelpMarker(void *ctxt, int num, const char *markername);
void GSRTFaddField (void *ctxt, const char *inst, const char *result);
#endif #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. */ /* Bison interface for Yacc-like parsers in C
/* Skeleton interface for Bison's Yacc-like parsers in C Copyright (C) 1984, 1989-1990, 2000-2012 Free Software Foundation, Inc.
Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify 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 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 This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */ 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. */ /* Tokens. */
#ifndef YYTOKENTYPE #ifndef YYTOKENTYPE
@ -63,87 +70,94 @@
RTFemspace = 279, RTFemspace = 279,
RTFenspace = 280, RTFenspace = 280,
RTFbullet = 281, RTFbullet = 281,
RTFlquote = 282, RTFfield = 282,
RTFrquote = 283, RTFfldinst = 283,
RTFldblquote = 284, RTFfldalt = 284,
RTFrdblquote = 285, RTFfldrslt = 285,
RTFred = 286, RTFflddirty = 286,
RTFgreen = 287, RTFfldedit = 287,
RTFblue = 288, RTFfldlock = 288,
RTFcolorbg = 289, RTFfldpriv = 289,
RTFcolorfg = 290, RTFfttruetype = 290,
RTFunderlinecolor = 291, RTFlquote = 291,
RTFcolortable = 292, RTFrquote = 292,
RTFfont = 293, RTFldblquote = 293,
RTFfontSize = 294, RTFrdblquote = 294,
RTFNeXTGraphic = 295, RTFred = 295,
RTFNeXTGraphicWidth = 296, RTFgreen = 296,
RTFNeXTGraphicHeight = 297, RTFblue = 297,
RTFNeXTHelpLink = 298, RTFcolorbg = 298,
RTFNeXTHelpMarker = 299, RTFcolorfg = 299,
RTFNeXTfilename = 300, RTFunderlinecolor = 300,
RTFNeXTmarkername = 301, RTFcolortable = 301,
RTFNeXTlinkFilename = 302, RTFfont = 302,
RTFNeXTlinkMarkername = 303, RTFfontSize = 303,
RTFpaperWidth = 304, RTFNeXTGraphic = 304,
RTFpaperHeight = 305, RTFNeXTGraphicWidth = 305,
RTFmarginLeft = 306, RTFNeXTGraphicHeight = 306,
RTFmarginRight = 307, RTFNeXTHelpLink = 307,
RTFmarginTop = 308, RTFNeXTHelpMarker = 308,
RTFmarginButtom = 309, RTFNeXTfilename = 309,
RTFfirstLineIndent = 310, RTFNeXTmarkername = 310,
RTFleftIndent = 311, RTFNeXTlinkFilename = 311,
RTFrightIndent = 312, RTFNeXTlinkMarkername = 312,
RTFalignCenter = 313, RTFpaperWidth = 313,
RTFalignJustified = 314, RTFpaperHeight = 314,
RTFalignLeft = 315, RTFmarginLeft = 315,
RTFalignRight = 316, RTFmarginRight = 316,
RTFlineSpace = 317, RTFmarginTop = 317,
RTFspaceAbove = 318, RTFmarginButtom = 318,
RTFstyle = 319, RTFfirstLineIndent = 319,
RTFbold = 320, RTFleftIndent = 320,
RTFitalic = 321, RTFrightIndent = 321,
RTFunderline = 322, RTFalignCenter = 322,
RTFunderlineDot = 323, RTFalignJustified = 323,
RTFunderlineDash = 324, RTFalignLeft = 324,
RTFunderlineDashDot = 325, RTFalignRight = 325,
RTFunderlineDashDotDot = 326, RTFlineSpace = 326,
RTFunderlineDouble = 327, RTFspaceAbove = 327,
RTFunderlineStop = 328, RTFstyle = 328,
RTFunderlineThick = 329, RTFbold = 329,
RTFunderlineThickDot = 330, RTFitalic = 330,
RTFunderlineThickDash = 331, RTFunderline = 331,
RTFunderlineThickDashDot = 332, RTFunderlineDot = 332,
RTFunderlineThickDashDotDot = 333, RTFunderlineDash = 333,
RTFunderlineWord = 334, RTFunderlineDashDot = 334,
RTFstrikethrough = 335, RTFunderlineDashDotDot = 335,
RTFstrikethroughDouble = 336, RTFunderlineDouble = 336,
RTFunichar = 337, RTFunderlineStop = 337,
RTFsubscript = 338, RTFunderlineThick = 338,
RTFsuperscript = 339, RTFunderlineThickDot = 339,
RTFtabstop = 340, RTFunderlineThickDash = 340,
RTFfcharset = 341, RTFunderlineThickDashDot = 341,
RTFfprq = 342, RTFunderlineThickDashDotDot = 342,
RTFcpg = 343, RTFunderlineWord = 343,
RTFOtherStatement = 344, RTFstrikethrough = 344,
RTFfontListStart = 345, RTFstrikethroughDouble = 345,
RTFfamilyNil = 346, RTFunichar = 346,
RTFfamilyRoman = 347, RTFsubscript = 347,
RTFfamilySwiss = 348, RTFsuperscript = 348,
RTFfamilyModern = 349, RTFtabstop = 349,
RTFfamilyScript = 350, RTFfcharset = 350,
RTFfamilyDecor = 351, RTFfprq = 351,
RTFfamilyTech = 352 RTFcpg = 352,
RTFOtherStatement = 353,
RTFfontListStart = 354,
RTFfamilyNil = 355,
RTFfamilyRoman = 356,
RTFfamilySwiss = 357,
RTFfamilyModern = 358,
RTFfamilyScript = 359,
RTFfamilyDecor = 360,
RTFfamilyTech = 361
}; };
#endif #endif
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE typedef union YYSTYPE
{ {
/* Line 2058 of yacc.c */
/* Line 1676 of yacc.c */
#line 82 "rtfGrammar.y" #line 82 "rtfGrammar.y"
int number; int number;
@ -151,9 +165,8 @@ typedef union YYSTYPE
RTFcmd cmd; RTFcmd cmd;
/* Line 2058 of yacc.c */
/* Line 1676 of yacc.c */ #line 170 "rtfGrammar.tab.h"
#line 157 "rtfGrammar.tab.h"
} YYSTYPE; } YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1 # define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */ # define yystype YYSTYPE /* obsolescent; will be withdrawn */
@ -161,5 +174,18 @@ typedef union YYSTYPE
#endif #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 CTXT ctxt
#define YYERROR_VERBOSE #define YYERROR_VERBOSE
#define YYDEBUG 0 #define YYDEBUG 1
#include "RTFConsumerFunctions.h" #include "RTFConsumerFunctions.h"
/*int GSRTFlex (YYSTYPE *lvalp, RTFscannerCtxt *lctxt); */ /*int GSRTFlex (YYSTYPE *lvalp, RTFscannerCtxt *lctxt); */
@ -110,6 +110,15 @@ int GSRTFlex(void *lvalp, void *lctxt);
%token RTFemspace %token RTFemspace
%token RTFenspace %token RTFenspace
%token RTFbullet %token RTFbullet
%token RTFfield
%token RTFfldinst
%token RTFfldalt
%token RTFfldrslt
%token RTFflddirty
%token RTFfldedit
%token RTFfldlock
%token RTFfldpriv
%token RTFfttruetype
%token RTFlquote %token RTFlquote
%token RTFrquote %token RTFrquote
%token RTFldblquote %token RTFldblquote
@ -187,6 +196,7 @@ int GSRTFlex(void *lvalp, void *lctxt);
%token RTFfamilyTech %token RTFfamilyTech
%type <number> rtfFontFamily rtfCharset rtfFontStatement %type <number> rtfFontFamily rtfCharset rtfFontStatement
%type <text> rtfFieldinst rtfFieldrslt
/* let's go */ /* 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); } RTFheader rtfIngredients '}' { GSRTFcloseBlock(CTXT, YES); }
| '{' { GSRTFopenBlock(CTXT, YES); } RTFfooter rtfIngredients '}' { GSRTFcloseBlock(CTXT, YES); } | '{' { GSRTFopenBlock(CTXT, YES); } RTFfooter rtfIngredients '}' { GSRTFcloseBlock(CTXT, YES); }
| '{' { GSRTFopenBlock(CTXT, YES); } RTFpict rtfIngredients '}' { GSRTFcloseBlock(CTXT, YES); } | '{' { GSRTFopenBlock(CTXT, YES); } RTFpict rtfIngredients '}' { GSRTFcloseBlock(CTXT, YES); }
| '{' { GSRTFopenBlock(CTXT, NO); } RTFfield rtfField '}' { GSRTFcloseBlock(CTXT, NO); }
| '{' error '}' | '{' 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 RTF statements start with a '\', have a alpha name and a number argument
*/ */
@ -548,6 +593,7 @@ rtfFontAttrs: /* empty */
| rtfFontAttrs RTFfcharset | rtfFontAttrs RTFfcharset
| rtfFontAttrs RTFfprq | rtfFontAttrs RTFfprq
| rtfFontAttrs RTFcpg | rtfFontAttrs RTFcpg
| rtfFontAttrs RTFfttruetype
| rtfFontAttrs rtfBlock | rtfFontAttrs rtfBlock
; ;

View file

@ -180,7 +180,15 @@ LexKeyword RTFcommands[] =
{"fcharset", token(RTFfcharset)}, {"fcharset", token(RTFfcharset)},
{"fdecor", token(RTFfamilyDecor)}, {"fdecor", token(RTFfamilyDecor)},
{"fi", token(RTFfirstLineIndent)}, {"fi", token(RTFfirstLineIndent)},
{"field", token(RTFfield)},
{"filename", token(RTFNeXTfilename)}, {"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)}, {"fmodern", token(RTFfamilyModern)},
{"fnil", token(RTFfamilyNil)}, {"fnil", token(RTFfamilyNil)},
{"fonttbl", token(RTFfontListStart)}, {"fonttbl", token(RTFfontListStart)},
@ -196,6 +204,7 @@ LexKeyword RTFcommands[] =
{"fscript", token(RTFfamilyScript)}, {"fscript", token(RTFfamilyScript)},
{"fswiss", token(RTFfamilySwiss)}, {"fswiss", token(RTFfamilySwiss)},
{"ftech", token(RTFfamilyTech)}, {"ftech", token(RTFfamilyTech)},
{"fttruetype", token(RTFfttruetype)},
{"green", token(RTFgreen)}, {"green", token(RTFgreen)},
/* All headers are mapped on one entry */ /* All headers are mapped on one entry */
{"header", token(RTFheader)}, {"header", token(RTFheader)},