mirror of
https://github.com/microtherion/VocalEasel.git
synced 2024-12-22 11:14:00 +00:00
Store and load print properties
This commit is contained in:
parent
07f118ada0
commit
93a34a71f2
|
@ -9,7 +9,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
\paper {
|
\paper {
|
||||||
#(set-paper-size "<{PAPERSIZE}>")
|
#(set-paper-size <{PAPERSIZE}>)
|
||||||
indent = 0.0\cm
|
indent = 0.0\cm
|
||||||
pagenumber = no
|
pagenumber = no
|
||||||
page-top-space = #.1
|
page-top-space = #.1
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
#import "VLLilypondDocument.h"
|
#import "VLLilypondDocument.h"
|
||||||
#import "VLLilypondWriter.h"
|
#import "VLLilypondWriter.h"
|
||||||
|
|
||||||
|
#import <algorithm>
|
||||||
|
|
||||||
@interface NSMutableString (VLLilypond)
|
@interface NSMutableString (VLLilypond)
|
||||||
|
|
||||||
- (void) substituteMacro:(NSString *)macro withValue:(NSString *)value;
|
- (void) substituteMacro:(NSString *)macro withValue:(NSString *)value;
|
||||||
|
@ -103,6 +105,14 @@
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
static NSSize sPaperSizes[] = {
|
||||||
|
{842.0f, 1191.0f}, {595.0f, 842.0f}, {421.0f, 595.0f}, {298.0f, 421.0f},
|
||||||
|
{612.0f, 1008.0f}, {612.0f, 792.0f}, {792.0f, 1224.0f}
|
||||||
|
};
|
||||||
|
static const char * sPaperNames[] = {
|
||||||
|
"a3", "a4", "a5", "a6", "letter", "legal", "11x17", 0
|
||||||
|
};
|
||||||
|
|
||||||
@implementation VLDocument (Lilypond)
|
@implementation VLDocument (Lilypond)
|
||||||
|
|
||||||
- (NSData *)lilypondDataWithError:(NSError **)outError
|
- (NSData *)lilypondDataWithError:(NSError **)outError
|
||||||
|
@ -116,13 +126,36 @@
|
||||||
NSStringEncoding enc = NSUTF8StringEncoding;
|
NSStringEncoding enc = NSUTF8StringEncoding;
|
||||||
NSMutableString * ly =
|
NSMutableString * ly =
|
||||||
[NSMutableString stringWithContentsOfFile:tmpl encoding:enc error:outError];
|
[NSMutableString stringWithContentsOfFile:tmpl encoding:enc error:outError];
|
||||||
|
NSPrintInfo * pi = [self printInfo];
|
||||||
|
NSSize sz = [pi paperSize];
|
||||||
|
int bestPaper = -1;
|
||||||
|
float bestDist = 1e10f;
|
||||||
|
|
||||||
|
if ([pi orientation] == NSLandscapeOrientation)
|
||||||
|
std::swap(sz.width, sz.height);
|
||||||
|
|
||||||
|
for (int paper = 0; sPaperNames[paper]; ++paper) {
|
||||||
|
float dist = hypotf(sz.width - sPaperSizes[paper].width,
|
||||||
|
sz.height- sPaperSizes[paper].height);
|
||||||
|
if (dist < bestDist) {
|
||||||
|
bestPaper = paper;
|
||||||
|
bestDist = dist;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
NSString * paper = [NSString stringWithFormat:
|
||||||
|
[pi orientation] == NSLandscapeOrientation ? @"\"%s\" 'landscape" : @"\"%s\"",
|
||||||
|
sPaperNames[bestPaper]];
|
||||||
|
float scaling= [[[pi dictionary] objectForKey:NSPrintScalingFactor]
|
||||||
|
floatValue];
|
||||||
|
|
||||||
[ly substituteMacro:@"TITLE" withValue:songTitle];
|
[ly substituteMacro:@"TITLE" withValue:songTitle];
|
||||||
[ly substituteMacro:@"POET" withValue:songLyricist];
|
[ly substituteMacro:@"POET" withValue:songLyricist];
|
||||||
[ly substituteMacro:@"COMPOSER" withValue:songComposer];
|
[ly substituteMacro:@"COMPOSER" withValue:songComposer];
|
||||||
[ly substituteMacro:@"ARRANGER" withValue:songArranger];
|
[ly substituteMacro:@"ARRANGER" withValue:songArranger];
|
||||||
[ly substituteMacro:@"VLVERSION" withValue:
|
[ly substituteMacro:@"VLVERSION" withValue:
|
||||||
[bndl objectForInfoDictionaryKey:@"CFBundleVersion"]];
|
[bndl objectForInfoDictionaryKey:@"CFBundleVersion"]];
|
||||||
[ly substituteMacro:@"PAPERSIZE" withValue:@"letter"];
|
[ly substituteMacro:@"PAPERSIZE" withValue:paper];
|
||||||
[ly substituteMacro:@"FORMATTING" withValue:@"ragged-last-bottom = ##f"];
|
[ly substituteMacro:@"FORMATTING" withValue:@"ragged-last-bottom = ##f"];
|
||||||
[ly substituteMacro:@"VLVERSION" withValue:
|
[ly substituteMacro:@"VLVERSION" withValue:
|
||||||
[bndl objectForInfoDictionaryKey:@"CFBundleVersion"]];
|
[bndl objectForInfoDictionaryKey:@"CFBundleVersion"]];
|
||||||
|
@ -131,7 +164,7 @@
|
||||||
[ly substituteMacro:@"LYRICSIZE" withValue:
|
[ly substituteMacro:@"LYRICSIZE" withValue:
|
||||||
[NSString stringWithFormat:@"%.1f", lyricSize]];
|
[NSString stringWithFormat:@"%.1f", lyricSize]];
|
||||||
[ly substituteMacro:@"STAFFSIZE" withValue:
|
[ly substituteMacro:@"STAFFSIZE" withValue:
|
||||||
[NSString stringWithFormat:@"%.1f", staffSize]];
|
[NSString stringWithFormat:@"%.1f", staffSize*scaling]];
|
||||||
[ly substituteMacro:@"CHORDS" withValue:
|
[ly substituteMacro:@"CHORDS" withValue:
|
||||||
[NSString stringWithUTF8String:writer.Chords().c_str()]];
|
[NSString stringWithUTF8String:writer.Chords().c_str()]];
|
||||||
[ly substituteMacro:@"NOTES" withValue:
|
[ly substituteMacro:@"NOTES" withValue:
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
|
|
||||||
- (NSFileWrapper *)XMLFileWrapperWithError:(NSError **)outError flat:(BOOL)flat;
|
- (NSFileWrapper *)XMLFileWrapperWithError:(NSError **)outError flat:(BOOL)flat;
|
||||||
{
|
{
|
||||||
|
static NSArray * sPropertyKeys = nil;
|
||||||
|
|
||||||
NSFileWrapper * contents = [self fileWrapperWithFilter:@"VLMusicXMLType" error:outError];
|
NSFileWrapper * contents = [self fileWrapperWithFilter:@"VLMusicXMLType" error:outError];
|
||||||
|
|
||||||
if (!contents) {
|
if (!contents) {
|
||||||
|
@ -30,6 +32,17 @@
|
||||||
[wrap addFileWrapper:contents];
|
[wrap addFileWrapper:contents];
|
||||||
if (vcsWrapper)
|
if (vcsWrapper)
|
||||||
[wrap addFileWrapper:vcsWrapper];
|
[wrap addFileWrapper:vcsWrapper];
|
||||||
|
NSData * pd = [NSArchiver archivedDataWithRootObject:
|
||||||
|
[self printInfo]];
|
||||||
|
[wrap addRegularFileWithContents:pd preferredFilename:@"PrintInfo"];
|
||||||
|
if (!sPropertyKeys)
|
||||||
|
sPropertyKeys = [[NSArray alloc] initWithObjects:
|
||||||
|
@"staffSize", @"chordSize", @"lyricSize", nil];
|
||||||
|
NSData * prop = [NSPropertyListSerialization dataFromPropertyList:
|
||||||
|
[self dictionaryWithValuesForKeys:sPropertyKeys]
|
||||||
|
format:NSPropertyListXMLFormat_v1_0
|
||||||
|
errorDescription:nil];
|
||||||
|
[wrap addRegularFileWithContents:prop preferredFilename:@"Properties"];
|
||||||
|
|
||||||
return wrap;
|
return wrap;
|
||||||
}
|
}
|
||||||
|
@ -44,7 +57,7 @@
|
||||||
)
|
)
|
||||||
[vcsWrapper retain];
|
[vcsWrapper retain];
|
||||||
//
|
//
|
||||||
// Read properties dictionary for backward compatibility
|
// Read properties dictionary
|
||||||
//
|
//
|
||||||
NSFileWrapper * prop = [wrappers objectForKey:@"Properties"];
|
NSFileWrapper * prop = [wrappers objectForKey:@"Properties"];
|
||||||
if (prop) {
|
if (prop) {
|
||||||
|
@ -57,6 +70,17 @@
|
||||||
format:nil errorDescription:nil]];
|
format:nil errorDescription:nil]];
|
||||||
[undoMgr enableUndoRegistration];
|
[undoMgr enableUndoRegistration];
|
||||||
}
|
}
|
||||||
|
//
|
||||||
|
// Read print info
|
||||||
|
NSFileWrapper * print = [wrappers objectForKey:@"PrintInfo"];
|
||||||
|
if (print) {
|
||||||
|
NSUndoManager * undoMgr = [self undoManager];
|
||||||
|
[undoMgr disableUndoRegistration];
|
||||||
|
NSPrintInfo * pi = [NSUnarchiver unarchiveObjectWithData:
|
||||||
|
[print regularFileContents]];
|
||||||
|
[self setPrintInfo:pi];
|
||||||
|
[undoMgr enableUndoRegistration];
|
||||||
|
}
|
||||||
return [self readFromFileWrapper:[wrappers objectForKey:@"Song"] withFilter:@"VLMusicXMLType"
|
return [self readFromFileWrapper:[wrappers objectForKey:@"Song"] withFilter:@"VLMusicXMLType"
|
||||||
error:outError];
|
error:outError];
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user