小编jac*_*ack的帖子

库上的静态变量初始化

我正在开发一个将添加类型的工厂,但是,如果该类没有在执行的.exe中明确地被编程(编译时),那么该类型不会添加到工厂中.这是因为静态调用是如何不进行的.有没有人对如何解决这个问题有任何建议?下面是我放入lib的五个非常小的文件,然后一个.exe将调用这个lib.如果有任何关于如何使其工作的建议,或者可能是更好的设计模式,请告诉我.这基本上就是我要找的东西

1)可以采用类型的工厂

2)自动注册进入类.cpp文件,任何和所有注册码都应该在类.cpp中(对于下面的示例,RandomClass.cpp)而没有其他文件.

BaseClass.h:http://codepad.org/zGRZvIZf

RandomClass.h:http://codepad.org/rqIZ1atp

RandomClass.cpp:http://codepad.org/WqnQDWQd

TemplateFactory.h:http://codepad.org/94YfusgC

TemplateFactory.cpp:http://codepad.org/Hc2tSfzZ

c++ static-libraries static-linking

7
推荐指数
2
解决办法
6465
查看次数

字体渲染与字形信息

我调用"GetCharABCWidthsFloatW"来获取角色的宽度信息.有了这个,我将获得左侧轴承,右侧轴承和先进的宽度.

为了定位每个字符,我将从一个从零开始的"xPlacement"变量开始.我将首先通过减去"左侧轴承"来调整xPlacement变量.绘制完角色后,我会按角色的宽度前进(我稍后会显示计算结果).然后,我将通过添加当前"xPlacement"中的"右侧方位"信息来移动xPlacement变量.

在我看来,这应该是字符放置的代码,对吗?

重要的是要纠正字符的宽度.宽度将通过采用advancedWidth,左侧轴承的POSITIVE版本和右侧轴承的POSITIVE版本来计算.我会将这些值转换为正值,如果它们是负数,那么我可以得到字符的总宽度.

这是一些关于如何生成的伪代码.

float xPlacement = 0.0f;
for(int i = 0; i < strlen(text); ++i)
{
 char charValue = text[i];
 GetCharWidthABC(.., .., charInfo);

 float posLeft = charInfo.leftSideBearing;
 if(charInfo.leftSideBearing < 0)
  posLeft = -charInfo.leftSideBearing;

 float posRight = charInfo.rightSideBearing;
 if(posRight < 0)
  posRight = -charInfo.rightSideBearing;

 float posWidth = posRight + posRight + charInfo.advancedWidth;

 float letterWidth = posWidth;

 xPlacement  -= charInfo.leftSideBearing;

 /* generated some vertex coordinates, using the xPlacement variable and letterWidth */

 xPlacement += letterWidth;
 xPlacement += charInfo.rightSideBearing
}
Run Code Online (Sandbox Code Playgroud)

这似乎是正确的方法吗?

c# c++ algorithm fonts rendering

6
推荐指数
1
解决办法
5688
查看次数

Android C++本机代码

我是一名新的Android开发人员,我想创建一个仅使用Android的C/C++代码的应用程序,但我发现文档非常有限.我可以在eclipse中创建一个Android C/C++项目,但它使用了很多java代码.

我正在使用NativeActivity(2.3的新手),我需要帮助设置我的项目.有谁知道如何做到这一点?

http://developer.android.com/reference/android/app/NativeActivity.html

c++ eclipse mobile android native

5
推荐指数
1
解决办法
5991
查看次数

确定用于渲染文本的字符的y位置

我一直在研究自己的位图字体渲染器,虽然我相信我的字符间距可能正确,但我不确定如何确定字符的y位置.例如,如果字母'a'的位置为0,那么'*'或','会有什么?我一直在使用winapi函数GetCharABCWidthsFloatW来确定字符之间的间距,是否有另一个函数我可以用来确定某种类型的偏移?

我在我的位图图像上做得最好,所以它们的大小并不总是一样.

c++ winapi text typography bitmap-fonts

5
推荐指数
1
解决办法
1103
查看次数

wxWidgets中的命令行参数

有没有办法可以读取传递给C++ wxWidgets应用程序的命令行参数?如果是这样,请您提供一个如何操作的示例.

c++ command-line wxwidgets

4
推荐指数
2
解决办法
5087
查看次数

C++中的模板工厂模式

我正在尝试创建一个将传入类型的工厂,而不是将其硬编码为类型.但是,当我尝试将类型添加到类型.cpp文件内的工厂时,我将收到链接器错误.例如,他是我目前得到的链接器错误.

1> RandomClass.obj:错误LNK2019:未解析的外部符号"public:short __thiscall TemplatedFactory :: AddType(char const*)"(?? $ AddType @ VRandomClass @@@ TemplatedFactory @@ QAEFPBD @ Z)在函数"void _"中引用cdecl`动态初始化器'私有:静态短的RandomClass :: ID''(void)"(?? _E?ID @ RandomClass @@ 0FA @@ YAXXZ)

我试图让测试用例尽可能小,虽然它确实跨越了五个文件,它们非常小

BaseClass.h:http://codepad.org/MhZMw7t0

#pragma once
class BaseClass{ };
Run Code Online (Sandbox Code Playgroud)

RandomClass.h:http://codepad.org/xoObzP8G

#pragma once
#include "BaseClass.h"
class RandomClass : public BaseClass
{
private:
    static short ID;

public:
    RandomClass();
    virtual ~RandomClass();
};
Run Code Online (Sandbox Code Playgroud)

TemplatedFactory.h:http://codepad.org/qkcTBw24

#pragma once
#include <map>
using std::map;
#include "BaseClass.h"

template<typename Type> BaseClass* createType() { return new …
Run Code Online (Sandbox Code Playgroud)

c++ templates design-patterns metaprogramming factory-pattern

1
推荐指数
1
解决办法
5241
查看次数