comparison src/com/five_ten_sg/connectbot/service/TerminalBridge.java @ 260:edf4dacea9ff

allow both fixed rows/columns and specified font size
author Carl Byington <carl@five-ten-sg.com>
date Tue, 15 Jul 2014 14:17:22 -0700
parents e13878bb3ddf
children 79e6adde6fde
comparison
equal deleted inserted replaced
259:c3c11114885d 260:edf4dacea9ff
748 public synchronized void resizeComputed(int cols, int rows, int width, int height) { 748 public synchronized void resizeComputed(int cols, int rows, int width, int height) {
749 float size = 8.0f; 749 float size = 8.0f;
750 float step = 8.0f; 750 float step = 8.0f;
751 float limit = 0.125f; 751 float limit = 0.125f;
752 int direction; 752 int direction;
753 753 boolean fixed = true;
754 while ((direction = fontSizeCompare(size, cols, rows, width, height)) < 0) 754
755 size += step; 755 if (!fixed) {
756 756 while ((direction = fontSizeCompare(size, cols, rows, width, height)) < 0)
757 if (direction == 0) { 757 size += step;
758 Log.d("fontsize", String.format("Found match at %f", size)); 758
759 return; 759 if (direction == 0) {
760 } 760 Log.d("fontsize", String.format("Found match at %f", size));
761 761 return;
762 step /= 2.0f; 762 }
763 size -= step; 763
764
765 while ((direction = fontSizeCompare(size, cols, rows, width, height)) != 0
766 && step >= limit) {
767 step /= 2.0f; 764 step /= 2.0f;
768
769 if (direction > 0) {
770 size -= step;
771 }
772 else {
773 size += step;
774 }
775 }
776
777 if (direction > 0)
778 size -= step; 765 size -= step;
766
767 while ((direction = fontSizeCompare(size, cols, rows, width, height)) != 0
768 && step >= limit) {
769 step /= 2.0f;
770
771 if (direction > 0) {
772 size -= step;
773 }
774 else {
775 size += step;
776 }
777 }
778
779 if (direction > 0) size -= step;
780 }
779 781
780 this.columns = cols; 782 this.columns = cols;
781 this.rows = rows; 783 this.rows = rows;
782 forcedSize = true; 784 forcedSize = true;
783 setFontSize(size); 785 if (fixed) setFontSize(host.getFontSize());
786 else setFontSize(size);
784 } 787 }
785 788
786 private int fontSizeCompare(float size, int cols, int rows, int width, int height) { 789 private int fontSizeCompare(float size, int cols, int rows, int width, int height) {
787 // read new metrics to get exact pixel dimensions 790 // read new metrics to get exact pixel dimensions
788 defaultPaint.setTextSize(size); 791 defaultPaint.setTextSize(size);