2015-05-19 23 views
0

我使用code39來顯示條形碼。但由於某些原因,我不能使用下面的code39字體是我的代碼。我已經將ttf文件包含在字體文件夾中。下面如何包含code39字體ttf文件並使用它?

@Scripts.Render("~/bundles/modernizr") 
@Scripts.Render("~/bundles/jquery") 
@Scripts.Render("~/bundles/jquery") 
@Scripts.Render("~/bundles/jqueryui") 

@Styles.Render("~/fonts") 

<table class="table"> 

     <tr> 
      @{ 
       string size = "0px"; 
       int co = Model.BarCodeItems.FirstOrDefault().Columns; 
       if (co <= 2) 
       { 
        size = "90px"; 
       } 
       if (co > 2 || co < 5) 
       { 
        size = "70px"; 
       } 
       if (co >= 5) 
       { 
        size = "40px"; 
       } 
       int count = 0; 
      } 
      @foreach (var items in Model.BarCodeItems) 
      { 


       <td style="text-align:center"> 
        <p style="font-family:Code39r;font-size:@size"> @items.BarCode</p> 
        <p> @items.BarCode</p> 

        @*<ol class="" style="width:5px">@items.BarCode.Replace("*", "")</ol>*@ 

       </td> 
       count++; 
       if (count == @items.Columns) 
       { 
       <tr></tr> 
        count = 0; 
       } 




      } 
      </tr> 
     </table> 

是我包的配置我都添加進來捆綁配置,也呈現在我的網頁。

public static void RegisterBundles(BundleCollection bundles) 
    { 

     bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
        "~/Scripts/jquery-{version}.js")); 
     bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
        "~/Scripts/jquery.unobtrusive*", 
        "~/Scripts/jquery.validate*")); 
     bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include(
     "~/Scripts/jquery-ui-{version}.js")); 
     bundles.Add(new StyleBundle("~/Content/themes/base/css").Include(
      "~/Content/themes/base/jquery.ui.datepicker.css")); 


     bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
        "~/Scripts/modernizr-*")); 


     bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
        "~/Scripts/bootstrap.js", 
        "~/Scripts/respond.js")); 


     bundles.Add(new StyleBundle("~/bootstrap").Include(
      "~/Content/bootstrap.min.css")); 

     bundles.Add(new StyleBundle("~/fonts").Include(
      "~/fonts/Code39r.ttf")); 


    } 

回答

1

您必須包括一個字體引用不通過StyleBundle(它不是一個純文本文件text/css但二進制文件,捆綁了minifier不會理解它,它就會被錯誤地與<style src="...">標籤包含),但在你的CSS裏面有@font-face。例如,將它嵌入在HTML代碼:

<style> 
    @@font-face { 
     font-family: Code39r; src: url('@Url.Content("~/fonts/Code39r.ttf")'); 
    } 
</style> 

注意@font-face來轉義成@@font-face(因爲剃刀將識別@)。如果你在你的CSS中使用它,你不能使用Url.Content()來解析路徑,那麼你指定的路徑必須是相對於你的CSS文件的,例如:

@font-face { font-family: Code39r; src: url('../fonts/Code39r.ttf'); } 
相關問題