Apparently is is possible to use Cocos2d-js 3.0 RC3 cc.LabelTTF with custom fonts, for example as answered here. However this doesn't seem to produce any results for me, neither in the local JSBinding app nor in the web browser.
Font file was included in the res object:
var res = {
lobster_ttf: "res/Lobster.ttf"
};
var g_resources = [];
for (var i in res) {
g_resources.push(res[i]);
}
Lobster.ttf does exist in the directory res.
The label is instantiated as follows:
var label = new cc.LabelTTF("labeltext", res.lobster_ttf, 48);
Doing this will not display the label in the specified font but in the default font. Specifying an installed font instead of the path to the custom ttf does however work.
Is there extra work required to be able to use TTF files?
cocos2d-js v3.0 rc3
Mine worked using the font name (font name when installing the font, not the file name font)
sample:
var label = new cc.LabelTTF("labeltext", "Lobster", 48);
Give it a try..
Tim
Related
I'm want to use sans-serif-condensed in jetpack compose, but for the life of me, I can't find it anywhere within compose itself?
Am I just blind, or will I need to do something like import the font and set it all manually?
You can use the fontFamily attribute to specify the font family.
Text("Hello World", fontFamily = FontFamily.Serif)
Predefined Fonts
By default, Jetpack compose has only 5 Font Families,
Default, SansSerif, Serif, Monospace and Cursive.
Custom Fonts
If you need any other font family (which seems to be your case), you have to add it as mentioned here.
Steps
Download or Get the required fonts files and add them to the res/fonts directory.
Create FontFamily like this,
val firaSansFamily = FontFamily(
Font(R.font.firasans_light, FontWeight.Light),
Font(R.font.firasans_regular, FontWeight.Normal),
Font(R.font.firasans_italic, FontWeight.Normal, FontStyle.Italic),
Font(R.font.firasans_medium, FontWeight.Medium),
Font(R.font.firasans_bold, FontWeight.Bold)
)
Use like this,
Text(..., fontFamily = firaSansFamily, fontWeight = FontWeight.Light)
Text(..., fontFamily = firaSansFamily, fontWeight = FontWeight.Normal)
When I try to export to PDF DataGrid with Russian values in it, it displays gibberish in this new PDF file even though I managed to set a proper font (PTSans) for jsPDF and when you print just random text it is working fineā¦
So is there a way to configure table to PDF to display proper Russian?
Actually I suddenly found a solution :D
If anyone will ever have this problem again, this is how you solve it:
const doc = new jsPDF();
const font = "../../../assets/fonts/PTSans-Regular.ttf" // path to .ttf file
doc.addFont(font, "PTSans-Regular", "normal");
exportDataGridToPdf({
jsPDFDocument: doc,
component: grid,
autoTableOptions: {
styles: {
font: 'PTSans-Regular' // this is a part I forgot about before
}
}
}).then(() => {
doc.save(filename);
})
Basically you need to set up font for your language in jsPdf as well as set up the same in styles for jsPDF-autoTable options.
Huge thanks to Alisher from DevExpress Support whose answer helped me to figure it out.
I'm currently trying to add a custom font to my project, but I somehow won't work.
I've already added the .otf file to a font folder, checked that it targets to my project and added Fonts provided by application to Info.plist.
struct ContentView: View {
var body: some View {
Text("CLOSEST")
.foregroundColor(Color("primary"))
.font(Font.custom("HelveticaNowDisplayBold", size: 60))
}
}
If you have made sure that the Info.plist is using the correct filename:
Note if you are using Xcode 13 you may not have an Info.plist where you expect. This SO answer explains where you can find it.
That the font is available in the app's target.
You also need to make sure that you are accessing the font by the correct name.
An easy way to check the font's name is to add the following to your AppDelegate in the didFinishLaunchingWithOptions before the return true. Or if you are using the new SwiftUI lifecycle you can add it to an .onAppear.
for family in UIFont.familyNames.sorted() {
let names = UIFont.fontNames(forFamilyName: family)
print("Family: \(family) Font names: \(names)")
}
This will list all the fonts by family and name.
Just remember to remove it once you have finished using it as you don't need to unnecessarily print to the console.
When I do it for my fonts (I have added the same font as you) I find the following in the console in the list of available fonts (see the above screenshot) :
Family: Helvetica Now Display Font names: ["HelveticaNowDisplay-Bold"]
Your font may have a different name to mine, and it is important to note that the font name may not be the same as the filename. This is what trips up a lot of people, as they try using the filename when they need to use the font name.
The following test code produces:
struct ContentView: View {
var body: some View {
Text("Hello")
.foregroundColor(.blue)
.font(Font.custom("HelveticaNowDisplay-Bold", size: 60))
}
}
For more information about adding custom fonts see Apple's documentation.
Dynamic Type in SwiftUI
If you are using a custom font then you should consider setting it up so that it will scale with dynamic type.
iOS 14
iOS 14 introduces a new modifier that allows you to scale a font relative to a Dynamic Font Type.
Text("Hello")
.font(.custom("HelveticaNowDisplay-Bold", size: 60, relativeTo: .body))
iOS 13
If you are using iOS 13 that requires a bit more effort to get the same effect.
You first need to create a ViewModifier. This view modifier listens to the size category from the environment (it doesn't actually use it but having it here makes sure the view modifier is updated whenever the size category is updated).
struct ScaledFont: ViewModifier {
#Environment(\.sizeCategory) var sizeCategory
var name: String
var size: CGFloat
func body(content: Content) -> some View {
let scaledSize = UIFontMetrics.default.scaledValue(for: size)
return content.font(.custom(name, size: scaledSize))
}
}
extension View {
func scaledFont(name: String, size: CGFloat) -> some View {
return self.modifier(ScaledFont(name: name, size: size))
}
}
It is then used in the following way:
Text("Hello")
.scaledFont(name: "HelveticaNowDisplay-Bold", size: 60)
For a really good write up check out this post on Hacking With Swift.
For those people who no longer have a app/scene delegate to put this in. In your <Your_App_Name>App.swift file
init() {
for family in UIFont.familyNames.sorted() {
let names = UIFont.fontNames(forFamilyName: family)
print("Family: \(family) Font names: \(names)")
}
}
Will work
You need to include the extension of the font (for example .ttf) in the info.plist . I saw a couple of tutorials on youtube, which do not included it, but for me, it does not work without it.
I had the exact same problem. The following steps fixed it for me. I'm currently using Xcode 11.4.1
Create a storyboard, add a label and select your font in the inspector as font for the label.
Build your App in the Simulator
Check the installed fonts with:
for family in UIFont.familyNames.sorted() {
let names = UIFont.fontNames(forFamilyName: family)
print("Family: \(family) Font names: \(names)")
}
If it's appearing you can use it also programmatically
Here is also a list of Common mistakes with adding custom fonts
I had the same issue,
it worked for me when I omitted the "-Regular",
but in the info.plist I wrote it with it.
Sometimes font file name and the font actual name are different.
In my case my file name was SCRIPTIN.ttf but the actual font name was Scriptina.
I found this by running the following function in App.swift file.
init() {
for family in UIFont.familyNames.sorted() {
let names = UIFont.fontNames(forFamilyName: family)
print("Family: \(family) Font names: \(names)")
}
}
Just put this file after this function in App.swift file and run the app. You will get a list of all loaded files and their names including the newly added font.
var body: some Scene {
WindowGroup {
ContentView()
}
}
Thank you.
Xcode 13 Press on target, then info, type Fonts provided by the application and add item font name as like image
Jonas Deichelmann's answer (to list the fonts available to app) was very helpful to fine tune the Info.plist entries.
Contrary to Apple's example at https://developer.apple.com/documentation/swiftui/applying-custom-fonts-to-text that shows the Fonts provided by application entries to include a relative path to the font files including a subdirectory, I had to provide exclusively the font file name (e.g. Mulish-Regular.ttf with the file extension but without the subdirectory into which the file is stored)
Xcode 14.2
Enlargement of size of the device font will sometimes break (Styling wise).
Disabling font scaling can hurt the accessibility of your app, ideally if you want to limit scaling for Apps using React native 0.58.0 and above; use the maxFontSizeMultiplier prop on specific Text components.
However if you absolutely want to disable font scaling across your entire Application, you can do so by globally setting the allowFontScaling prop in the defaultProps of Text.
You should place these lines in your root entrypoint (normally index.js) before AppRegistry.registerComponent.
For React Native 0.56.0+
Text.defaultProps = Text.defaultProps || {};
Text.defaultProps.allowFontScaling = false;
For earlier versions of React Native you should only need the second line, but having both won't hurt. The first line just protects against the Text component not having defaultProps which is the case for React Native 0.56.0 and above.
Add the above lines in the entry point file of your React Native application (usually index.js, app.js or main.js) to apply this prop to all Text components in your application.
This prop will only affect Text components and you may want to apply the same changes to TextInput which can be done with a similar snippet:
TextInput.defaultProps = TextInput.defaultProps || {};
TextInput.defaultProps.allowFontScaling = false;
Also note that some components wont obey font scaling settings, for example: Alert, PickerIOS, DatePickerIOS, TabBarIOS, SegmentedControlIOS as these are all natively drawn and don't rely on the Text component.
For React native 0.58+
Preferable to keep font scaling but you can limit it by using Text new prop maxFontSizeMultiplier
For React native 0.56+ use Levi's answer
Text.defaultProps = Text.defaultProps || {};
Text.defaultProps.allowFontScaling = false;
For React native 0.55 and lower
Add Text.defaultProps.allowFontScaling=false at the beginning of the app (e.g. main.js or app.js etc ...) to apply this prop on all Text components through out the whole app.
When user increase full font size from setting
Enlargement of size of the device font will not break (Styling wise).
index.js file
import {AppRegistry} from 'react-native';
import App from './src/App';
import {name as appName} from './app.json';
import {Text, TextInput} from 'react-native';
AppRegistry.registerComponent(appName, () => App);
//ADD this
if (Text.defaultProps == null) {
Text.defaultProps = {};
Text.defaultProps.allowFontScaling = false;
}
if (TextInput.defaultProps == null) {
TextInput.defaultProps = {};
TextInput.defaultProps.allowFontScaling = false;
}
<CalendarStrip
shouldAllowFontScaling={false}
/>
Also note that some components wont obey font scaling settings, for example: Alert, PickerIOS, DatePickerIOS, TabBarIOS, SegmentedControlIOS as these are all natively drawn and don't rely on the Text component.
if (Text.defaultProps == null) {
Text.defaultProps = {};
Text.defaultProps.allowFontScaling = false;
}
I kept this piece of code inside the constructor of index.js.It really worked well. By the I am using react native version 0.59.9 FYI.
Create an <AppText> component and use it with your presets instead of the original one, with your own default, including font scaling false. This is better because you can enrich it with your own API.
For example, my AppText permit to do things like:
<AppText id="some.translation.key" color="primary" size="l" underline italic bold/>
In another file, import the actual Text component as ScaledText so as a backup, and then redefine Text, overriding the allowFontScaling prop.
export function Text(props) {
return <ScaledText {...props} allowFontScaling={false} />;
}
Then, import your locally defined Text component, instead of the built-in React Native Text. This is also useful if you want to elegantly disable font scaling on only certain parts of your app.
For webview we can use textZoom={100} props to handle font-size change if font size is changed from mobile setting.
if imported from react-native-webview
<WebView
textZoom={100}
source={}/>
I'm kinda late, but if anyone wants a answer with Typescript, here it is
interface TextWithDefaultProps extends Text {
defaultProps?: { allowFontScaling?: boolean };
}
(Text as unknown as TextWithDefaultProps).defaultProps = {
...((Text as unknown as TextWithDefaultProps).defaultProps || {}),
allowFontScaling: false,
};
I'm trying to learn TCPDF but I`m stucked in a strange problem, it's my code picked up by the example.
require_once('../tcpdf.php');
ob_start();
// create new PDF document
$pdf = new TCPDF("P","mm","A4",true,"UTF-8",false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('User');
$pdf->SetTitle('TCPDF');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 001', PDF_HEADER_STRING, array(0,64,255), array(0,64,128));
$pdf->setFooterData(array(0,64,0), array(0,64,128));
// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
// set some language-dependent strings (optional)
if (#file_exists(dirname(__FILE__).'/lang/eng.php')) {
require_once(dirname(__FILE__).'/lang/eng.php');
$pdf->setLanguageArray($l);
}
// ---------------------------------------------------------
// set default font subsetting mode
$pdf->setFontSubsetting(true);
// Set font
// dejavusans is a UTF-8 Unicode font, if you only need to
// print standard ASCII chars, you can use core fonts like
// helvetica or times to reduce file size.
//~ $pdf->SetFont('dejavusans', '', 14, '', true);
// Add a page
// This method has several options, check the source code documentation for more information.
$pdf->AddPage();
// set text shadow effect
$pdf->setTextShadow(array('enabled'=>true, 'depth_w'=>0.2, 'depth_h'=>0.2, 'color'=>array(196,196,196), 'opacity'=>1, 'blend_mode'=>'Normal'));
$html = "ASD";
$pdf->writeHTML($html, true, false, true, false, '');
ob_end_clean();
$pdf->Output('prova.pdf', 'I');`
When the PHP reach the Output command something gone wrong, it doesn't open the PDF page on the browser but print a strange output, like if a open a PDF file with a text editor.
Here I use writeHTML(), but is the same with Image(), I've already try it.
Where am I doing wrong?
You need a Content-Disposition header.
See this other thread: PHP Content-Disposition: attachment / Content-Type
i tested things that you did, i working for me, i thing if download the tcpdf API again and replace it with your current folder.
and also about image: make sure that your image type is .jpg as
$html = "ASD
<img src="project path/images/image.jpg"/>
";