diff --git a/TextConverters/DOCX/.cvsignore b/TextConverters/DOCX/.cvsignore new file mode 100644 index 000000000..c9fbf56a0 --- /dev/null +++ b/TextConverters/DOCX/.cvsignore @@ -0,0 +1,6 @@ +*obj +*.app +*.debug +*.profile +.gdbinit +*.bundle diff --git a/TextConverters/DOCX/DOCXConsumer.h b/TextConverters/DOCX/DOCXConsumer.h new file mode 100644 index 000000000..a8d3e3319 --- /dev/null +++ b/TextConverters/DOCX/DOCXConsumer.h @@ -0,0 +1,51 @@ +/* docxConsumer.h created by gcasa Feb-2025 + + Copyright (C) 2025 Free Software Foundation, Inc. + + Author: Gregory John Casamento + Date: Feb 2025 + + This file is part of the GNUstep GUI Library. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; see the file COPYING.LIB. + If not, see or write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef _docxConsumer_h_INCLUDE +#define _docxConsumer_h_INCLUDE + +#include + +@class NSMutableDictionary; +@class NSMutableArray; +@class NSMutableAttributedString; + +@interface DOCXConsumer: NSObject +{ +@public + NSStringEncoding encoding; + NSMutableDictionary *documentAttributes; + NSMutableDictionary *fonts; + NSMutableArray *colours; + NSMutableArray *attrs; + NSMutableAttributedString *result; + Class _class; + int ignore; +} + +@end + +#endif diff --git a/TextConverters/DOCX/DOCXConsumer.m b/TextConverters/DOCX/DOCXConsumer.m new file mode 100644 index 000000000..c7a91a415 --- /dev/null +++ b/TextConverters/DOCX/DOCXConsumer.m @@ -0,0 +1,94 @@ +/* attributedStringConsumer.m + + Copyright (C) 1999 Free Software Foundation, Inc. + + Author: Stefan Böhringer (stefan.boehringer@uni-bochum.de) + Date: Dec 1999 + Author: Fred Kiefer + Date: June 2000 + + This file is part of the GNUstep GUI Library. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; see the file COPYING.LIB. + If not, see or write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#import +#import +#import + +#import "DOCXConsumer.h" +// #import "DOCXConsumerFunctions.h" +#import "DOCXProducer.h" + +@implementation DOCXConsumer + +/* RTFConsumer is the principal class and thus implements this */ ++ (Class) classForFormat: (NSString *)format producer: (BOOL)flag +{ + Class cClass = Nil; + + return cClass; +} + ++ (NSAttributedString*) parseFile: (NSFileWrapper *)wrapper + options: (NSDictionary *)options + documentAttributes: (NSDictionary **)dict + error: (NSError **)error + class: (Class)class +{ + NSAttributedString *text = nil; + + return text; +} + ++ (NSAttributedString*) parseData: (NSData *)rtfData + options: (NSDictionary *)options + documentAttributes: (NSDictionary **)dict + error: (NSError **)error + class: (Class)class +{ + // DOCXConsumer *consumer = [DOCXConsumer new]; + NSAttributedString *text = nil; + + return text; +} + +- (id) init +{ + ignore = 0; + result = nil; + encoding = NSISOLatin1StringEncoding; + documentAttributes = nil; + fonts = nil; + attrs = nil; + colours = nil; + _class = Nil; + + return self; +} + +- (void) dealloc +{ + RELEASE(fonts); + RELEASE(attrs); + RELEASE(colours); + RELEASE(result); + RELEASE(documentAttributes); + [super dealloc]; +} + +@end diff --git a/TextConverters/DOCX/DOCXConsumerFunctions.h b/TextConverters/DOCX/DOCXConsumerFunctions.h new file mode 100644 index 000000000..eae8ac13a --- /dev/null +++ b/TextConverters/DOCX/DOCXConsumerFunctions.h @@ -0,0 +1,159 @@ +/* docxConsumerFunctions.h created by pingu on Wed 17-Nov-1999 + + Copyright (C) 1999 Free Software Foundation, Inc. + + Author: Stefan Böhringer (stefan.boehringer@uni-bochum.de) + Date: Dec 1999 + + This file is part of the GNUstep GUI Library. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; see the file COPYING.LIB. + If not, see or write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +/* here we define the interface functions to grammer consumers */ + +#ifndef docxConsumerFunctions_h_INCLUDE +#define docxConsumerFunctions_h_INCLUDE + +#include "docxScanner.h" + +/* general statements: + * measurement is usually in twips: one twentieth of a point (this is + * about 0.01764 mm) a tabstop of 540 twips (as it occurs on NeXT) is + * therefore about 0.95 cm + */ +#define halfpoints2points(a) ((a)/2.0) +#define twips2points(a) ((a)/20.0) +#define twips2mm(a) ((a)*0.01764) + +/* prepare the ctxt, or whatever you want */ +void GSDOCXstart(void *ctxt); + +/* seal the parsing process, the context or whatever you want */ +void GSDOCXstop(void *ctxt); + +/* */ +int GSDOCXgetPosition(void *ctxt); + +/* + * those pairing functions enclose DOCXBlocks. Use it to capture the + * hierarchical attribute changes of blocks. i.e. attributes of a + * block are forgotten once a block is closed + */ +void GSDOCXopenBlock(void *ctxt, BOOL ignore); +void GSDOCXcloseBlock(void *ctxt, BOOL ignore); + +/* handle errors */ +void GSDOCXerror(void *ctxt, void *lctxt, const char *msg); + +/* handle docx commands not expicated in the grammer */ +void GSDOCXgenericDOCXcommand(void *ctxt, DOCXcmd cmd); + +/* go, handle text */ +void GSDOCXmangleText(void *ctxt, const char *text); +void GSDOCXunicode (void *ctxt, int uchar); + +/* + * font functions + */ + +/* get noticed that a particular font is introduced */ +void GSDOCXregisterFont(void *ctxt, const char *fontName, + DOCXfontFamily family, int fontNumber); + +/* change font number */ +void GSDOCXfontNumber(void *ctxt, int fontNumber); +/* change font size in half points*/ +void GSDOCXfontSize(void *ctxt, int fontSize); + +/* set paper width in twips */ +void GSDOCXpaperWidth(void *ctxt, int width); +/* set paper height in twips */ +void GSDOCXpaperHeight(void *ctxt, int height); +/* set left margin in twips */ +void GSDOCXmarginLeft(void *ctxt, int margin); +/* set right margin in twips */ +void GSDOCXmarginRight(void *ctxt, int margin); +/* set top margin in twips */ +void GSDOCXmarginTop(void *ctxt, int margin); +/* set buttom margin in twips */ +void GSDOCXmarginButtom(void *ctxt, int margin); +/* set first line indent */ +void GSDOCXfirstLineIndent(void *ctxt, int indent); +/* set left indent */ +void GSDOCXleftIndent(void *ctxt, int indent); +/* set right indent */ +void GSDOCXrightIndent(void *ctxt, int indent); +/* set tabstop */ +void GSDOCXtabstop(void *ctxt, int location); +/* set center alignment */ +void GSDOCXalignCenter(void *ctxt); +/* set justified alignment */ +void GSDOCXalignJustified(void *ctxt); +/* set left alignment */ +void GSDOCXalignLeft(void *ctxt); +/* set right alignment */ +void GSDOCXalignRight(void *ctxt); +/* set space above */ +void GSDOCXspaceAbove(void *ctxt, int location); +/* set line space */ +void GSDOCXlineSpace(void *ctxt, int location); +/* set default paragraph style */ +void GSDOCXdefaultParagraph(void *ctxt); +/* set paragraph style */ +void GSDOCXstyle(void *ctxt, int style); +/* Add a colour to the colour table*/ +void GSDOCXaddColor(void *ctxt, int red, int green, int blue); +/* Add the default colour to the colour table*/ +void GSDOCXaddDefaultColor(void *ctxt); +/* set background colour */ +void GSDOCXcolorbg(void *ctxt, int color); +/* set foreground colour */ +void GSDOCXcolorfg(void *ctxt, int color); +/* set underline colour */ +void GSDOCXunderlinecolor(void *ctxt, int color); +/* set default character style */ +void GSDOCXdefaultCharacterStyle(void *ctxt); +/* set subscript in half points */ +void GSDOCXsubscript(void *ctxt, int script); +/* set superscript in half points */ +void GSDOCXsuperscript(void *ctxt, int script); +/* Switch bold mode on or off */ +void GSDOCXbold(void *ctxt, BOOL on); +/* Switch italic mode on or off */ +void GSDOCXitalic(void *ctxt, BOOL on); +/* Set the underline style */ +void GSDOCXunderline(void *ctxt, BOOL on, NSInteger style); +/* Set the strikethrough style */ +void GSDOCXstrikethrough(void *ctxt, NSInteger style); +/* new paragraph */ +void GSDOCXparagraph(void *ctxt); +/* NeXTGraphic */ +void GSDOCXNeXTGraphic(void *ctxt, const char *fileName, int width, int height); +/* NeXTHelpLink */ +void GSDOCXNeXTHelpLink(void *ctxt, int num, const char *markername, + const char *linkFilename, const char *linkMarkername); +/* NeXTHelpMarker */ +void GSDOCXNeXTHelpMarker(void *ctxt, int num, const char *markername); + +void GSDOCXaddField (void *ctxt, int start, const char *inst); + +/* set encoding */ +void GSDOCXencoding(void *ctxt, int encoding); + +#endif + diff --git a/TextConverters/DOCX/DOCXProducer.h b/TextConverters/DOCX/DOCXProducer.h new file mode 100644 index 000000000..74870c257 --- /dev/null +++ b/TextConverters/DOCX/DOCXProducer.h @@ -0,0 +1,63 @@ +/* + DOCXProducer.h + + Writes out a NSAttributedString as DOCX + + Copyright (C) 2025 Free Software Foundation, Inc. + + Author: Gregory John Casamento + Date: Feb 2025 + + This file is part of the GNUstep GUI Library. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; see the file COPYING.LIB. + If not, see or write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + */ + +#ifndef _GNUstep_H_DOCXProducer +#define _GNUstep_H_DOCXProducer + +#include + +@class NSAttributedString; +@class NSMutableDictionary; +@class NSColor; +@class NSFont; +@class NSMutableParagraphStyle; + +@interface DOCXProducer: NSObject +{ + @public + NSAttributedString *text; + NSMutableDictionary *fontDict; + NSMutableDictionary *colorDict; + NSDictionary *docDict; + NSMutableArray *attachments; + + NSColor *fgColor; + NSColor *bgColor; + NSColor *ulColor; + + NSDictionary *_attributesOfLastRun; /*" holds the attributes of the last run + to build the delta "*/ + + BOOL _inlineGraphics; /*" Indicates if graphics should be inlined. "*/ + int unnamedAttachmentCounter; /*" Count the number of unnamed attachments so we can name them uniquely "*/ +} + +@end + +#endif diff --git a/TextConverters/DOCX/DOCXProducer.m b/TextConverters/DOCX/DOCXProducer.m new file mode 100644 index 000000000..6b97d102a --- /dev/null +++ b/TextConverters/DOCX/DOCXProducer.m @@ -0,0 +1,65 @@ +/* + DOCXProducer.m + + Writes out a NSAttributedString as DOCX + + Copyright (C) 2025 Free Software Foundation, Inc. + + Author: Gregory John Casamento + Date: Feb 2025 + + This file is part of the GNUstep GUI Library. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; see the file COPYING.LIB. + If not, see or write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + */ +#import +#import +#import + +#import "DOCXProducer.h" + +@implementation DOCXProducer + ++ (NSFileWrapper *)produceFileFrom: (NSAttributedString *)aText + documentAttributes: (NSDictionary *)dict + error: (NSError **)error +{ + // Implement code that converts the attributed string to DOCX... + return nil; // AUTORELEASE(wrapper); +} + ++ (NSData *)produceDataFrom: (NSAttributedString *)aText + documentAttributes: (NSDictionary *)dict + error: (NSError **)error +{ + return [[self produceFileFrom: aText + documentAttributes: dict + error: error] serializedRepresentation]; +} + +- (id)init +{ + // Initialize... + return self; +} + +- (void)dealloc +{ + [super dealloc]; +} + +@end diff --git a/TextConverters/DOCX/GNUmakefile b/TextConverters/DOCX/GNUmakefile new file mode 100644 index 000000000..19d3d74a1 --- /dev/null +++ b/TextConverters/DOCX/GNUmakefile @@ -0,0 +1,47 @@ +# GNUmakefile +# +# Copyright (C) 2001 Free Software Foundation, Inc. +# +# Author: Adam Fedor +# +# This file is part of GNUstep +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library 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 +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; see the file COPYING.LIB. +# If not, see or write to the +# Free Software Foundation, 51 Franklin Street, Fifth Floor, +# Boston, MA 02110-1301, USA. + +PACKAGE_NAME = gnustep-gui +include $(GNUSTEP_MAKEFILES)/common.make + +BUNDLE_NAME = DOCXConverter +BUNDLE_INSTALL_DIR =$(GNUSTEP_BUNDLES)/TextConverters + +DOCXConverter_OBJC_FILES = DOCXConsumer.m DOCXProducer.m + +DOCXConverter_PRINCIPAL_CLASS = DOCXConsumer + +ifeq ($(GNUSTEP_TARGET_OS),mingw32) +DOCXConverter_BUNDLE_LIBS += -lgnustep-gui $(FND_LIBS) $(OBJC_LIBS) +endif +ifeq ($(GNUSTEP_TARGET_OS),cygwin) +DOCXConverter_BUNDLE_LIBS += -lgnustep-gui $(FND_LIBS) $(OBJC_LIBS) +endif + +-include GNUmakefile.preamble + +include $(GNUSTEP_MAKEFILES)/bundle.make + +-include GNUmakefile.postamble + diff --git a/TextConverters/DOCX/GNUmakefile.postamble b/TextConverters/DOCX/GNUmakefile.postamble new file mode 100644 index 000000000..f4e6415e4 --- /dev/null +++ b/TextConverters/DOCX/GNUmakefile.postamble @@ -0,0 +1,31 @@ +# GNUmakefile.postamble +# +# Copyright (C) 2001 Free Software Foundation, Inc. +# +# Author: Philippe C.D. Robert +# +# This file is part of GNUstep +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library 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 +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; see the file COPYING.LIB. +# If not, see or write to the +# Free Software Foundation, 51 Franklin Street, Fifth Floor, +# Boston, MA 02110-1301, USA. + +BISON_FLAGS = -p GSRTF --output=rtfGrammar.tab.m --defines=rtfGrammar.tab.h +BISON = BISON_SIMPLE=bison.simple bison + +# Rule not enabled because not every system has bison installed... +# FIXME add configure check for bison? +#rtfGrammar.tab.m: rtfGrammar.y +# $(BISON) $(BISON_FLAGS) $< diff --git a/TextConverters/DOCX/GNUmakefile.preamble b/TextConverters/DOCX/GNUmakefile.preamble new file mode 100644 index 000000000..574bb7f65 --- /dev/null +++ b/TextConverters/DOCX/GNUmakefile.preamble @@ -0,0 +1,73 @@ +# GNUmakefile.preamble +# +# Copyright (C) 2001 Free Software Foundation, Inc. +# +# Author: Philippe C.D. Robert +# +# This file is part of GNUstep +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library 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 +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; see the file COPYING.LIB. +# If not, see or write to the +# Free Software Foundation, 51 Franklin Street, Fifth Floor, +# Boston, MA 02110-1301, USA. + +# +# Makefile.preamble +# +# Project specific makefile variables, and additional +# +# Do not put any Makefile rules in this file, instead they should +# be put into Makefile.postamble. +# + +# +# Flags dealing with compiling and linking +# + +# Additional flags to pass to the preprocessor +ADDITIONAL_CPPFLAGS += -Wall + +# Additional flags to pass to the Objective-C compiler +ADDITIONAL_OBJCFLAGS += + +# Additional flags to pass to the C compiler +ADDITIONAL_CFLAGS += +#ADDITIONAL_CFLAGS += + +# Additional include directories the compiler should search +ADDITIONAL_INCLUDE_DIRS +=-I../../Headers/Additions -I../../Headers + +# Additional LDFLAGS to pass to the linker +#ADDITIONAL_LDFLAGS += + +# Additional library directories the linker should search +ADDITIONAL_LIB_DIRS += -L../../Source/$(GNUSTEP_OBJ_DIR) + +#ADDITIONAL_TOOL_LIBS += + +RTFConverter_BUNDLE_LIBS += -lgnustep-gui + +# +# Flags dealing with installing and uninstalling +# + +# Additional directories to be created during installation +#ADDITIONAL_INSTALL_DIRS += + +# +# Local configuration +# + + + diff --git a/TextConverters/GNUmakefile b/TextConverters/GNUmakefile index 6c4e557d1..011e0ea95 100644 --- a/TextConverters/GNUmakefile +++ b/TextConverters/GNUmakefile @@ -28,6 +28,6 @@ include $(GNUSTEP_MAKEFILES)/common.make # # The list of subproject directories # -SUBPROJECTS = RTF +SUBPROJECTS = RTF DOCX include $(GNUSTEP_MAKEFILES)/aggregate.make