Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add skeletal DOCX support #334

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions TextConverters/DOCX/.cvsignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*obj
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would we need an .cvsignore file?

*.app
*.debug
*.profile
.gdbinit
*.bundle
51 changes: 51 additions & 0 deletions TextConverters/DOCX/DOCXConsumer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* docxConsumer.h created by gcasa Feb-2025
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capitalization of the file name seems to be wrong.


Copyright (C) 2025 Free Software Foundation, Inc.

Author: Gregory John Casamento <[email protected]>
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 <http://www.gnu.org/licenses/> 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 <GNUstepGUI/GSTextConverter.h>

@class NSMutableDictionary;
@class NSMutableArray;
@class NSMutableAttributedString;

@interface DOCXConsumer: NSObject <GSTextConsumer>
{
@public
NSStringEncoding encoding;
NSMutableDictionary *documentAttributes;
NSMutableDictionary *fonts;
NSMutableArray *colours;
NSMutableArray *attrs;
NSMutableAttributedString *result;
Class _class;
int ignore;
}

@end

#endif
94 changes: 94 additions & 0 deletions TextConverters/DOCX/DOCXConsumer.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/* attributedStringConsumer.m
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file name is wrong.


Copyright (C) 1999 Free Software Foundation, Inc.

Author: Stefan B�hringer ([email protected])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather attribute this file to yourself.

Date: Dec 1999
Author: Fred Kiefer <[email protected]>
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 <http://www.gnu.org/licenses/> or write to the
Free Software Foundation, 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/

#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
#import <GNUstepGUI/GSHelpAttachment.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure you are going to need this?


#import "DOCXConsumer.h"
// #import "DOCXConsumerFunctions.h"
#import "DOCXProducer.h"

@implementation DOCXConsumer

/* RTFConsumer is the principal class and thus implements this */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment seems to be a leftover

+ (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
159 changes: 159 additions & 0 deletions TextConverters/DOCX/DOCXConsumerFunctions.h
Original file line number Diff line number Diff line change
@@ -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 ([email protected])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again the wrong author

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 <http://www.gnu.org/licenses/> 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

63 changes: 63 additions & 0 deletions TextConverters/DOCX/DOCXProducer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
DOCXProducer.h

Writes out a NSAttributedString as DOCX

Copyright (C) 2025 Free Software Foundation, Inc.

Author: Gregory John Casamento <[email protected]>
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 <http://www.gnu.org/licenses/> 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 <GNUstepGUI/GSTextConverter.h>

@class NSAttributedString;
@class NSMutableDictionary;
@class NSColor;
@class NSFont;
@class NSMutableParagraphStyle;

@interface DOCXProducer: NSObject <GSTextProducer>
{
@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
Loading