mirror of
https://github.com/ONLYOFFICE/desktop-apps.git
synced 2026-04-07 14:09:22 +08:00
Fix print preview for consistent page orintations
This commit is contained in:
@ -39,61 +39,53 @@
|
||||
class ASCPrinterInfo
|
||||
{
|
||||
public:
|
||||
double m_dDpiX;
|
||||
double m_dDpiY;
|
||||
double m_dDpiX;
|
||||
double m_dDpiY;
|
||||
|
||||
int m_nMarginLeft;
|
||||
int m_nMarginRight;
|
||||
int m_nMarginTop;
|
||||
int m_nMarginBottom;
|
||||
int m_nMarginLeft;
|
||||
int m_nMarginRight;
|
||||
int m_nMarginTop;
|
||||
int m_nMarginBottom;
|
||||
|
||||
int m_nPaperWidth;
|
||||
int m_nPaperHeight;
|
||||
int m_nPaperWidth;
|
||||
int m_nPaperHeight;
|
||||
|
||||
// Actual values take orientation into account
|
||||
int m_nPaperWidthActual;
|
||||
int m_nPaperHeightActual;
|
||||
int m_nPagesCount;
|
||||
|
||||
int m_nPagesCount;
|
||||
int m_nPaperWidthOrigin;
|
||||
int m_nPaperHeightOrigin;
|
||||
|
||||
// Origin values are without dpi scaling
|
||||
int m_nPaperWidthOrigin;
|
||||
int m_nPaperHeightOrigin;
|
||||
|
||||
NSEditorApi::CAscPrinterContextBase* m_pContext;
|
||||
NSEditorApi::CAscPrinterContextBase* m_pContext;
|
||||
|
||||
public:
|
||||
ASCPrinterInfo()
|
||||
{
|
||||
m_dDpiX = 72.0;
|
||||
m_dDpiY = 72.0;
|
||||
ASCPrinterInfo()
|
||||
{
|
||||
m_dDpiX = 72.0;
|
||||
m_dDpiY = 72.0;
|
||||
|
||||
m_nPaperWidth = 1000;
|
||||
m_nPaperHeight = 1000;
|
||||
m_nPaperWidth = 1000;
|
||||
m_nPaperHeight = 1000;
|
||||
|
||||
m_nPaperWidthActual = 1000;
|
||||
m_nPaperHeightActual = 1000;
|
||||
m_nMarginLeft = 0;
|
||||
m_nMarginRight = 0;
|
||||
m_nMarginTop = 0;
|
||||
m_nMarginBottom = 0;
|
||||
|
||||
m_nMarginLeft = 0;
|
||||
m_nMarginRight = 0;
|
||||
m_nMarginTop = 0;
|
||||
m_nMarginBottom = 0;
|
||||
m_nPagesCount = 0;
|
||||
m_pContext = NULL;
|
||||
|
||||
m_nPagesCount = 0;
|
||||
m_pContext = NULL;
|
||||
|
||||
m_nPaperWidthOrigin = 0;
|
||||
m_nPaperHeightOrigin = 0;
|
||||
}
|
||||
m_nPaperWidthOrigin = 0;
|
||||
m_nPaperHeightOrigin = 0;
|
||||
}
|
||||
};
|
||||
|
||||
@interface ASCPrintView : NSView
|
||||
{
|
||||
CAscApplicationManager* m_pManager;
|
||||
CCefView* m_pView;
|
||||
ASCPrinterInfo * m_pPrinterInfo;
|
||||
CAscApplicationManager* m_pManager;
|
||||
CCefView* m_pView;
|
||||
ASCPrinterInfo * m_pPrinterInfo;
|
||||
|
||||
std::vector<bool> m_arOrientation; // true - Horizontal
|
||||
std::vector<bool> m_arOrientation; // true - Horizontal
|
||||
}
|
||||
|
||||
- (id) initWithParams:(CGRect)frame manager:(CAscApplicationManager*)_manager viewId:(int)_viewId info:(ASCPrinterInfo*)_info;
|
||||
@ -105,32 +97,31 @@ public:
|
||||
|
||||
- (id) initWithParams:(CGRect)frame manager:(CAscApplicationManager*)_manager viewId:(int)_viewId info:(ASCPrinterInfo*)_info;
|
||||
{
|
||||
self = [super initWithFrame:frame];
|
||||
if (self)
|
||||
{
|
||||
m_pManager = _manager;
|
||||
m_pView = m_pManager->GetViewById(_viewId);
|
||||
m_pPrinterInfo = _info;
|
||||
}
|
||||
return self;
|
||||
self = [super initWithFrame:frame];
|
||||
if (self)
|
||||
{
|
||||
m_pManager = _manager;
|
||||
m_pView = m_pManager->GetViewById(_viewId);
|
||||
m_pPrinterInfo = _info;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) drawRect:(NSRect)dirtyRect
|
||||
{
|
||||
m_pPrinterInfo->m_pContext->AddRef();
|
||||
m_pPrinterInfo->m_pContext->AddRef();
|
||||
|
||||
NSEditorApi::CAscPrintPage* pData = new NSEditorApi::CAscPrintPage();
|
||||
pData->put_Context(m_pPrinterInfo->m_pContext);
|
||||
NSEditorApi::CAscPrintPage* pData = new NSEditorApi::CAscPrintPage();
|
||||
pData->put_Context(m_pPrinterInfo->m_pContext);
|
||||
|
||||
int nPage = (int)[[NSPrintOperation currentOperation] currentPage] - 1;
|
||||
pData->put_Page(nPage);
|
||||
int nPage = (int)[[NSPrintOperation currentOperation] currentPage] - 1;
|
||||
pData->put_Page(nPage);
|
||||
|
||||
NSEditorApi::CAscMenuEvent* pEvent = new NSEditorApi::CAscMenuEvent();
|
||||
pEvent->m_nType = ASC_MENU_EVENT_TYPE_CEF_PRINT_PAGE;
|
||||
pEvent->m_pData = pData;
|
||||
NSEditorApi::CAscMenuEvent* pEvent = new NSEditorApi::CAscMenuEvent();
|
||||
pEvent->m_nType = ASC_MENU_EVENT_TYPE_CEF_PRINT_PAGE;
|
||||
pEvent->m_pData = pData;
|
||||
|
||||
NSLog(@"[drawRect] Drawing page %d with orientation %d and sizes: %d, %d", nPage, (int)m_arOrientation[nPage], m_pPrinterInfo->m_nPaperWidth, m_pPrinterInfo->m_nPaperHeight);
|
||||
m_pView->Apply(pEvent);
|
||||
m_pView->Apply(pEvent);
|
||||
}
|
||||
|
||||
- (BOOL)knowsPageRange:(NSRangePointer)range
|
||||
@ -163,7 +154,6 @@ public:
|
||||
m_pView->Apply(pEvent);
|
||||
|
||||
m_arOrientation[nPage] = pData->get_IsRotate();
|
||||
NSLog(@"[knowsPageRange] Set orientation for page %d: %d", nPage, pData->get_IsRotate());
|
||||
|
||||
pEvent->Release();
|
||||
}
|
||||
@ -171,43 +161,48 @@ public:
|
||||
range->location = 1;
|
||||
range->length = m_pPrinterInfo->m_nPagesCount;
|
||||
|
||||
return YES;
|
||||
// for correctly displaying preview when all pages are in landscape orientation
|
||||
// TODO: remove this
|
||||
if (m_pPrinterInfo->m_nPagesCount > 0 && m_arOrientation[0])
|
||||
[pInfo setOrientation: NSPaperOrientationLandscape];
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void) fillInfo
|
||||
{
|
||||
NSPrintInfo* pInfo = [[NSPrintOperation currentOperation] printInfo];
|
||||
NSPrintInfo* pInfo = [[NSPrintOperation currentOperation] printInfo];
|
||||
|
||||
PMPrintSession _session = (PMPrintSession)[pInfo PMPrintSession];
|
||||
PMPrintSettings _settings = (PMPrintSettings)[pInfo PMPrintSettings];
|
||||
PMPrintSession _session = (PMPrintSession)[pInfo PMPrintSession];
|
||||
PMPrintSettings _settings = (PMPrintSettings)[pInfo PMPrintSettings];
|
||||
|
||||
PMPrinter _printer;
|
||||
OSStatus err = PMSessionGetCurrentPrinter(_session, &_printer);
|
||||
PMPrinter _printer;
|
||||
OSStatus err = PMSessionGetCurrentPrinter(_session, &_printer);
|
||||
|
||||
PMResolution _resolution;
|
||||
err = PMPrinterGetOutputResolution(_printer, _settings, &_resolution);
|
||||
if (err == 0)
|
||||
{
|
||||
m_pPrinterInfo->m_dDpiX = _resolution.hRes;
|
||||
m_pPrinterInfo->m_dDpiY = _resolution.vRes;
|
||||
}
|
||||
else
|
||||
{
|
||||
UInt32 _res_count = 0;
|
||||
PMPrinterGetPrinterResolutionCount(_printer, &_res_count);
|
||||
PMResolution _resolution;
|
||||
err = PMPrinterGetOutputResolution(_printer, _settings, &_resolution);
|
||||
if (err == 0)
|
||||
{
|
||||
m_pPrinterInfo->m_dDpiX = _resolution.hRes;
|
||||
m_pPrinterInfo->m_dDpiY = _resolution.vRes;
|
||||
}
|
||||
else
|
||||
{
|
||||
UInt32 _res_count = 0;
|
||||
PMPrinterGetPrinterResolutionCount(_printer, &_res_count);
|
||||
|
||||
PMResolution* pResolutions = (PMResolution*)malloc(_res_count * sizeof(PMResolution));
|
||||
PMResolution* pResolutions = (PMResolution*)malloc(_res_count * sizeof(PMResolution));
|
||||
|
||||
for (UInt32 i = 1; i <= _res_count; ++i)
|
||||
{
|
||||
PMPrinterGetIndexedPrinterResolution(_printer, i, pResolutions + i - 1);
|
||||
}
|
||||
for (UInt32 i = 1; i <= _res_count; ++i)
|
||||
{
|
||||
PMPrinterGetIndexedPrinterResolution(_printer, i, pResolutions + i - 1);
|
||||
}
|
||||
|
||||
m_pPrinterInfo->m_dDpiX = pResolutions[0].hRes;
|
||||
m_pPrinterInfo->m_dDpiY = pResolutions[0].vRes;
|
||||
m_pPrinterInfo->m_dDpiX = pResolutions[0].hRes;
|
||||
m_pPrinterInfo->m_dDpiY = pResolutions[0].vRes;
|
||||
|
||||
free(pResolutions);
|
||||
}
|
||||
free(pResolutions);
|
||||
}
|
||||
|
||||
[self recalcPageSizes];
|
||||
}
|
||||
@ -219,16 +214,14 @@ public:
|
||||
|
||||
double dKoefX = m_pPrinterInfo->m_dDpiX / 72.0;
|
||||
double dKoefY = m_pPrinterInfo->m_dDpiY / 72.0;
|
||||
NSLog(@"[recalcPageSizes] DPI: %.2f, %.2f", m_pPrinterInfo->m_dDpiX, m_pPrinterInfo->m_dDpiY);
|
||||
|
||||
m_pPrinterInfo->m_nPaperWidthOrigin = (int)pInfo.paperSize.width;
|
||||
m_pPrinterInfo->m_nPaperHeightOrigin = (int)pInfo.paperSize.height;
|
||||
|
||||
NSRect _rectMargins = pInfo.imageablePageBounds;
|
||||
|
||||
m_pPrinterInfo->m_nPaperWidth = (int)(dKoefX * pInfo.paperSize.width);
|
||||
m_pPrinterInfo->m_nPaperHeight = (int)(dKoefY * pInfo.paperSize.height);
|
||||
NSLog(@"[recalcPageSizes] Set page sizes: %d, %d", m_pPrinterInfo->m_nPaperWidth, m_pPrinterInfo->m_nPaperHeight);
|
||||
|
||||
NSRect _rectMargins = pInfo.imageablePageBounds;
|
||||
|
||||
m_pPrinterInfo->m_nMarginLeft = (int)(dKoefX * _rectMargins.origin.x);
|
||||
m_pPrinterInfo->m_nMarginRight = (int)(dKoefX * (m_pPrinterInfo->m_nPaperWidthOrigin - (_rectMargins.origin.x + _rectMargins.size.width)));
|
||||
@ -238,212 +231,210 @@ public:
|
||||
|
||||
- (NSRect)rectForPage:(NSInteger)page
|
||||
{
|
||||
int nPage = (int)(page - 1);
|
||||
if (nPage < m_pPrinterInfo->m_nPagesCount)
|
||||
{
|
||||
NSPrintInfo* pInfo = [[NSPrintOperation currentOperation] printInfo];
|
||||
int nPage = (int)(page - 1);
|
||||
if (nPage < m_pPrinterInfo->m_nPagesCount)
|
||||
{
|
||||
NSPrintInfo* pInfo = [[NSPrintOperation currentOperation] printInfo];
|
||||
|
||||
NSLog(@"[rectForPage] Applying orientation %d for page %d (previous orientation: %d)", (int)m_arOrientation[nPage], nPage, (int)[pInfo orientation]);
|
||||
[pInfo setOrientation: (m_arOrientation[nPage]) ? NSPaperOrientationLandscape : NSPaperOrientationPortrait];
|
||||
[pInfo setOrientation: (m_arOrientation[nPage]) ? NSPaperOrientationLandscape : NSPaperOrientationPortrait];
|
||||
// update page sizes and margins
|
||||
[self recalcPageSizes];
|
||||
}
|
||||
}
|
||||
|
||||
NSRect R = NSMakeRect( 0, 0, m_pPrinterInfo->m_nPaperWidth, m_pPrinterInfo->m_nPaperHeight );
|
||||
NSLog(@"[rectForPage] Applied actual rect sizes for page %d", nPage);
|
||||
[self setFrame: R];
|
||||
return R;
|
||||
NSRect R = NSMakeRect( 0, 0, m_pPrinterInfo->m_nPaperWidth, m_pPrinterInfo->m_nPaperHeight );
|
||||
[self setFrame: R];
|
||||
return R;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
class ASCPrinterContext : public NSEditorApi::CAscPrinterContextBase
|
||||
{
|
||||
CAscApplicationManager* m_pManager;
|
||||
ASCPrinterInfo m_oInfo;
|
||||
NSView* m_pView;
|
||||
CCefView* m_pParent;
|
||||
CAscApplicationManager* m_pManager;
|
||||
ASCPrinterInfo m_oInfo;
|
||||
NSView* m_pView;
|
||||
CCefView* m_pParent;
|
||||
|
||||
public:
|
||||
ASCPrinterContext(CAscApplicationManager* pManager) : NSEditorApi::CAscPrinterContextBase()
|
||||
{
|
||||
m_pManager = pManager;
|
||||
m_pView = nil;
|
||||
m_pParent = NULL;
|
||||
}
|
||||
ASCPrinterContext(CAscApplicationManager* pManager) : NSEditorApi::CAscPrinterContextBase()
|
||||
{
|
||||
m_pManager = pManager;
|
||||
m_pView = nil;
|
||||
m_pParent = NULL;
|
||||
}
|
||||
|
||||
void BeginPaint(NSDictionary * info, id sender, SEL didRunSelector)
|
||||
{
|
||||
int viewId = [info[@"viewId"] intValue];
|
||||
int pageCurrent = [info[@"currentPage"] intValue];
|
||||
void BeginPaint(NSDictionary * info, id sender, SEL didRunSelector)
|
||||
{
|
||||
int viewId = [info[@"viewId"] intValue];
|
||||
int pageCurrent = [info[@"currentPage"] intValue];
|
||||
|
||||
m_oInfo.m_nPagesCount = [info[@"countPages"] intValue];
|
||||
m_oInfo.m_pContext = this;
|
||||
m_pView = [[ASCPrintView alloc] initWithParams:NSMakeRect(0, 0, 100, 100) manager:m_pManager viewId:viewId info:&m_oInfo];
|
||||
m_pParent = m_pManager->GetViewById(viewId);
|
||||
m_oInfo.m_nPagesCount = [info[@"countPages"] intValue];
|
||||
m_oInfo.m_pContext = this;
|
||||
m_pView = [[ASCPrintView alloc] initWithParams:NSMakeRect(0, 0, 100, 100) manager:m_pManager viewId:viewId info:&m_oInfo];
|
||||
m_pParent = m_pManager->GetViewById(viewId);
|
||||
|
||||
NSLog(@"page from %d to %d", pageCurrent, m_oInfo.m_nPagesCount);
|
||||
NSLog(@"page from %d to %d", pageCurrent, m_oInfo.m_nPagesCount);
|
||||
|
||||
NSView* pViewParent = (__bridge NSView*)(m_pParent->GetWidgetImpl()->cef_handle);
|
||||
NSView* pViewParent = (__bridge NSView*)(m_pParent->GetWidgetImpl()->cef_handle);
|
||||
|
||||
// start print dialog
|
||||
NSPrintInfo* pPrintInfo = [NSPrintInfo sharedPrintInfo];
|
||||
// NSString* sKeyPrint = @"prihord"; // Ключ в котором расположен объект NSPrintInfo
|
||||
// start print dialog
|
||||
NSPrintInfo* pPrintInfo = [NSPrintInfo sharedPrintInfo];
|
||||
// NSString* sKeyPrint = @"prihord"; // Ключ в котором расположен объект NSPrintInfo
|
||||
|
||||
// Пробуем извлечь
|
||||
// NSUserDefaults* pUserDef = [[NSUserDefaults alloc] init];
|
||||
// NSData* pDataInfo = [pUserDef dataForKey:sKeyPrint];
|
||||
// if (pDataInfo)
|
||||
// {
|
||||
// Если удачно извлекли
|
||||
// pPrintInfo = [NSUnarchiver unarchiveObjectWithData:pDataInfo];
|
||||
// }
|
||||
// else
|
||||
{
|
||||
// Пробуем извлечь
|
||||
// NSUserDefaults* pUserDef = [[NSUserDefaults alloc] init];
|
||||
// NSData* pDataInfo = [pUserDef dataForKey:sKeyPrint];
|
||||
// if (pDataInfo)
|
||||
// {
|
||||
// Если удачно извлекли
|
||||
// pPrintInfo = [NSUnarchiver unarchiveObjectWithData:pDataInfo];
|
||||
// }
|
||||
// else
|
||||
{
|
||||
#if 0
|
||||
// Иначе выводим панель настройки печати
|
||||
NSPageLayout* pPageLayout = [[NSPageLayout alloc] init];
|
||||
if ([pPageLayout runModal] == NSModalResponseOK)
|
||||
{
|
||||
pPrintInfo = pPageLayout.printInfo;
|
||||
// Иначе выводим панель настройки печати
|
||||
NSPageLayout* pPageLayout = [[NSPageLayout alloc] init];
|
||||
if ([pPageLayout runModal] == NSModalResponseOK)
|
||||
{
|
||||
pPrintInfo = pPageLayout.printInfo;
|
||||
|
||||
// сохраним введенные настройки в User Defaults
|
||||
pDataInfo = [NSArchiver archivedDataWithRootObject:pPrintInfo];
|
||||
[pUserDef setObject:pDataInfo forKey:sKeyPrint];
|
||||
}
|
||||
// сохраним введенные настройки в User Defaults
|
||||
pDataInfo = [NSArchiver archivedDataWithRootObject:pPrintInfo];
|
||||
[pUserDef setObject:pDataInfo forKey:sKeyPrint];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
NSDictionary * pWOptions = [info[@"options"] dictionary];
|
||||
if ( pWOptions && [pWOptions objectForKey:@"nativeOptions"] ) {
|
||||
NSDictionary * pNOptions = pWOptions[@"nativeOptions"];
|
||||
NSDictionary * pWOptions = [info[@"options"] dictionary];
|
||||
if ( pWOptions && [pWOptions objectForKey:@"nativeOptions"] ) {
|
||||
NSDictionary * pNOptions = pWOptions[@"nativeOptions"];
|
||||
|
||||
NSDictionary * paperSize = pNOptions[@"paperSize"];
|
||||
if ( [paperSize objectForKey:@"preset"] != nil )
|
||||
[pPrintInfo setPaperName:paperSize[@"preset"]];
|
||||
else {
|
||||
// [pPrintInfo setPaperSize:NSMakeSize(595, 842)];
|
||||
}
|
||||
NSDictionary * paperSize = pNOptions[@"paperSize"];
|
||||
if ( [paperSize objectForKey:@"preset"] != nil )
|
||||
[pPrintInfo setPaperName:paperSize[@"preset"]];
|
||||
else {
|
||||
// [pPrintInfo setPaperSize:NSMakeSize(595, 842)];
|
||||
}
|
||||
|
||||
PMPrintSettings printSettings = (PMPrintSettings)pPrintInfo.PMPrintSettings;
|
||||
PMSetPageRange(printSettings, 1, m_oInfo.m_nPagesCount);
|
||||
PMSetCopies(printSettings , [pNOptions[@"copies"] intValue], kPMUnlocked);
|
||||
PMPrintSettings printSettings = (PMPrintSettings)pPrintInfo.PMPrintSettings;
|
||||
PMSetPageRange(printSettings, 1, m_oInfo.m_nPagesCount);
|
||||
PMSetCopies(printSettings , [pNOptions[@"copies"] intValue], kPMUnlocked);
|
||||
|
||||
// PMPageFormat pageFormat = (PMPageFormat)pPrintInfo.PMPageFormat;
|
||||
// if ( [pNOptions[@"paperOrientation"] isEqualTo:@"landscape"] )
|
||||
// PMSetOrientation(pageFormat, kPMLandscape, kPMUnlocked);
|
||||
// else PMSetOrientation(pageFormat, kPMPortrait, kPMUnlocked);
|
||||
// [pPrintInfo updateFromPMPageFormat];
|
||||
// PMPageFormat pageFormat = (PMPageFormat)pPrintInfo.PMPageFormat;
|
||||
// if ( [pNOptions[@"paperOrientation"] isEqualTo:@"landscape"] )
|
||||
// PMSetOrientation(pageFormat, kPMLandscape, kPMUnlocked);
|
||||
// else PMSetOrientation(pageFormat, kPMPortrait, kPMUnlocked);
|
||||
// [pPrintInfo updateFromPMPageFormat];
|
||||
|
||||
PMSetFirstPage(printSettings, pageCurrent, kPMUnlocked ) ;
|
||||
PMSetFirstPage(printSettings, pageCurrent, kPMUnlocked ) ;
|
||||
|
||||
NSString * duplex = pNOptions[@"sides"];
|
||||
if ( [duplex isEqualToString:@"both-long"] )
|
||||
PMSetDuplex(printSettings, kPMDuplexNoTumble);
|
||||
else
|
||||
if ( [duplex isEqualToString:@"both-short"] )
|
||||
PMSetDuplex(printSettings, kPMDuplexTumble);
|
||||
else PMSetDuplex(printSettings, kPMDuplexNone);
|
||||
[pPrintInfo updateFromPMPrintSettings];
|
||||
}
|
||||
NSString * duplex = pNOptions[@"sides"];
|
||||
if ( [duplex isEqualToString:@"both-long"] )
|
||||
PMSetDuplex(printSettings, kPMDuplexNoTumble);
|
||||
else
|
||||
if ( [duplex isEqualToString:@"both-short"] )
|
||||
PMSetDuplex(printSettings, kPMDuplexTumble);
|
||||
else PMSetDuplex(printSettings, kPMDuplexNone);
|
||||
[pPrintInfo updateFromPMPrintSettings];
|
||||
}
|
||||
|
||||
NSPrintPanelOptions options = NSPrintPanelShowsCopies;
|
||||
options |= NSPrintPanelShowsPageRange;
|
||||
options |= NSPrintPanelShowsPaperSize;
|
||||
options |= NSPrintPanelShowsPrintSelection;
|
||||
options |= NSPrintPanelShowsPreview;
|
||||
NSPrintPanelOptions options = NSPrintPanelShowsCopies;
|
||||
options |= NSPrintPanelShowsPageRange;
|
||||
options |= NSPrintPanelShowsPaperSize;
|
||||
// commented since we can't select which pages to print directly in app
|
||||
// options |= NSPrintPanelShowsPrintSelection;
|
||||
options |= NSPrintPanelShowsPreview;
|
||||
|
||||
NSPrintOperation* pro;
|
||||
if (pPrintInfo)
|
||||
pro = [NSPrintOperation printOperationWithView:m_pView printInfo:pPrintInfo];
|
||||
else
|
||||
pro = [NSPrintOperation printOperationWithView:m_pView];
|
||||
NSPrintOperation* pro;
|
||||
if (pPrintInfo)
|
||||
pro = [NSPrintOperation printOperationWithView:m_pView printInfo:pPrintInfo];
|
||||
else
|
||||
pro = [NSPrintOperation printOperationWithView:m_pView];
|
||||
|
||||
[pro setShowsPrintPanel:YES]; // Выводим на печать или предпросмотр
|
||||
[[pro printPanel] setOptions:options];
|
||||
//[pro runOperation];
|
||||
[pro runOperationModalForWindow:pViewParent.window delegate:sender didRunSelector:didRunSelector contextInfo:nil];
|
||||
}
|
||||
void EndPaint()
|
||||
{
|
||||
NSEditorApi::CAscMenuEvent* pEventEnd = new NSEditorApi::CAscMenuEvent();
|
||||
pEventEnd->m_nType = ASC_MENU_EVENT_TYPE_CEF_PRINT_END;
|
||||
[pro setShowsPrintPanel:YES]; // Выводим на печать или предпросмотр
|
||||
[[pro printPanel] setOptions:options];
|
||||
//[pro runOperation];
|
||||
[pro runOperationModalForWindow:pViewParent.window delegate:sender didRunSelector:didRunSelector contextInfo:nil];
|
||||
}
|
||||
void EndPaint()
|
||||
{
|
||||
NSEditorApi::CAscMenuEvent* pEventEnd = new NSEditorApi::CAscMenuEvent();
|
||||
pEventEnd->m_nType = ASC_MENU_EVENT_TYPE_CEF_PRINT_END;
|
||||
|
||||
m_pParent->Apply(pEventEnd);
|
||||
m_pParent->Apply(pEventEnd);
|
||||
|
||||
m_pView = nil;
|
||||
this->Release();
|
||||
}
|
||||
m_pView = nil;
|
||||
this->Release();
|
||||
}
|
||||
|
||||
virtual void GetLogicalDPI(int& nDpiX, int& nDpiY)
|
||||
{
|
||||
nDpiX = (int)m_oInfo.m_dDpiX;
|
||||
nDpiY = (int)m_oInfo.m_dDpiY;
|
||||
}
|
||||
virtual void GetLogicalDPI(int& nDpiX, int& nDpiY)
|
||||
{
|
||||
nDpiX = (int)m_oInfo.m_dDpiX;
|
||||
nDpiY = (int)m_oInfo.m_dDpiY;
|
||||
}
|
||||
|
||||
virtual void GetPhysicalRect(int& nX, int& nY, int& nW, int& nH)
|
||||
{
|
||||
nX = m_oInfo.m_nMarginLeft;
|
||||
nY = m_oInfo.m_nMarginTop;
|
||||
nW = m_oInfo.m_nPaperWidth;
|
||||
nH = m_oInfo.m_nPaperHeight;
|
||||
}
|
||||
virtual void GetPhysicalRect(int& nX, int& nY, int& nW, int& nH)
|
||||
{
|
||||
nX = m_oInfo.m_nMarginLeft;
|
||||
nY = m_oInfo.m_nMarginTop;
|
||||
nW = m_oInfo.m_nPaperWidth;
|
||||
nH = m_oInfo.m_nPaperHeight;
|
||||
}
|
||||
|
||||
virtual void GetPrintAreaSize(int& nW, int& nH)
|
||||
{
|
||||
nW = m_oInfo.m_nPaperWidth - m_oInfo.m_nMarginLeft - m_oInfo.m_nMarginRight;
|
||||
nH = m_oInfo.m_nPaperHeight - m_oInfo.m_nMarginTop - m_oInfo.m_nMarginBottom;
|
||||
}
|
||||
virtual void GetPrintAreaSize(int& nW, int& nH)
|
||||
{
|
||||
nW = m_oInfo.m_nPaperWidth - m_oInfo.m_nMarginLeft - m_oInfo.m_nMarginRight;
|
||||
nH = m_oInfo.m_nPaperHeight - m_oInfo.m_nMarginTop - m_oInfo.m_nMarginBottom;
|
||||
}
|
||||
|
||||
static void releasePixels(void *info, const void *data, size_t size)
|
||||
{
|
||||
delete ((unsigned char*)data);
|
||||
}
|
||||
static void releasePixels(void *info, const void *data, size_t size)
|
||||
{
|
||||
delete ((unsigned char*)data);
|
||||
}
|
||||
|
||||
virtual void BitBlt(unsigned char* pBGRA, const int& nRasterX, const int& nRasterY, const int& nRasterW, const int& nRasterH,
|
||||
const double& x, const double& y, const double& w, const double& h, const double& dAngle)
|
||||
{
|
||||
virtual void BitBlt(unsigned char* pBGRA, const int& nRasterX, const int& nRasterY, const int& nRasterW, const int& nRasterH,
|
||||
const double& x, const double& y, const double& w, const double& h, const double& dAngle)
|
||||
{
|
||||
|
||||
|
||||
CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();
|
||||
CGDataProviderRef pDataProvider = CGDataProviderCreateWithData(NULL, pBGRA, 4 * nRasterW * nRasterH, releasePixels);
|
||||
CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();
|
||||
CGDataProviderRef pDataProvider = CGDataProviderCreateWithData(NULL, pBGRA, 4 * nRasterW * nRasterH, releasePixels);
|
||||
|
||||
CGImageRef pCgImage = CGImageCreate(nRasterW, nRasterH, 8, 32, 4 * nRasterW, cs,
|
||||
kCGImageAlphaPremultipliedLast, pDataProvider,
|
||||
NULL, false, kCGRenderingIntentAbsoluteColorimetric);
|
||||
CGImageRef pCgImage = CGImageCreate(nRasterW, nRasterH, 8, 32, 4 * nRasterW, cs,
|
||||
kCGImageAlphaPremultipliedLast, pDataProvider,
|
||||
NULL, false, kCGRenderingIntentAbsoluteColorimetric);
|
||||
|
||||
// здесь никаких поворотов - разруливаем все раньше
|
||||
CGFloat fX = (CGFloat)((x + m_oInfo.m_nMarginLeft) * m_oInfo.m_nPaperWidthOrigin / m_oInfo.m_nPaperWidth);
|
||||
CGFloat fY = (CGFloat)((y + m_oInfo.m_nMarginTop) * m_oInfo.m_nPaperHeightOrigin / m_oInfo.m_nPaperHeight);
|
||||
CGFloat fW = (CGFloat)(nRasterW * m_oInfo.m_nPaperWidthOrigin / m_oInfo.m_nPaperWidth);
|
||||
CGFloat fH = (CGFloat)(nRasterH * m_oInfo.m_nPaperHeightOrigin / m_oInfo.m_nPaperHeight);
|
||||
fY = (m_oInfo.m_nPaperHeightOrigin - fY - fH);
|
||||
// здесь никаких поворотов - разруливаем все раньше
|
||||
CGFloat fX = (CGFloat)((x + m_oInfo.m_nMarginLeft) * m_oInfo.m_nPaperWidthOrigin / m_oInfo.m_nPaperWidth);
|
||||
CGFloat fY = (CGFloat)((y + m_oInfo.m_nMarginTop) * m_oInfo.m_nPaperHeightOrigin / m_oInfo.m_nPaperHeight);
|
||||
CGFloat fW = (CGFloat)(nRasterW * m_oInfo.m_nPaperWidthOrigin / m_oInfo.m_nPaperWidth);
|
||||
CGFloat fH = (CGFloat)(nRasterH * m_oInfo.m_nPaperHeightOrigin / m_oInfo.m_nPaperHeight);
|
||||
fY = (m_oInfo.m_nPaperHeightOrigin - fY - fH);
|
||||
|
||||
CGContextRef _context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
|
||||
CGContextRef _context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
|
||||
|
||||
CGAffineTransform orig_cg_matrix = CGContextGetCTM(_context);
|
||||
CGAffineTransform orig_cg_matrix_inv = CGAffineTransformInvert(orig_cg_matrix);
|
||||
CGAffineTransform orig_cg_matrix = CGContextGetCTM(_context);
|
||||
CGAffineTransform orig_cg_matrix_inv = CGAffineTransformInvert(orig_cg_matrix);
|
||||
|
||||
orig_cg_matrix.a = fabs(orig_cg_matrix.a);
|
||||
orig_cg_matrix.d = fabs(orig_cg_matrix.d);
|
||||
orig_cg_matrix.tx = 0;
|
||||
orig_cg_matrix.ty = 0;
|
||||
orig_cg_matrix.a = fabs(orig_cg_matrix.a);
|
||||
orig_cg_matrix.d = fabs(orig_cg_matrix.d);
|
||||
orig_cg_matrix.tx = 0;
|
||||
orig_cg_matrix.ty = 0;
|
||||
|
||||
CGContextSaveGState(_context);
|
||||
CGContextSaveGState(_context);
|
||||
|
||||
CGContextConcatCTM(_context, orig_cg_matrix_inv);
|
||||
CGContextConcatCTM(_context, orig_cg_matrix);
|
||||
CGContextConcatCTM(_context, orig_cg_matrix_inv);
|
||||
CGContextConcatCTM(_context, orig_cg_matrix);
|
||||
|
||||
CGRect _rect = NSMakeRect(fX, fY, fW, fH);
|
||||
CGContextDrawImage(_context, _rect, pCgImage);
|
||||
CGImageRelease(pCgImage);
|
||||
CGRect _rect = NSMakeRect(fX, fY, fW, fH);
|
||||
CGContextDrawImage(_context, _rect, pCgImage);
|
||||
CGImageRelease(pCgImage);
|
||||
|
||||
CGContextRestoreGState(_context);
|
||||
CGContextRestoreGState(_context);
|
||||
|
||||
CGColorSpaceRelease(cs);
|
||||
CGDataProviderRelease(pDataProvider);
|
||||
}
|
||||
CGColorSpaceRelease(cs);
|
||||
CGDataProviderRelease(pDataProvider);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // NSASCPRINTER_H
|
||||
|
||||
Reference in New Issue
Block a user