diff options
Diffstat (limited to 'tikzit/src/gtk')
-rw-r--r-- | tikzit/src/gtk/PreviewRenderer.m | 22 | ||||
-rw-r--r-- | tikzit/src/gtk/PreviewWindow.m | 39 | ||||
-rw-r--r-- | tikzit/src/gtk/WidgetSurface.h | 3 |
3 files changed, 41 insertions, 23 deletions
diff --git a/tikzit/src/gtk/PreviewRenderer.m b/tikzit/src/gtk/PreviewRenderer.m index d334832..43fbe98 100644 --- a/tikzit/src/gtk/PreviewRenderer.m +++ b/tikzit/src/gtk/PreviewRenderer.m @@ -24,7 +24,7 @@ @implementation PreviewRenderer -@synthesize preambles,document; +@synthesize preambles, document; - (id) init { [self release]; @@ -212,8 +212,26 @@ } - (void) renderWithContext:(id<RenderContext>)c onSurface:(id<Surface>)surface { - if (document != nil) { + if (document != nil && pdfPage) { CairoRenderContext *context = (CairoRenderContext*)c; + + double w = 0.0; + double h = 0.0; + poppler_page_get_size(pdfPage, &w, &h); + if (w==0) w = 1.0; + if (h==0) h = 1.0; + + double scale = ([surface height] / h) * 0.95; + if (w * scale > [surface width]) scale = [surface width] / w; + [[surface transformer] setScale:scale]; + + NSPoint origin; + w *= scale; + h *= scale; + origin.x = ([surface width] - w) / 2; + origin.y = ([surface height] - h) / 2; + + [[surface transformer] setOrigin:origin]; [context saveState]; [context applyTransform:[surface transformer]]; diff --git a/tikzit/src/gtk/PreviewWindow.m b/tikzit/src/gtk/PreviewWindow.m index 418886e..5443e8d 100644 --- a/tikzit/src/gtk/PreviewWindow.m +++ b/tikzit/src/gtk/PreviewWindow.m @@ -26,9 +26,11 @@ @interface PreviewWindow (Private) - (BOOL) updateOrShowError; +- (void) updateDefaultSize; @end // {{{ API + @implementation PreviewWindow - (id) init { @@ -46,7 +48,8 @@ window = GTK_WINDOW (gtk_window_new (GTK_WINDOW_TOPLEVEL)); gtk_window_set_title (window, "Preview"); - gtk_window_set_resizable (window, FALSE); + gtk_window_set_resizable (window, TRUE); + gtk_window_set_default_size (window, 150.0, 150.0); g_signal_connect (G_OBJECT (window), "delete-event", G_CALLBACK (gtk_widget_hide_on_delete), @@ -54,7 +57,6 @@ GtkWidget *pdfArea = gtk_drawing_area_new (); gtk_container_add (GTK_CONTAINER (window), pdfArea); - gtk_widget_set_size_request (pdfArea, 150.0, 150.0); gtk_widget_show (pdfArea); surface = [[WidgetSurface alloc] initWithWidget:pdfArea]; [surface setRenderDelegate:previewer]; @@ -81,26 +83,9 @@ [previewer setDocument:doc]; } -- (void) updateSize { - double width = 150; - double height = 150; - if ([previewer isValid]) { - double pWidth = [previewer width]; - double pHeight = [previewer height]; - width = (width < pWidth + 4) ? pWidth + 4 : width; - height = (height < pHeight + 4) ? pHeight + 4 : height; - NSPoint offset; - offset.x = (width-pWidth)/2.0; - offset.y = (height-pHeight)/2.0; - [[surface transformer] setOrigin:offset]; - } - [surface setSizeRequestWidth:width height:height]; -} - - (BOOL) update { if ([self updateOrShowError]) { - [self updateSize]; - [surface invalidate]; + [self updateDefaultSize]; return YES; } @@ -109,7 +94,7 @@ - (void) show { if ([self updateOrShowError]) { - [self updateSize]; + [self updateDefaultSize]; gtk_widget_show (GTK_WIDGET (window)); [surface invalidate]; } @@ -186,6 +171,18 @@ } return YES; } + +- (void) updateDefaultSize { + double width = 150; + double height = 150; + if ([previewer isValid]) { + double pWidth = [previewer width]; + double pHeight = [previewer height]; + width = (width < pWidth + 4) ? pWidth + 4 : width; + height = (height < pHeight + 4) ? pHeight + 4 : height; + } + gtk_window_set_default_size (window, width, height); +} @end // vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/WidgetSurface.h b/tikzit/src/gtk/WidgetSurface.h index 7a62660..32c8222 100644 --- a/tikzit/src/gtk/WidgetSurface.h +++ b/tikzit/src/gtk/WidgetSurface.h @@ -48,6 +48,9 @@ - (CGFloat) defaultScale; - (void) setDefaultScale:(CGFloat)scale; +/** + * Set the minimum size that this widget wants + */ - (void) setSizeRequestWidth:(double)width height:(double)height; @end |