Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 6acfcba6591b6929e816fe0ed9190d071dde4f21 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*******************************************************************************
 * Copyright (c) 2008, 2010 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

package org.eclipse.help.ui.internal.util;

import org.eclipse.core.runtime.Platform;
import org.eclipse.osgi.service.environment.Constants;
import org.eclipse.swt.widgets.Display;

public class FontUtils {

	private static final int TRAY_FONT_HEIGHT_LIMIT = 17;

	/*
	 * Determine whether the font is suitable for use in a tray dialog
	 * @return true if the font is so large that the tray would look bad.
	 */
	static public boolean isFontTooLargeForTray() {
		try {
			int height = Display.getDefault().getSystemFont().getFontData()[0].getHeight();
			return height > TRAY_FONT_HEIGHT_LIMIT;
		} catch (RuntimeException e) {
			return true;
		}
	}

	/*
	 * Get a sequence of JavaScript which will scale the embedded browser contents
	 * @param percent The percentage scaling relative to the default size
	 * @return Javascript to perform the scaling or null if we cannot create scaling script for this OS/browser
	 */
	static public String getRescaleScript(int percent) {
		String scaleString = percent/100 + "." + (percent % 100) / 10; //$NON-NLS-1$
		String os = Platform.getOS();
		if (Constants.WS_WIN32.equalsIgnoreCase(os) ||
			Constants.OS_MACOSX.equalsIgnoreCase(os)) {
			return "document.body.style.zoom = " + scaleString; //$NON-NLS-1$
		}
		return null;  // No rescale in Mozilla browsers
	}

	/*
	 * Function to determine whether the browser in the help view supports a zoom command
	 */
	static public boolean canRescaleHelpView() {
		String os = Platform.getOS();
		if (Constants.WS_WIN32.equalsIgnoreCase(os) ||
			Constants.OS_MACOSX.equalsIgnoreCase(os)) {
			return true;
		}
		// No rescale in Mozilla browsers, see Bug 227198
		return false;
	}

}

Back to the top