View Full Version : آموزش: استفاده از فونت های عربی - فارسی در ویندوز 7
ROSTAM2
جمعه 02 آذر 1403, 11:00 صبح
سلام
نرم افزاری که با .Net Framework در ویندوز 7 برای فونت آزمایش کردم بالاخره با این روش خطاش برطرف شده و اجرا شد....
156300
استفاده از کلاس PrivateFontCollection:
Imports System.Drawing.Text
Public Class Form1
Dim Collection As New PrivateFontCollection
Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
For Each File As String In IO.Directory.GetFiles(".\Fonts", "*.ttf")
Collection.AddFontFile(File)
Next
Me.Font = New Font(Collection.Families(0), 12, FontStyle.Bold)
Me.Label2.Font = New Font(Collection.Families(1), 12, FontStyle.Bold)
End Sub
End Class
mazoolagh
شنبه 03 آذر 1403, 13:09 عصر
سلام
البته مشخص نکردین که مشکل چی بوده،
و این فونت عربی-فارسی چی هست (شاید یونیکد نیستن مثل فونت های سری B)،
ولی تا جایی که یادمه (از زمان xp) این private font ها فقط در نمایش دیده میشن و قابل چاپ نیستن.
ROSTAM2
شنبه 03 آذر 1403, 15:06 عصر
سلام
البته مشخص نکردین که مشکل چی بوده،
و این فونت عربی-فارسی چی هست (شاید یونیکد نیستن مثل فونت های سری B)،
ولی تا جایی که یادمه (از زمان xp) این private font ها فقط در نمایش دیده میشن و قابل چاپ نیستن.
سلام
برای مثال omnes arabic و Baloo Bhaijaan2
و هر فونت فارسی هست. برای چاپ از HTML استفاده می کنم که مشکلی بافونت ها نداره.
mazoolagh
یک شنبه 04 آذر 1403, 18:16 عصر
سلام دوباره
پس شاید نیاز باشه برنامه تون رو یه بازنگری بکنین،
این دو فونت در xp هم مشکلی ندارن.
ROSTAM2
یک شنبه 04 آذر 1403, 18:22 عصر
سلام دوباره
پس شاید نیاز باشه برنامه تون رو یه بازنگری بکنین،
این دو فونت در xp هم مشکلی ندارن.
نرم افزار رو با VS 2010 نوشتم و در ویندوز 7 هم از سیستم خودم و هم از سیستم کاربر همون خطا داشت و با حذف فئونت ها اجرا می شد البته فونت انگلیسی رو پشتیبانی می کنه
mazoolagh
دوشنبه 05 آذر 1403, 17:50 عصر
به هر حال یک چیزی هست که از چشم دور مونده و الان اینجا خودش رو نشون داده،
و ممکنه بعدا جای دیگه ای پدیدار بشه.
ROSTAM2
دوشنبه 05 آذر 1403, 18:09 عصر
این هم سوس کد PrivateFontProvider:
Imports System.ComponentModel, System.Drawing.Text
<ProvideProperty("PrivateFont", GetType(Component))>
<ProvideProperty("PrivateFontSize", GetType(Component))>
<ProvideProperty("PrivateFontStyle", GetType(Component))>
Public Class PrivateFontProvider
Implements ISupportInitialize
Implements IExtenderProvider
Private PrivateFontsValue As New PrivateFontCollection
<Browsable(False)>
Public ReadOnly Property PrivateFonts() As PrivateFontCollection
Get
Return PrivateFontsValue
End Get
End Property
Private FontDirectoryValue As String = ""
Public Property FontDirectory() As String
Get
Return FontDirectoryValue
End Get
Set(ByVal value As String)
FontDirectoryValue = value
End Set
End Property
Protected Friend ComponentFonts As New Dictionary(Of Component, String)
Protected Friend ComponentFontSizes As New Dictionary(Of Component, Single)
Protected Friend ComponentFontStyles As New Dictionary(Of Component, FontStyle)
Public Sub SetPrivateFont(Component As Component, Name As String)
If ComponentFonts.ContainsKey(Component) Then
ComponentFonts(Component) = Name
ResetFont(Component, Name)
Else
ComponentFonts.Add(Component, Name)
End If
End Sub
Public Sub SetPrivateFontSize(Component As Component, Optional Size As Single = 11)
If ComponentFontSizes.ContainsKey(Component) Then
ComponentFontSizes(Component) = Size
ResetFont(Component, ComponentFonts(Component))
Else
ComponentFontSizes.Add(Component, Size)
End If
End Sub
Public Sub SetPrivateFontStyle(Component As Component, Style As FontStyle)
If ComponentFontStyles.ContainsKey(Component) Then
ComponentFontStyles(Component) = Style
ResetFont(Component, ComponentFonts(Component))
Else
ComponentFontStyles.Add(Component, Style)
End If
End Sub
Public Function GetPrivateFont(Component As Component) As String
If ComponentFonts.ContainsKey(Component) Then
Return ComponentFonts(Component)
End If
Return ""
End Function
Public Function GetPrivateFontSize(Component As Component) As Single
If ComponentFontSizes.ContainsKey(Component) Then
Return ComponentFontSizes(Component)
End If
Return 11
End Function
Public Function GetPrivateFontStyle(Component As Component) As FontStyle
If ComponentFontStyles.ContainsKey(Component) Then
Return ComponentFontStyles(Component)
End If
Return FontStyle.Regular
End Function
Public Sub EndInit() Implements System.ComponentModel.ISupportInitialize.EndInit
'If Me.Fonts.Count = 0 Then Exit Sub
If Me.FontDirectory.Length = 0 Then Exit Sub
If IO.Directory.Exists(Me.FontDirectory) = False Then Exit Sub
For Each File As String In IO.Directory.GetFiles(Me.FontDirectory, "*.ttf")
Me.PrivateFonts.AddFontFile(File)
Application.DoEvents()
Next
For Each ComponentFont As KeyValuePair(Of Component, String) In Me.ComponentFonts
ResetFont(ComponentFont.Key, ComponentFont.Value)
Next
End Sub
Sub ResetFont(Component As Component, FontName As String)
Dim FontSize As Single = Me.ComponentFontSizes(Component)
Dim FontStyle As FontStyle = Me.ComponentFontStyles(Component)
If TypeOf (Component) Is ToolStrip Then
DirectCast(Component, ToolStrip).Font =
New Font(FontName, FontSize, FontStyle)
ElseIf TypeOf (Component) Is Control Then
DirectCast(Component, Control).Font =
New Font(FontName, FontSize, FontStyle)
End If
End Sub
Public Function CanExtend(extendee As Object) As Boolean Implements System.ComponentModel.IExtenderProvider.CanExtend
Return CBool(TypeOf (extendee) Is ToolStrip Or TypeOf (extendee) Is Control)
End Function
Public Sub BeginInit() Implements System.ComponentModel.ISupportInitialize.BeginInit
End Sub
End Class
طریقه استفاده یک Component Class با نام privateFontProvider ایجاد و کد های مربوطه رو جایگزین کرده و پرژو Build شود....
سورس پروژه در پست اول موجود است....
156305
156306
156307
ROSTAM2
دوشنبه 05 آذر 1403, 21:39 عصر
..... حذف شود ....
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.