summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleks Kissinger <aleks0@gmail.com>2012-05-22 16:59:45 +0100
committerAleks Kissinger <aleks0@gmail.com>2012-05-22 16:59:45 +0100
commit295ae320e2385fd1340492a959e3633a339e3d0d (patch)
tree9b75f42c78b6bae62dd86afa57fafb11eb3a9f99
parent9a36706cc03ae3781ce8bdc02f10289a24408b58 (diff)
almost there, just doesnt resize container now
-rw-r--r--tikzit/src/gtk/PreviewRenderer.m6
-rw-r--r--tikzit/src/gtk/PreviewWindow.h1
-rw-r--r--tikzit/src/gtk/PreviewWindow.m44
3 files changed, 29 insertions, 22 deletions
diff --git a/tikzit/src/gtk/PreviewRenderer.m b/tikzit/src/gtk/PreviewRenderer.m
index d6d368d..f43abf6 100644
--- a/tikzit/src/gtk/PreviewRenderer.m
+++ b/tikzit/src/gtk/PreviewRenderer.m
@@ -221,9 +221,11 @@
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 = h / [self height];
- if (w * scale > [self width]) scale = w / [self width];
+ double scale = [self height] / h;
+ if (w * scale > [self width]) scale = [self width] / w;
[[surface transformer] setScale:scale];
[context saveState];
diff --git a/tikzit/src/gtk/PreviewWindow.h b/tikzit/src/gtk/PreviewWindow.h
index 32c7991..ca6b30c 100644
--- a/tikzit/src/gtk/PreviewWindow.h
+++ b/tikzit/src/gtk/PreviewWindow.h
@@ -42,7 +42,6 @@
- (void) show;
- (void) hide;
-- (void) resize;
- (BOOL) isVisible;
- (void) setVisible:(BOOL)visible;
diff --git a/tikzit/src/gtk/PreviewWindow.m b/tikzit/src/gtk/PreviewWindow.m
index 6126bc1..bde39a4 100644
--- a/tikzit/src/gtk/PreviewWindow.m
+++ b/tikzit/src/gtk/PreviewWindow.m
@@ -91,36 +91,42 @@ static gboolean window_configure_event_cb (GtkWindow *window,
[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];
+// }
+
- (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];
+ gint w, h;
+ gtk_window_get_size(window, &w, &h);
+ double width = (double)w;
+ double height = (double)h;
+ [previewer setWidth:width];
+ [previewer setHeight:height];
+ [surface invalidate];
+ //NSLog(@"got that resize event! --> (%d, %d)", w, h);
}
- (BOOL) update {
if ([self updateOrShowError]) {
[self updateSize];
- [surface invalidate];
return YES;
}
return NO;
}
-- (void) resize {
- NSLog(@"got that resize event!");
-}
-
- (void) show {
if ([self updateOrShowError]) {
[self updateSize];
@@ -207,7 +213,7 @@ static gboolean window_configure_event_cb (GtkWindow *window,
GdkEvent *event,
PreviewWindow *preview) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- [preview resize];
+ [preview updateSize];
[pool drain];
return TRUE; // we dealt with this event
}