Some of my Hindi characters are not showing correctly in my CHtmlView (xml.xsl). Why?

时间:2016-02-12 20:59:52

标签: html xml mfc xslt-1.0 hindi

MFC Dialog VS2015

My application uses a CHtmlView browser. In this context is it a hidden browser that is purely used to fire the print preview mechanism. I have just started to add support for printing webpages with Hindi content.

When my application is displaying the Print Preview (via CHtmlView), sometimes the text is not showing correctly:

CHtmlView

The content being displayed is an image with text overlay. Simple stuff. The font is Arial Unicode MS. The data is XML using a XSL template.

If I open the same file directly in Internet Explorer 11:

Internet Explorer 11

As you can see, it has shown the same text correctly.

And if I right-click in IE11, and view source, and copy it into Microsoft Expression Web 4:

MS Expression Web 4

Again, it all looks good. So why is the CHtmlView print preview not displaying it correctly?

If you have any ideas as to why this may be happening I would like to know. The other 30 languages I support (including Arabic does not suffer this problem).

This is the head section of the HTML. And I confirm that the HTML file is UTF-8 encoded:

<?php

$connection = mysql_connect('#', '#', '#')
    or die('Could not connect: ' .mysql_error());
mysql_select_db('#');

$jobnum = (int)$_GET['0'];
$job_arr = $_POST['job'];
$tech_arr = $_POST['tech'];

if(($jobnum > 0) && is_array($job_arr) && (count($job_arr) > 0)) {

    $equipmentquery = ""
        . "UPDATE tbl_assets "
        . "SET date_installed = curdate(), "
        . "account_number = ".$jobnum." "
        . "WHERE "
        . 'serial IN ("'.implode('","',$job_arr).'") ';

    $result1 = mysql_query ( $equipmentquery );

}
if(($jobnum > 0) && is_array($tech_arr) && (count($tech_arr) > 0)) {

    $techquery = ""
        . "UPDATE tbl_assets "
        . "SET date_installed = curdate(), "
        . "account_number = ".$jobnum." "
        . "WHERE "
        . 'serial IN ("'.implode('","',$job_arr).'") ';

    $result2 = mysql_query ( $techquery );

}

But please keep in mind that the content of the hidden CHtmlView (which fires the Print Preview) is the result of the XML/XSL translformation.

This is the XSL template:

<!DOCTYPE html PUBLIC "//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html lang="hi" xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
    <title>
              Assignment Slips
            </title>
    <style type="text/css">
    body {
        font-family: 'Arial Unicode MS';
        font-size: 10pt;
    }
    .containerPage {
    }
    .containerSlip{
        float:left;
        position: relative; 
        margin: 3mm;
    }
    .fieldName {
        position: absolute;
        left: 45px; top: 48px; width: 265px;
    }
    .fieldAssisant {
        position: absolute;
        left: 63px; top: 85px; width: 246px;
    }
    .fieldDate {
        position: absolute;
        left: 56px; top: 124px; width: 254px;
    }
    .fieldCounsel {
        position: absolute;
        left: 76px; top: 158px; width: 230px;
    }
    .fieldOther {
        position: absolute;
        left: 77px; top: 291px; width: 155px;
        font-size: 8pt;
    }
    .checkBibleReading {
        position: absolute;
        left: 30px; top: 215px; width: 15px;
    }
    .checkInitialCall {
        position: absolute;
        left: 30px; top: 232px; width: 15px;
    }
    .checkReturnVisit {
        position: absolute;
        left: 30px; top: 248px; width: 15px;
    }
    .checkBibleStudy {
        position: absolute;
        left: 30px; top: 267px; width: 15px;
    }
    .checkOther {
        position: absolute;
        left: 30px; top: 285px; width: 15px;
    }
    .checkMainHall {
        position: absolute;
        left: 176px; top: 215px; width: 15px;
    }
    .checkAuxClass1 {
        position: absolute;
        left: 176px; top: 232px; width: 15px;
    }
    .checkAuxClass2 {
        position: absolute;
        left: 176px; top: 248px; width: 15px;
    }
    </style>
</head>

But I confirm that I keep getting this sporadic problem of some characters not showing right in my specific print preview.

2 个答案:

答案 0 :(得分:1)

我不知道为什么,但是我的:

body
{
    font-family: "Arial Unicode MS";
    font-size: 10pt;
}

...顶级CSS格式未被尊重。

我不得不将设置复制到我的每个CSS类中:

<style type="text/css">
.containerPage {
    font-family: "Arial Unicode MS";
    font-size: 10pt;
}
.containerSlip{
    float:left;
    position: relative; 
    margin: 3mm;
}
.fieldName {
    position: absolute;
    left: 45px; top: 46px; width: 265px;
    font-family: "Arial Unicode MS";
}
.fieldAssisant {
    position: absolute;
    left: 63px; top: 81px; width: 246px;
    font-family: "Arial Unicode MS";
}
.fieldDate {
    position: absolute;
    left: 56px; top: 122px; width: 254px;
    font-family: "Arial Unicode MS";
}
.fieldCounsel {
    position: absolute;
    left: 76px;
    top: 156px;
    width: 230px;
    font-family: "Arial Unicode MS";
}
.fieldOther {
    position: absolute;
    left: 77px; top: 289px; width: 155px;
    font-size: 8pt;
    font-family: "Arial Unicode MS";
}
.checkBibleReading {
    position: absolute;
    left: 30px; top: 213px; width: 15px;
}
.checkInitialCall {
    position: absolute;
    left: 30px; top: 232px; width: 15px;
}
.checkReturnVisit {
    position: absolute;
    left: 30px; top: 248px; width: 15px;
}
.checkBibleStudy {
    position: absolute;
    left: 30px; top: 267px; width: 15px;
}
.checkOther {
    position: absolute;
    left: 30px; top: 285px; width: 15px;
}
.checkMainHall {
    position: absolute;
    left: 176px; top: 213px; width: 15px;
}
.checkAuxClass1 {
    position: absolute;
    left: 176px; top: 232px; width: 15px;
}
.checkAuxClass2 {
    position: absolute;
    left: 176px; top: 248px; width: 15px;
}
</style>

Print Preview from CHtmlView

答案 1 :(得分:0)

我想为此问题提供新的答案。

我要做的是让CHtmlView使用安装了最新 Internet Explorer 浏览器。可以通过将meta数据直接插入<head>标签之后来实现,如下所示:

<meta http-equiv="X-UA-Compatible" content="IE=edge">

因此<head>元素可能看起来像这样:

<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
    <style type="text/css">
        /* Styles here */
    </style>
    <title>Document Title</title>
</head>

由于我的HTML文档是使用XSL转换创建的,因此我可以包含上述meta。使用最新浏览器的唯一副作用是我的分页符不再起作用。但是我能够更改我的HTML语法,以使它们再次工作。

对HTML文件进行简单的代码更改即可使其使用最新安装的浏览器。没有更多的字体损坏!